Class RequestCollector

  • All Implemented Interfaces:
    Collector, Entity

    class RequestCollector
    extends java.lang.Object
    implements Collector
    The RequestCollector object is used to collect all of the data used to form a request entity. This will collect the data fragment by fragment from the underlying transport. When all of the data is consumed and the entity is created and then it is sent to the Selector object for processing. If the request has completed the next request can be collected from the underlying transport using a new collector object.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Channel channel
      This is the channel used to acquire the underlying data.
      private ByteCursor cursor
      This is the cursor used to read and reset the data.
      private EntityConsumer entity
      This is used to consume the request entity from the channel.
      private Timer timer
      This represents the time the request collection began at.
      private Trace trace
      This is the trace used to listen for various collect events.
    • Constructor Summary

      Constructors 
      Constructor Description
      RequestCollector​(Allocator allocator, Channel channel)
      The RequestCollector object used to collect the data from the underlying transport.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void collect​(Controller controller)
      This is used to collect the data from a Channel which is used to compose the entity.
      Body getBody()
      This is used to acquire the body for this HTTP entity.
      Channel getChannel()
      This provides the connected channel for the client.
      Header getHeader()
      This provides the HTTP request header for the entity.
      java.nio.channels.SocketChannel getSocket()
      This returns the socket channel that is used by the collector to read content from.
      long getTime()
      This is the time in milliseconds when the request was first read from the underlying channel.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • entity

        private final EntityConsumer entity
        This is used to consume the request entity from the channel.
      • cursor

        private final ByteCursor cursor
        This is the cursor used to read and reset the data.
      • channel

        private final Channel channel
        This is the channel used to acquire the underlying data.
      • trace

        private final Trace trace
        This is the trace used to listen for various collect events.
      • timer

        private final Timer timer
        This represents the time the request collection began at.
    • Constructor Detail

      • RequestCollector

        public RequestCollector​(Allocator allocator,
                                Channel channel)
        The RequestCollector object used to collect the data from the underlying transport. In order to collect a body this must be given an Allocator which is used to create an internal buffer to store the consumed body.
        Parameters:
        allocator - this is the allocator used to buffer data
        tracker - this is the tracker used to create sessions
        channel - this is the channel used to read the data
    • Method Detail

      • collect

        public void collect​(Controller controller)
                     throws java.io.IOException
        This is used to collect the data from a Channel which is used to compose the entity. If at any stage there are no ready bytes on the socket the controller provided can be used to queue the collector until such time as the socket is ready to read. Also, should the entity have completed reading all required content it is handed to the controller as ready, which processes the entity as a new client HTTP request.
        Specified by:
        collect in interface Collector
        Parameters:
        controller - this is the controller used to queue this
        Throws:
        java.io.IOException
      • getTime

        public long getTime()
        This is the time in milliseconds when the request was first read from the underlying channel. The time represented here represents the time collection of this request began. This does not necessarily represent the time the bytes arrived on the receive buffers as some data may have been buffered.
        Specified by:
        getTime in interface Entity
        Returns:
        this represents the time the request was ready at
      • getHeader

        public Header getHeader()
        This provides the HTTP request header for the entity. This is always populated and provides the details sent by the client such as the target URI and the query if specified. Also this can be used to determine the method and protocol version used.
        Specified by:
        getHeader in interface Entity
        Returns:
        the header provided by the HTTP request message
      • getBody

        public Body getBody()
        This is used to acquire the body for this HTTP entity. This will return a body which can be used to read the content of the message, also if the request is multipart upload then all of the parts are provided as Part objects. Each part can then be read as an individual message.
        Specified by:
        getBody in interface Entity
        Returns:
        the body provided by the HTTP request message
      • getChannel

        public Channel getChannel()
        This provides the connected channel for the client. This is used to send and receive bytes to and from an transport layer. Each channel provided with an entity contains an attribute map which contains information about the connection.
        Specified by:
        getChannel in interface Entity
        Returns:
        the connected channel for this HTTP entity
      • getSocket

        public java.nio.channels.SocketChannel getSocket()
        This returns the socket channel that is used by the collector to read content from. This is a selectable socket, in that it can be registered with a Java NIO selector. This ensures that the system can be notified when the socket is ready.
        Returns:
        the socket channel used by this collector object