Class HttpConnector

All Implemented Interfaces:
Iterable<ComponentType>, Channel, ComponentType, Eligible, Manager

public class HttpConnector extends Component
A converter component that receives and sends web application layer messages and byte buffers on associated network channels.
  • Constructor Details

    • HttpConnector

      public HttpConnector(Channel appChannel, Channel networkChannel)
      Create a new connector that uses the networkChannel for network level I/O.
      Parameters:
      appChannel - this component’s channel
      networkChannel - the channel for network level I/O
  • Method Details

    • setApplicationBufferSize

      public HttpConnector setApplicationBufferSize(int applicationBufferSize)
      Sets the size of the buffers used for Input 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

      public int 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 interrupted
      IOException - 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 event
      appChannel - the application layer channel
      Throws:
      InterruptedException - the interrupted exception
    • onConnected

      @Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onConnected(Connected<?> event, TcpChannel netConnChannel) throws InterruptedException, IOException
      Called when the network connection is established.

      Triggers the further processing of the initial request.

      Parameters:
      event - the event
      netConnChannel - the network layer channel
      Throws:
      InterruptedException - if the execution is interrupted
      IOException - 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, TcpChannel netConnChannel) throws InterruptedException, ProtocolException
      Processes any input from the network layer.
      Parameters:
      event - the event
      netConnChannel - the network layer channel
      Throws:
      InterruptedException - if the thread is interrupted
      ProtocolException - if the protocol is violated
    • onClosed

      @Handler(channels=org.jgrapes.http.HttpConnector.NetworkChannel.class) public void onClosed(Closed event, TcpChannel netConnChannel)
      Called when the network connection is closed.
      Parameters:
      event - the event
      netConnChannel - 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 of the connection has been upgraded to a websocket connection.

      Parameters:
      event - the event
      appChannel - the application channel