rice.pastry.wire
Class WireNodeHandle

java.lang.Object
  extended byjava.util.Observable
      extended byrice.p2p.commonapi.NodeHandle
          extended byrice.pastry.NodeHandle
              extended byrice.pastry.dist.DistNodeHandle
                  extended byrice.pastry.dist.DistCoalesedNodeHandle
                      extended byrice.pastry.wire.WireNodeHandle
All Implemented Interfaces:
LocalNodeI, MessageReceiver, java.util.Observer, SelectionKeyHandler, java.io.Serializable

public class WireNodeHandle
extends DistCoalesedNodeHandle
implements SelectionKeyHandler

Class which represents a node handle in the socket-based pastry protocol. Initially, all of the messages are sent over UDP. If a message is too large to be sent over the UDP protocol (as determined by the MAX_UDP_MESSAGE_SIZE), then a socket connection is opened to the remote node.

See Also:
Serialized Form

Field Summary
static int MAX_UDP_MESSAGE_SIZE
          the largest message size to send over UDP
static int PING_THROTTLE
          the throttle (pings only sent this many seconds)
static int SOCKET_BUFFER_SIZE
          the size of the "receive" buffer for the socket
static int STATE_USING_TCP
          using TCP
static int STATE_USING_UDP
          using UDP
static int STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT
          waiting to disconnect from TCP from remote side
static int STATE_USING_UDP_WAITING_TO_DISCONNECT
          waiting to disconnect
 
Fields inherited from class rice.pastry.dist.DistCoalesedNodeHandle
alive, DEFAULT_DISTANCE, isInPool, isLocal
 
Fields inherited from class rice.pastry.dist.DistNodeHandle
address, nodeId
 
Fields inherited from class rice.pastry.NodeHandle
localnode
 
Fields inherited from class rice.p2p.commonapi.NodeHandle
DECLARED_DEAD, DECLARED_LIVE, PROXIMITY_CHANGED
 
Fields inherited from interface rice.pastry.LocalNodeI
pending
 
Constructor Summary
WireNodeHandle(java.net.InetSocketAddress address, NodeId nid)
          Constructor.
WireNodeHandle(java.net.InetSocketAddress address, NodeId nid, PastryNode pn)
          Alternate constructor with local Pastry node.
 
Method Summary
 void accept(java.nio.channels.SelectionKey key)
          Requeired by the SelectionKeyHandler interface.
 void connect(java.nio.channels.SelectionKey key)
          Called by the socket manager whnever this node handle needs to complete it's connection to it's remote node.
 void connectToRemoteNode(java.util.Iterator messages)
          Method which initiates a connection to a remote node.
 void disconnect()
          Method that is designed to be called by the SocketManager when it wishes for this node handle to disconnect.
 int getState()
          Returns the state of this WireNodeHandle
 boolean isWriteEnabled()
          Gets the WriteEnabled attribute of the WireNodeHandle object
 void notifyKilled()
          prints Potentially lost the message for all messages in queue
 void notifyPotentiallyLostMessage(java.util.Iterator i)
          prints Potentially lost the message for all messages in the iterator
 boolean pingImpl()
          Ping the remote node now, and update the proximity metric.
 void pingResponse()
          Method which is called by the SocketPingManager when a ping response comes back for this node.
 void pingStarted()
          Method which is called by the PingMessage right before it is going to be sent across the wire.
 void read(java.nio.channels.SelectionKey key)
          Called by the socket manager whenever there is data to be read from this node handle's remote node.
 void receiveMessageImpl(Message msg)
          Called to send a message to the node corresponding to this handle.
 void receiveSocketMessage(SocketCommandMessage message)
          Method which is called when a SocketCommandMessage comes across an open socket for this node handle.
 void setKey(java.nio.channels.SelectionKey key, SocketCommandMessage scm)
          Method which sets the SelectionKey of this node handle.
 java.lang.String toStringImpl()
          implementation for toString()
 void write(java.nio.channels.SelectionKey key)
          Method which is called when the key becomes writable.
 
Methods inherited from class rice.pastry.dist.DistCoalesedNodeHandle
addObserver, afterSetLocalNode, clearChanged, countObservers, debug, deleteObserver, deleteObservers, equals, getIsInPool, hasChanged, hashCode, isAlive, markAlive, markDead, notifyObservers, notifyObservers, ping, proximity, receiveMessage, setChanged, setIsInPool, setProximity, toString, update
 
Methods inherited from class rice.pastry.dist.DistNodeHandle
getAddress, getNodeId
 
Methods inherited from class rice.pastry.NodeHandle
assertLocalNode, getId, getLocalNode, setLocalNode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_USING_UDP

public static final int STATE_USING_UDP
using UDP

See Also:
Constant Field Values

STATE_USING_TCP

public static final int STATE_USING_TCP
using TCP

See Also:
Constant Field Values

STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT

public static final int STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT
waiting to disconnect from TCP from remote side

See Also:
Constant Field Values

STATE_USING_UDP_WAITING_TO_DISCONNECT

public static final int STATE_USING_UDP_WAITING_TO_DISCONNECT
waiting to disconnect

See Also:
Constant Field Values

MAX_UDP_MESSAGE_SIZE

public static int MAX_UDP_MESSAGE_SIZE
the largest message size to send over UDP


SOCKET_BUFFER_SIZE

public static int SOCKET_BUFFER_SIZE
the size of the "receive" buffer for the socket


PING_THROTTLE

public static int PING_THROTTLE
the throttle (pings only sent this many seconds)

Constructor Detail

WireNodeHandle

public WireNodeHandle(java.net.InetSocketAddress address,
                      NodeId nid)
Constructor.

Parameters:
address - The address of the host on which this node resides
nid - The NodeId of this host

WireNodeHandle

public WireNodeHandle(java.net.InetSocketAddress address,
                      NodeId nid,
                      PastryNode pn)
Alternate constructor with local Pastry node.

Parameters:
address - The address of the host on which this node resides
nid - The NodeId of this host
pn - The local Pastry node
Method Detail

getState

public int getState()
Returns the state of this WireNodeHandle

Returns:
The state of this handle

isWriteEnabled

public boolean isWriteEnabled()
Gets the WriteEnabled attribute of the WireNodeHandle object

Returns:
The WriteEnabled value

setKey

public void setKey(java.nio.channels.SelectionKey key,
                   SocketCommandMessage scm)
Method which sets the SelectionKey of this node handle. Is designed to be called whenever a TCP connection has been established. All pending message will now be sent over TCP using the socket attached to this SelectionKey. If a socket has already been established, there is a protocol for determining which socket to close. If the address:port of the local is less than that of the remote, this node ignores the incoming key. Otherwise, it will kill it's own socket and use the new key as the "real" socket. NOTE: There are known problems with this implementation, especially under high stress.

Parameters:
key - The new SelectionKey
scm - The new Key value

receiveSocketMessage

public void receiveSocketMessage(SocketCommandMessage message)
Method which is called when a SocketCommandMessage comes across an open socket for this node handle.

Parameters:
message - The message coming across the wire.

notifyKilled

public void notifyKilled()
prints Potentially lost the message for all messages in queue


receiveMessageImpl

public void receiveMessageImpl(Message msg)
Called to send a message to the node corresponding to this handle.

Specified by:
receiveMessageImpl in class DistCoalesedNodeHandle
Parameters:
msg - Message to be delivered, may or may not be routeMessage.

notifyPotentiallyLostMessage

public void notifyPotentiallyLostMessage(java.util.Iterator i)
prints Potentially lost the message for all messages in the iterator

Parameters:
i - an iterator of messages to print out the error message for

connectToRemoteNode

public void connectToRemoteNode(java.util.Iterator messages)
Method which initiates a connection to a remote node. This is done by connecting to the server socket on the remote node. This can be called by the receiveMessageImpl, if there is a too-big message waiting to be sent, or by the TransmissionManager if there are too many messages in the queue.

Parameters:
messages - the initial queue

disconnect

public void disconnect()
Method that is designed to be called by the SocketManager when it wishes for this node handle to disconnect. Once this is called, the node handle will finish writing out any pending objects in the queue, and then send a DisconnectMessage to the remote node. Upon receiving this DisconnectMessage, the remote node will finish writing out any pending objects, and then will actually disconnect the socket.


accept

public void accept(java.nio.channels.SelectionKey key)
Requeired by the SelectionKeyHandler interface. Should never be called (because we never accept connections).

Specified by:
accept in interface SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

connect

public void connect(java.nio.channels.SelectionKey key)
Called by the socket manager whnever this node handle needs to complete it's connection to it's remote node. Is specified by the SelectionKeyHandler interface.

Specified by:
connect in interface SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

write

public void write(java.nio.channels.SelectionKey key)
Description copied from interface: SelectionKeyHandler
Method which is called when the key becomes writable.

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

read

public void read(java.nio.channels.SelectionKey key)
Called by the socket manager whenever there is data to be read from this node handle's remote node. Is specified from the SelectionKeyHandler interface.

Specified by:
read in interface SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

pingImpl

public boolean pingImpl()
Ping the remote node now, and update the proximity metric. This method ALWAYS uses UDP, even if there already is a TCP socket open.

Specified by:
pingImpl in class DistCoalesedNodeHandle
Returns:
liveness of remote node.

pingStarted

public void pingStarted()
Method which is called by the PingMessage right before it is going to be sent across the wire. Marks the beginning of a ping as now.


pingResponse

public void pingResponse()
Method which is called by the SocketPingManager when a ping response comes back for this node.


toStringImpl

public java.lang.String toStringImpl()
implementation for toString()

Specified by:
toStringImpl in class DistCoalesedNodeHandle
Returns:
A String representation of the node handle.





Imprint-Dataprotection