rice.pastry.wire
Class DatagramManager

java.lang.Object
  extended byrice.pastry.wire.DatagramManager
All Implemented Interfaces:
NeedsWakeUp, SelectionKeyHandler

public class DatagramManager
extends java.lang.Object
implements SelectionKeyHandler, NeedsWakeUp

This class is an implementation of a UDP-based Pastry protocol. All messages are sent across the network as datagrams. It uses a TransmissionManager in order to ensure (ordered) delivery.


Field Summary
static int DATAGRAM_RECEIVE_BUFFER_SIZE
          the size of the buffer used to read incoming datagrams must be big enough to encompass multiple datagram packets
static int DATAGRAM_SEND_BUFFER_SIZE
          the size of the buffer used to send outgoing datagrams this is also the largest message size than can be sent via UDP
 
Constructor Summary
DatagramManager(WirePastryNode pastryNode, SelectorManager manager, int port)
          Constructor.
 
Method Summary
 void accept(java.nio.channels.SelectionKey key)
          Specified by the SelectionKeyHandler - should NEVER be called (since datagrams are never accepted).
 void connect(java.nio.channels.SelectionKey key)
          Specified by the SelectionKeyHandler - should NEVER be called (since datagrams are never connected).
static java.lang.Object deserialize(java.nio.ByteBuffer buffer)
          Method which takes in a ByteBuffer read from a datagram, and deserializes the contained object.
 void notifyKilled()
           
 void read(java.nio.channels.SelectionKey key)
          Specified by the SelectionKeyHandler interface - is called when there is a datagram ready to be read.
 void resetAckNumber(NodeId node)
          Designed to be called by a node handle when a socket is open in order to reset the seqence number of UDP.
static java.nio.ByteBuffer serialize(java.lang.Object o)
          Method which serializes a given object into a ByteBuffer, in order to prepare it for writing.
 void wakeup()
          Called by the SelectorManager whenever it is awoken.
 void write(NodeId destination, java.net.InetSocketAddress address, java.lang.Object o)
          Method designed for node handles to use when they wish to write to their remote node.
 void write(java.nio.channels.SelectionKey key)
          Specified by the SelectionKeyHandler interface - is called when there is space in the DatagramChannel's buffer to write some data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATAGRAM_RECEIVE_BUFFER_SIZE

public static int DATAGRAM_RECEIVE_BUFFER_SIZE
the size of the buffer used to read incoming datagrams must be big enough to encompass multiple datagram packets


DATAGRAM_SEND_BUFFER_SIZE

public static int DATAGRAM_SEND_BUFFER_SIZE
the size of the buffer used to send outgoing datagrams this is also the largest message size than can be sent via UDP

Constructor Detail

DatagramManager

public DatagramManager(WirePastryNode pastryNode,
                       SelectorManager manager,
                       int port)
Constructor.

Parameters:
port - The port number this Datagram Manager should run on
pastryNode - the pastry node that the Datagram Manager is servicing
manager - The selector manager that calls into this Datagram Manager
Method Detail

notifyKilled

public void notifyKilled()

resetAckNumber

public void resetAckNumber(NodeId node)
Designed to be called by a node handle when a socket is open in order to reset the seqence number of UDP.

Parameters:
node - The NodeId to reset.

write

public void write(NodeId destination,
                  java.net.InetSocketAddress address,
                  java.lang.Object o)
Method designed for node handles to use when they wish to write to their remote node. This method enqueues their message, and will eventually send the message to the remote node.

Parameters:
address - The remote address to send the message to.
o - The object that should be sent.
destination - DESCRIBE THE PARAMETER

read

public void read(java.nio.channels.SelectionKey key)
Specified by the SelectionKeyHandler interface - is called when there is a datagram ready to be read.

Specified by:
read in interface SelectionKeyHandler
Parameters:
key - The SelectionKey which is readable.

write

public void write(java.nio.channels.SelectionKey key)
Specified by the SelectionKeyHandler interface - is called when there is space in the DatagramChannel's buffer to write some data.

Specified by:
write in interface SelectionKeyHandler
Parameters:
key - The key which is writable

wakeup

public void wakeup()
Called by the SelectorManager whenever it is awoken. This allows the TransmissionManager to check and make sure that if we are waiting to write, we are registered as being interested in writing.

Specified by:
wakeup in interface NeedsWakeUp

accept

public void accept(java.nio.channels.SelectionKey key)
Specified by the SelectionKeyHandler - should NEVER be called (since datagrams are never accepted).

Specified by:
accept in interface SelectionKeyHandler
Parameters:
key - The key that is acceptable.

connect

public void connect(java.nio.channels.SelectionKey key)
Specified by the SelectionKeyHandler - should NEVER be called (since datagrams are never connected).

Specified by:
connect in interface SelectionKeyHandler
Parameters:
key - The key that is connectable.

serialize

public static java.nio.ByteBuffer serialize(java.lang.Object o)
                                     throws java.io.IOException
Method which serializes a given object into a ByteBuffer, in order to prepare it for writing.

Parameters:
o - The object to serialize
Returns:
A ByteBuffer containing the object
Throws:
java.io.IOException - if the object can't be serialized

deserialize

public static java.lang.Object deserialize(java.nio.ByteBuffer buffer)
                                    throws java.io.IOException
Method which takes in a ByteBuffer read from a datagram, and deserializes the contained object.

Parameters:
buffer - The buffer read from the datagram.
Returns:
The deserialized object.
Throws:
java.io.IOException - if the buffer can't be deserialized





Imprint-Dataprotection