org.apache.axis2.transport.udp
Class IODispatcher

java.lang.Object
  extended by org.apache.axis2.transport.udp.IODispatcher
All Implemented Interfaces:
java.lang.Runnable, DatagramDispatcher<Endpoint>

public class IODispatcher
extends java.lang.Object
implements DatagramDispatcher<Endpoint>, java.lang.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 a 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(String) 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 Summary
IODispatcher(DatagramDispatcherCallback callback)
          Constructor.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IODispatcher

public IODispatcher(DatagramDispatcherCallback callback)
             throws java.io.IOException
Constructor.

Parameters:
callback -
Throws:
java.io.IOException - if the Selector instance could not be created
Method Detail

addEndpoint

public void addEndpoint(Endpoint endpoint)
                 throws java.io.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 interface DatagramDispatcher<Endpoint>
Parameters:
endpoint - the endpoint description
Throws:
java.io.IOException - if the socket could not be created or registered with the selector

removeEndpoint

public void removeEndpoint(Endpoint endpoint)
                    throws java.io.IOException
Remove an endpoint. This causes the corresponding UDP socket to be closed.

Specified by:
removeEndpoint in interface DatagramDispatcher<Endpoint>
Parameters:
endpoint - the endpoint description
Throws:
java.io.IOException - if an error occurred when closing the socket

stop

public void stop()
          throws java.io.IOException
Stop the dispatcher. This method closes all sockets and causes the execution of the run() method to stop.

Specified by:
stop in interface DatagramDispatcher<Endpoint>
Throws:
java.io.IOException

run

public void run()
Run the I/O dispatcher. This method contains the event loop that polls the selector, reads the incoming packets and dispatches the work. It only returns when stop() is called.

Specified by:
run in interface java.lang.Runnable


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.