public class IODispatcher extends Object implements DatagramDispatcher<Endpoint>, Runnable
Selector
to receive packets from multiple endpoints
and a WorkerPool
to dispatch the processing tasks.
The dispatcher uses the following thread model:
Incoming packets for all the registered endpoints are received
in the thread that executes the run()
method. For every
packet received, a ProcessPacketTask
instance is created
and dispatched to a worker thread from the configured pool.
The methods addEndpoint(Endpoint)
, removeEndpoint(Endpoint)
and stop()
are thread safe and may be called from any thread.
However, to avoid concurrency issues, the operation on the underlying
Selector
will always be executed by the thread executing the
run()
method. The three methods mentioned above will block until
the operation has completed.
Constructor and Description |
---|
IODispatcher(DatagramDispatcherCallback callback)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addEndpoint(Endpoint endpoint)
Add a new endpoint.
|
void |
removeEndpoint(Endpoint endpoint)
Remove an endpoint.
|
void |
run()
Run the I/O dispatcher.
|
void |
stop()
Stop the dispatcher.
|
public IODispatcher(DatagramDispatcherCallback callback) throws IOException
callback
- IOException
- if the Selector
instance could not be createdpublic void addEndpoint(Endpoint endpoint) throws IOException
addEndpoint
in interface DatagramDispatcher<Endpoint>
endpoint
- the endpoint descriptionIOException
- if the socket could not be created or
registered with the selectorpublic void removeEndpoint(Endpoint endpoint) throws IOException
removeEndpoint
in interface DatagramDispatcher<Endpoint>
endpoint
- the endpoint descriptionIOException
- if an error occurred when closing the socketpublic void stop() throws IOException
run()
method to stop.stop
in interface DatagramDispatcher<Endpoint>
IOException
Copyright © 2004–2019 The Apache Software Foundation. All rights reserved.