Class ContainerController

java.lang.Object
org.simpleframework.http.core.ContainerController
All Implemented Interfaces:
Controller

class ContainerController extends Object implements Controller
The ContainerController object is essentially the core processing engine for the server. This is used to collect requests from the connected channels and dispatch those requests to the provided Container object. This contains two thread pools. The first is used to collect data from the channels and create request entities. The second is used to take the created entities and service them with the provided container.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Allocator
    This is the allocator used to create the buffers needed.
    private final ConcurrentExecutor
    This is the thread pool used for collecting the requests.
    private final Container
    This is the container used to service the requests.
    private final ConcurrentExecutor
    This is the thread pool used for servicing the requests.
    private final Reactor
    This is the reactor used to schedule the collectors.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ContainerController(Container container, Allocator allocator, int count, int select)
    Constructor for the ContainerController object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ready(Collector collector)
    The ready event is used when a full HTTP entity has been collected from the underlying transport.
    void
    select(Collector collector)
    The select event is used to register the connected socket with a Java NIO selector which can efficiently determine when there are bytes ready to read from the socket.
    void
    start(Collector collector)
    The start event is used to immediately consume bytes form the underlying transport, it does not require a select to check if the socket is read ready which improves performance.
    void
    start(Channel channel)
    This is used to initiate the processing of the channel.
    void
    This method is used to stop the Selector so that all resources are released.

    Methods inherited from class java.lang.Object

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

    • executor

      private final ConcurrentExecutor executor
      This is the thread pool used for servicing the requests.
    • collect

      private final ConcurrentExecutor collect
      This is the thread pool used for collecting the requests.
    • allocator

      private final Allocator allocator
      This is the allocator used to create the buffers needed.
    • container

      private final Container container
      This is the container used to service the requests.
    • reactor

      private final Reactor reactor
      This is the reactor used to schedule the collectors.
  • Constructor Details

    • ContainerController

      public ContainerController(Container container, Allocator allocator, int count, int select) throws IOException
      Constructor for the ContainerController object. This is used to create a controller which will collect and dispatch requests using two thread pools. The first is used to collect the requests, the second is used to service those requests.
      Parameters:
      container - this is the container used to service requests
      allocator - this is used to allocate any buffers needed
      count - this is the number of threads per thread pool
      select - this is the number of controller threads to use
      Throws:
      IOException
  • Method Details

    • start

      public void start(Channel channel) throws IOException
      This is used to initiate the processing of the channel. Once the channel is passed in to the initiator any bytes ready on the HTTP pipeline will be processed and parsed in to a HTTP request. When the request has been built a callback is made to the Container to process the request. Also when the request is completed the channel is passed back in to the initiator so that the next request can be dealt with.
      Specified by:
      start in interface Controller
      Parameters:
      channel - the channel to process the request from
      Throws:
      IOException
    • start

      public void start(Collector collector) throws IOException
      The start event is used to immediately consume bytes form the underlying transport, it does not require a select to check if the socket is read ready which improves performance. Also, when a response has been delivered the next request from the pipeline is consumed immediately.
      Specified by:
      start in interface Controller
      Parameters:
      collector - this is the collector used to collect data
      Throws:
      IOException
    • select

      public void select(Collector collector) throws IOException
      The select event is used to register the connected socket with a Java NIO selector which can efficiently determine when there are bytes ready to read from the socket.
      Specified by:
      select in interface Controller
      Parameters:
      collector - this is the collector used to collect data
      Throws:
      IOException
    • ready

      public void ready(Collector collector) throws IOException
      The ready event is used when a full HTTP entity has been collected from the underlying transport. On such an event the request and response can be handled by a container.
      Specified by:
      ready in interface Controller
      Parameters:
      collector - this is the collector used to collect data
      Throws:
      IOException
    • stop

      public void stop() throws IOException
      This method is used to stop the Selector so that all resources are released. As well as freeing occupied memory this will also stop all threads, which means that is can no longer be used to collect data from the pipelines.

      Here we stop the Reactor first, this ensures that there are no further selects performed if a given socket does not have enough data to fulfil a request. From there we stop the main dispatch Executor so that all of the currently executing tasks complete. The final stage of termination requires the collector thread pool to be stopped.

      Specified by:
      stop in interface Controller
      Throws:
      IOException