Package org.simpleframework.http.core
Class ContainerController
- java.lang.Object
-
- org.simpleframework.http.core.ContainerController
-
- All Implemented Interfaces:
Controller
class ContainerController extends java.lang.Object implements Controller
TheContainerController
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 providedContainer
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 Allocator
allocator
This is the allocator used to create the buffers needed.private ConcurrentExecutor
collect
This is the thread pool used for collecting the requests.private Container
container
This is the container used to service the requests.private ConcurrentExecutor
executor
This is the thread pool used for servicing the requests.private Reactor
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 theContainerController
object.
-
Method Summary
All Methods Instance Methods Concrete Methods 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
stop()
This method is used to stop theSelector
so that all resources are released.
-
-
-
Field Detail
-
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 Detail
-
ContainerController
public ContainerController(Container container, Allocator allocator, int count, int select) throws java.io.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:
java.io.IOException
-
-
Method Detail
-
start
public void start(Channel channel) throws java.io.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 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:
java.io.IOException
-
start
public void start(Collector collector) throws java.io.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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
java.io.IOException
-
select
public void select(Collector collector) throws java.io.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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
java.io.IOException
-
ready
public void ready(Collector collector) throws java.io.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 interfaceController
- Parameters:
collector
- this is the collector used to collect data- Throws:
java.io.IOException
-
stop
public void stop() throws java.io.IOException
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:
java.io.IOException
-
-