Rice Pastry API

rice.pastry.wire
Class WireNodeHandle

java.lang.Object
  |
  +--java.util.Observable
        |
        +--rice.p2p.commonapi.NodeHandle
              |
              +--rice.pastry.NodeHandle
                    |
                    +--rice.pastry.dist.DistNodeHandle
                          |
                          +--rice.pastry.wire.WireNodeHandle
All Implemented Interfaces:
LocalNodeI, MessageReceiver, java.util.Observer, SelectionKeyHandler, java.io.Serializable

public class WireNodeHandle
extends DistNodeHandle
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.

Version:
$Id: WireNodeHandle.java,v 1.22 2003/08/25 04:24:26 amislove Exp $
Author:
Alan Mislove
See Also:
Serialized Form

Field Summary
static int MAX_UDP_MESSAGE_SIZE
           
static int PING_THROTTLE
           
static int SOCKET_BUFFER_SIZE
           
static int STATE_USING_TCP
           
static int STATE_USING_UDP
           
static int STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT
           
static int STATE_USING_UDP_WAITING_TO_DISCONNECT
           
 
Fields inherited from class rice.pastry.dist.DistNodeHandle
address, alive, DEFAULT_DISTANCE, isInPool, isLocal, 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, rice.pastry.NodeId nid)
          Constructor.
WireNodeHandle(java.net.InetSocketAddress address, rice.pastry.NodeId nid, rice.pastry.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.LinkedList 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 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(rice.pastry.messaging.Message msg)
          Called to send a message to the node corresponding to this handle.
 void receiveSocketMessage(rice.pastry.wire.messaging.socket.SocketCommandMessage message)
          Method which is called when a SocketCommandMessage comes across an open socket for this node handle.
 void sendGreetingResponse(rice.pastry.wire.messaging.socket.HelloMessage hm)
           
 void setKey(java.nio.channels.SelectionKey key, rice.pastry.wire.messaging.socket.SocketCommandMessage scm)
          Method which sets the SelectionKey of this node handle.
 java.lang.String toStringImpl()
          Returns a String representation of this DistNodeHandle.
 void wakeup()
          Is called by the SelectorManager every time the manager is awakened.
 void write(java.nio.channels.SelectionKey key)
          Called by the socket manager whenever this node handle has registered interest in writing to it's remote node, and the socket is ready for writing.
 
Methods inherited from class rice.pastry.dist.DistNodeHandle
addObserver, afterSetLocalNode, clearChanged, countObservers, debug, deleteObserver, deleteObservers, equals, getAddress, getIsInPool, getNodeId, hasChanged, hashCode, isAlive, markAlive, markDead, notifyObservers, notifyObservers, ping, proximity, receiveMessage, setChanged, setIsInPool, setProximity, toString, update
 
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 int STATE_USING_UDP

STATE_USING_TCP

public static int STATE_USING_TCP

STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT

public static int STATE_USING_UDP_WAITING_FOR_TCP_DISCONNECT

STATE_USING_UDP_WAITING_TO_DISCONNECT

public static int STATE_USING_UDP_WAITING_TO_DISCONNECT

MAX_UDP_MESSAGE_SIZE

public static int MAX_UDP_MESSAGE_SIZE

SOCKET_BUFFER_SIZE

public static int SOCKET_BUFFER_SIZE

PING_THROTTLE

public static int PING_THROTTLE
Constructor Detail

WireNodeHandle

public WireNodeHandle(java.net.InetSocketAddress address,
                      rice.pastry.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,
                      rice.pastry.NodeId nid,
                      rice.pastry.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

receiveSocketMessage

public void receiveSocketMessage(rice.pastry.wire.messaging.socket.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.

receiveMessageImpl

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

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

connectToRemoteNode

public void connectToRemoteNode(java.util.LinkedList 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.


setKey

public void setKey(java.nio.channels.SelectionKey key,
                   rice.pastry.wire.messaging.socket.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

sendGreetingResponse

public void sendGreetingResponse(rice.pastry.wire.messaging.socket.HelloMessage hm)

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 - The key which is acceptable.

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 - The key which is connectable.

write

public void write(java.nio.channels.SelectionKey key)
Called by the socket manager whenever this node handle has registered interest in writing to it's remote node, and the socket is ready for writing. Is specified by the SelectionKeyHandler interface.

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 - The key which is readable.

wakeup

public void wakeup()
Is called by the SelectorManager every time the manager is awakened. Checks to make sure that if we are waiting to write data, we are registered as being interested in writing.

Specified by:
wakeup in interface SelectionKeyHandler

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 DistNodeHandle
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()
Description copied from class: DistNodeHandle
Returns a String representation of this DistNodeHandle. This method is to be run by the node handle which is in the NodeHandlePool.

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

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection