rice.pastry.wire
Class DatagramManager

public class DatagramManager
implements rice.pastry.wire.SelectionKeyHandler
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.
Version:
$Id: DatagramManager.java,v 1.9 2002/09/11 00:16:07 amislove Exp $
Author:
Alan Mislove
Constructor Detail

DatagramManager

public DatagramManager(rice.pastry.wire.WirePastryNode pastryNode,
                       rice.pastry.wire.SelectorManager manager,
                       int port)
Constructor.
Parameters:
node - The pastry node this SocketManager is serving
port - The port number this Datagram Manager should run on

Method Detail

resetAckNumber

public void resetAckNumber(rice.pastry.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(rice.pastry.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.

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.
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.
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.

sendAck

private boolean sendAck(java.net.InetSocketAddress address,
                        rice.pastry.wire.messaging.datagram.DatagramMessage message)
Method which prepares and enqueues an ack for an incoming message. If we have already seen the incoming data (i.e. it was a retransmission) this method returns false, signifying that the packet should be dropped.
Parameters:
address - The desintation address of the ack.
ackNum - The number of the incoming packet.

serialize

public 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.
Parameters:
o - The object to serialize
Returns:
A ByteBuffer containing the object

deserialize

public static java.lang.Object deserialize(java.nio.ByteBuffer buffer)
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.

accept

public void accept(java.nio.channels.SelectionKey key)
Specified by the SelectionKeyHandler - should NEVER be called (since datagrams are never accepted).
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).
Parameters:
key - The key that is connectable.