Package org.jgrapes.http
Class HttpConnector
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.http.HttpConnector
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
A converter component that receives and sends web application
layer messages and byte buffers on associated network channels.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionHttpConnector
(Channel appChannel, Channel networkChannel) Create a new connector that uses the networkChannel for network level I/O.HttpConnector
(Channel appChannel, Channel networkChannel, Channel secureChannel) Create a new connector that uses the networkChannel for network level I/O. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the size of the application side (receive) buffers.void
Handles a close event from the application channel.void
onClosed
(Closed<?> event, SocketIOChannel netConnChannel) Called when the network connection is closed.void
onConnected
(ClientConnected event, SocketIOChannel netConnChannel) Called when the network connection is established.void
onInput
(Input<ByteBuffer> event, SocketIOChannel netConnChannel) Processes any input from the network layer.void
Handles I/O error events from the network layer.void
Handles output from the application.void
onRequest
(Request.Out event) Starts the processing of a request from the application layer.setApplicationBufferSize
(int applicationBufferSize) Sets the size of the buffers used forInput
events on the application channel.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
HttpConnector
Create a new connector that uses the networkChannel for network level I/O.- Parameters:
appChannel
- this component’s channelnetworkChannel
- the channel for network level I/OsecureChannel
- the channel for secure network level I/O
-
HttpConnector
Create a new connector that uses the networkChannel for network level I/O.- Parameters:
appChannel
- this component’s channelnetworkChannel
- the channel for network level I/O
-
-
Method Details
-
setApplicationBufferSize
Sets the size of the buffers used forInput
events on the application channel.Defaults to the upstream buffer size minus 512 (estimate for added protocol overhead).
- Parameters:
applicationBufferSize
- the size to set- Returns:
- the http server for easy chaining
-
applicationBufferSize
Returns the size of the application side (receive) buffers.- Returns:
- the value or -1 if not set
-
onRequest
Starts the processing of a request from the application layer.When a network connection has been established, the application layer will be informed by a
HttpConnected
event, fired on a subchannel that is created for the processing of this request.- Parameters:
event
- the request- Throws:
InterruptedException
- if processing is interruptedIOException
- Signals that an I/O exception has occurred.
-
onOutput
@Handler public void onOutput(Output<?> event, org.jgrapes.http.HttpConnector.WebAppMsgChannel appChannel) throws InterruptedException Handles output from the application.This may be the payload of e.g. a POST or data to be transferes on a websocket connection.
- Parameters:
event
- the eventappChannel
- the application layer channel- Throws:
InterruptedException
- the interrupted exception
-
onConnected
@Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onConnected(ClientConnected event, SocketIOChannel netConnChannel) throws InterruptedException, IOException Called when the network connection is established.Triggers the further processing of the initial request.
- Parameters:
event
- the eventnetConnChannel
- the network layer channel- Throws:
InterruptedException
- if the execution is interruptedIOException
- Signals that an I/O exception has occurred.
-
onIoError
@Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onIoError(IOError event) throws IOException Handles I/O error events from the network layer.- Parameters:
event
- the event- Throws:
IOException
- Signals that an I/O exception has occurred.
-
onInput
@Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onInput(Input<ByteBuffer> event, SocketIOChannel netConnChannel) throws InterruptedException, ProtocolException Processes any input from the network layer.- Parameters:
event
- the eventnetConnChannel
- the network layer channel- Throws:
InterruptedException
- if the thread is interruptedProtocolException
- if the protocol is violated
-
onClosed
@Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onClosed(Closed<?> event, SocketIOChannel netConnChannel) Called when the network connection is closed.- Parameters:
event
- the eventnetConnChannel
- the net conn channel
-
onClose
@Handler public void onClose(Close event, org.jgrapes.http.HttpConnector.WebAppMsgChannel appChannel) Handles a close event from the application channel.Such an event may only be fired if the connection has been upgraded to a websocket connection.
- Parameters:
event
- the eventappChannel
- the application channel
-