Package org.simpleframework.http.core
Class ContainerController
java.lang.Object
org.simpleframework.http.core.ContainerController
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsConstructorDescriptionContainerController
(Container container, Allocator allocator, int count, int select) Constructor for theContainerController
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
The ready event is used when a full HTTP entity has been collected from the underlying transport.void
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
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
This is used to initiate the processing of the channel.void
stop()
This method is used to stop theSelector
so that all resources are released.
-
Field Details
-
executor
This is the thread pool used for servicing the requests. -
collect
This is the thread pool used for collecting the requests. -
allocator
This is the allocator used to create the buffers needed. -
container
This is the container used to service the requests. -
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 theContainerController
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 requestsallocator
- this is used to allocate any buffers neededcount
- this is the number of threads per thread poolselect
- this is the number of controller threads to use- Throws:
IOException
-
-
Method Details
-
start
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 theContainer
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 interfaceController
- Parameters:
channel
- the channel to process the request from- Throws:
IOException
-
start
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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
IOException
-
select
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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
IOException
-
ready
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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
IOException
-
stop
This method is used to stop theSelector
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 dispatchExecutor
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 interfaceController
- Throws:
IOException
-