Package org.apache.axis2.transport.udp
Class IODispatcher
- java.lang.Object
-
- org.apache.axis2.transport.udp.IODispatcher
-
- All Implemented Interfaces:
Runnable
,DatagramDispatcher<Endpoint>
public class IODispatcher extends Object implements DatagramDispatcher<Endpoint>, Runnable
I/O dispatcher for incoming UDP packets. This class is responsible for receiving UDP packets and dispatch the processing of these packets to worker threads. It uses aSelector
to receive packets from multiple endpoints and aWorkerPool
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, aProcessPacketTask
instance is created and dispatched to a worker thread from the configured pool.The methods
addEndpoint(Endpoint)
,removeEndpoint(Endpoint)
andstop()
are thread safe and may be called from any thread. However, to avoid concurrency issues, the operation on the underlyingSelector
will always be executed by the thread executing therun()
method. The three methods mentioned above will block until the operation has completed.
-
-
Constructor Summary
Constructors Constructor Description IODispatcher(DatagramDispatcherCallback callback)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
IODispatcher
public IODispatcher(DatagramDispatcherCallback callback) throws IOException
Constructor.- Parameters:
callback
-- Throws:
IOException
- if theSelector
instance could not be created
-
-
Method Detail
-
addEndpoint
public void addEndpoint(Endpoint endpoint) throws IOException
Add a new endpoint. This method creates a new socket listening on the UDP port specified in the endpoint description and makes sure that incoming packets are routed to the specified service.- Specified by:
addEndpoint
in interfaceDatagramDispatcher<Endpoint>
- Parameters:
endpoint
- the endpoint description- Throws:
IOException
- if the socket could not be created or registered with the selector
-
removeEndpoint
public void removeEndpoint(Endpoint endpoint) throws IOException
Remove an endpoint. This causes the corresponding UDP socket to be closed.- Specified by:
removeEndpoint
in interfaceDatagramDispatcher<Endpoint>
- Parameters:
endpoint
- the endpoint description- Throws:
IOException
- if an error occurred when closing the socket
-
stop
public void stop() throws IOException
Stop the dispatcher. This method closes all sockets and causes the execution of therun()
method to stop.- Specified by:
stop
in interfaceDatagramDispatcher<Endpoint>
- Throws:
IOException
-
-