org.sapia.ubik.mcast
Class UDPUnicastDispatcher

java.lang.Object
  extended by java.lang.Thread
      extended by org.sapia.ubik.mcast.server.UDPServer
          extended by org.sapia.ubik.mcast.UDPUnicastDispatcher
All Implemented Interfaces:
java.lang.Runnable, UnicastDispatcher

public class UDPUnicastDispatcher
extends UDPServer
implements UnicastDispatcher

Implements the UnicastDispatcher interface over UDP.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class org.sapia.ubik.mcast.server.UDPServer
_sock
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
UDPUnicastDispatcher(int soTimeout, EventConsumer consumer)
          Constructor for UnicastDispatcherImpl.
UDPUnicastDispatcher(int soTimeout, int port, EventConsumer consumer)
          Constructor for UnicastDispatcherImpl.
 
Method Summary
protected  int bufSize()
           
 void close()
          Closes this instance - which should not be used thereafter.
 void dispatch(ServerAddress addr, java.lang.String type, java.lang.Object data)
          Dispatches the given data to the node whose address is given.
 ServerAddress getAddress()
          Returns the address of this instance.
protected  void handle(java.net.DatagramPacket pack, java.net.DatagramSocket sock)
           
protected  void handlePacketSizeToShort(java.net.DatagramPacket pack)
           
protected  void handleSoTimeout()
           
 RespList send(java.util.List addresses, java.lang.String type, java.lang.Object data)
          Sends the given data to the list of destinations specified, and returning the responses received from each destination.
 Response send(ServerAddress addr, java.lang.String type, java.lang.Object data)
          Sends the given data to the node whose address is given, returning the corresponding response - received from the destination.
 void setBufsize(int size)
          Sets this instance's "buffer size".
 void setSoTimeoutListener(SocketTimeoutListener listener)
          Allows to set a listener that will be notified when the internal UDP socket used by this instance reaches a timeout.
 void start()
          Starts this instance - should be called prior to using this instance.
 
Methods inherited from class org.sapia.ubik.mcast.server.UDPServer
getPort, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UDPUnicastDispatcher

public UDPUnicastDispatcher(int soTimeout,
                            EventConsumer consumer)
                     throws java.net.SocketException
Constructor for UnicastDispatcherImpl.

Throws:
java.net.SocketException

UDPUnicastDispatcher

public UDPUnicastDispatcher(int soTimeout,
                            int port,
                            EventConsumer consumer)
                     throws java.net.SocketException
Constructor for UnicastDispatcherImpl.

Throws:
java.net.SocketException
Method Detail

setBufsize

public void setBufsize(int size)
Description copied from interface: UnicastDispatcher
Sets this instance's "buffer size". The size is specified in bytes, and can be interpreted differently from one implementation to another - for example, for UDP-based implementation, it can correspond to the datagram packet size.

Specified by:
setBufsize in interface UnicastDispatcher
Overrides:
setBufsize in class UDPServer
See Also:
UnicastDispatcher.setBufsize(int)

setSoTimeoutListener

public void setSoTimeoutListener(SocketTimeoutListener listener)
Allows to set a listener that will be notified when the internal UDP socket used by this instance reaches a timeout.

Specified by:
setSoTimeoutListener in interface UnicastDispatcher
See Also:
DatagramSocket.setSoTimeout(int), ServerSocket.setSoTimeout(int)

start

public void start()
Description copied from interface: UnicastDispatcher
Starts this instance - should be called prior to using this instance.

Specified by:
start in interface UnicastDispatcher
Overrides:
start in class java.lang.Thread
See Also:
UnicastDispatcher.start()

close

public void close()
Description copied from interface: UnicastDispatcher
Closes this instance - which should not be used thereafter.

Specified by:
close in interface UnicastDispatcher
See Also:
UnicastDispatcher.close()

dispatch

public void dispatch(ServerAddress addr,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Description copied from interface: UnicastDispatcher
Dispatches the given data to the node whose address is given.

Specified by:
dispatch in interface UnicastDispatcher
Parameters:
addr - a ServerAddress that corresponds to the destination node for the data passed in.
type - the logical type of the data that is sent - allows the receiver to perform logic according to the "type".
data - the Object to send.
Throws:
java.io.IOException
See Also:
UnicastDispatcher.dispatch(ServerAddress, String, Object)

send

public Response send(ServerAddress addr,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Description copied from interface: UnicastDispatcher
Sends the given data to the node whose address is given, returning the corresponding response - received from the destination.

Specified by:
send in interface UnicastDispatcher
Parameters:
addr - a ServerAddress that corresponds to the destination node for the data passed in.
type - the logical type of the data that is sent - allows the receiver to perform logic according to the "type".
data - the Object to send.
Returns:
a Response.
Throws:
java.io.IOException
See Also:
UnicastDispatcher.send(ServerAddress, String, Object)

send

public RespList send(java.util.List addresses,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Description copied from interface: UnicastDispatcher
Sends the given data to the list of destinations specified, and returning the responses received from each destination.

Specified by:
send in interface UnicastDispatcher
Parameters:
addresses - a List of ServerAddress instances.
type - the logical type of the data that is sent - allows the receiver to perform logic according to the "type".
data - the Object to send.
Returns:
a RespList.
Throws:
java.io.IOException
See Also:
UnicastDispatcher.send(java.util.List, String, Object)

getAddress

public ServerAddress getAddress()
                         throws java.lang.IllegalStateException
Description copied from interface: UnicastDispatcher
Returns the address of this instance.

Specified by:
getAddress in interface UnicastDispatcher
Returns:
a ServerAddress.
Throws:
java.lang.IllegalStateException - if the address of this instance is not yet available. This can be the case if the start() method has not yet been called; therefore, always call start() before calling this method.
See Also:
UnicastDispatcher.getAddress()

handleSoTimeout

protected void handleSoTimeout()
Specified by:
handleSoTimeout in class UDPServer
See Also:
UDPServer.handleSoTimeout()

handlePacketSizeToShort

protected void handlePacketSizeToShort(java.net.DatagramPacket pack)
Specified by:
handlePacketSizeToShort in class UDPServer
See Also:
UDPServer.handlePacketSizeToShort(DatagramPacket)

bufSize

protected int bufSize()
Overrides:
bufSize in class UDPServer
See Also:
UDPServer.bufSize()

handle

protected void handle(java.net.DatagramPacket pack,
                      java.net.DatagramSocket sock)
Specified by:
handle in class UDPServer
See Also:
UDPServer.handle(DatagramPacket, DatagramSocket)


Copyright © 2010 Sapia OSS. All Rights Reserved.