ePOST API

rice.pastry.socket
Class PingManager

java.lang.Object
  extended by rice.selector.SelectionKeyHandler
      extended by rice.pastry.socket.PingManager

public class PingManager
extends SelectionKeyHandler

Version:
$Id: PingManager.java 3203 2006-04-17 18:07:26Z jstewart $
Author:
jeffh To change the template for this generated type comment go to Window>Preferences>Java>Code Generation>Code and Comments

Nested Class Summary
 class PingManager.Envelope
          Internal class which holds a pending datagram
 
Field Summary
 int DATAGRAM_RECEIVE_BUFFER_SIZE
           
 int DATAGRAM_SEND_BUFFER_SIZE
           
protected static byte[] HEADER_PING
           
protected static byte[] HEADER_SHORT_PING
           
protected static byte[] HEADER_SHORT_PING_RESPONSE
           
static int HEADER_SIZE
           
protected  java.util.WeakHashMap lastPingTime
           
protected  java.util.ArrayList pendingMsgs
           
static int PING_THROTTLE
           
protected  java.util.WeakHashMap pingListeners
           
 boolean USE_SHORT_PINGS
           
 
Constructor Summary
PingManager(SocketPastryNode spn, SocketSourceRouteManager manager, EpochInetSocketAddress bindAddress, EpochInetSocketAddress proxyAddress)
           
 
Method Summary
static byte[] addHeader(SourceRoute path, java.lang.Object data, EpochInetSocketAddress localAddress, Environment env, Logger logger)
          Method which adds a header for the provided path to the given data.
protected  void addPingResponseListener(SourceRoute path, PingResponseListener prl)
          Adds a feature to the PingResponseListener attribute of the PingManager object
 SourceRoute decodeHeader(byte[] header)
          Method which adds a header for the provided path to the given data.
static java.lang.Object deserialize(byte[] array, Environment env, SocketPastryNode spn, Logger logger)
          Method which takes in a ByteBuffer read from a datagram, and deserializes the contained object.
 void enqueue(SourceRoute path, java.lang.Object msg)
          DESCRIBE THE METHOD
 void modifyKey(java.nio.channels.SelectionKey key)
          DESCRIBE THE METHOD
protected  void notifyPingResponseListeners(SourceRoute path, int proximity, long lastTimePinged)
          caller must synchronized(pingResponseTimes)
protected  void ping(SourceRoute path, PingResponseListener prl)
          Method which actually sends a ping to over the specified path, and returns the result to the specified listener.
 void read(java.nio.channels.SelectionKey key)
          DESCRIBE THE METHOD
protected  void readHeader(java.net.InetSocketAddress address)
          Method which processes an incoming message and hands it off to the appropriate handler.
 void receiveMessage(java.lang.Object message, int size, java.net.InetSocketAddress from)
          DESCRIBE THE METHOD
protected  void removePingResponseListener(SourceRoute path, PingResponseListener prl)
          Adds a feature to the PingResponseListener attribute of the PingManager object
protected  void resign()
          Makes this node resign from the network.
protected  void sendShortPing(SourceRoute route)
          Builds the data for a short ping
static byte[] serialize(java.lang.Object message, Environment environment, Logger logger)
          Method which serializes a given object into a ByteBuffer, in order to prepare it for writing.
protected  void shortPingReceived(SourceRoute route, byte[] payload)
          Builds the data for a short ping response
protected  void shortPingResponseReceived(SourceRoute route, byte[] payload)
          Processes a short ping response
 void stall()
          Internal testing method which simulates a stall.
 void write(java.nio.channels.SelectionKey key)
          DESCRIBE THE METHOD
 
Methods inherited from class rice.selector.SelectionKeyHandler
accept, connect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PING_THROTTLE

public static final int PING_THROTTLE
See Also:
Constant Field Values

USE_SHORT_PINGS

public final boolean USE_SHORT_PINGS

HEADER_PING

protected static byte[] HEADER_PING

HEADER_SHORT_PING

protected static byte[] HEADER_SHORT_PING

HEADER_SHORT_PING_RESPONSE

protected static byte[] HEADER_SHORT_PING_RESPONSE

HEADER_SIZE

public static int HEADER_SIZE

DATAGRAM_RECEIVE_BUFFER_SIZE

public final int DATAGRAM_RECEIVE_BUFFER_SIZE

DATAGRAM_SEND_BUFFER_SIZE

public final int DATAGRAM_SEND_BUFFER_SIZE

pingListeners

protected java.util.WeakHashMap pingListeners

lastPingTime

protected java.util.WeakHashMap lastPingTime

pendingMsgs

protected java.util.ArrayList pendingMsgs
Constructor Detail

PingManager

public PingManager(SocketPastryNode spn,
                   SocketSourceRouteManager manager,
                   EpochInetSocketAddress bindAddress,
                   EpochInetSocketAddress proxyAddress)
Parameters:
port - DESCRIBE THE PARAMETER
manager - DESCRIBE THE PARAMETER
pool - DESCRIBE THE PARAMETER
Method Detail

ping

protected void ping(SourceRoute path,
                    PingResponseListener prl)
Method which actually sends a ping to over the specified path, and returns the result to the specified listener. Note that if no ping response is ever received, the listener is never called.

Parameters:
path - The path to send the ping over
prl - The listener which should hear about the response

resign

protected void resign()
               throws java.io.IOException
Makes this node resign from the network. Is designed to be used for debugging and testing.

Throws:
java.io.IOException

stall

public void stall()
Internal testing method which simulates a stall. DO NOT USE!!!!!


sendShortPing

protected void sendShortPing(SourceRoute route)
Builds the data for a short ping


shortPingReceived

protected void shortPingReceived(SourceRoute route,
                                 byte[] payload)
                          throws java.io.IOException
Builds the data for a short ping response

Throws:
java.io.IOException

shortPingResponseReceived

protected void shortPingResponseReceived(SourceRoute route,
                                         byte[] payload)
                                  throws java.io.IOException
Processes a short ping response

Throws:
java.io.IOException

removePingResponseListener

protected void removePingResponseListener(SourceRoute path,
                                          PingResponseListener prl)
Adds a feature to the PingResponseListener attribute of the PingManager object

Parameters:
address - The feature to be added to the PingResponseListener attribute
prl - The feature to be added to the PingResponseListener attribute

addPingResponseListener

protected void addPingResponseListener(SourceRoute path,
                                       PingResponseListener prl)
Adds a feature to the PingResponseListener attribute of the PingManager object

Parameters:
address - The feature to be added to the PingResponseListener attribute
prl - The feature to be added to the PingResponseListener attribute

notifyPingResponseListeners

protected void notifyPingResponseListeners(SourceRoute path,
                                           int proximity,
                                           long lastTimePinged)
caller must synchronized(pingResponseTimes)

Parameters:
address -
proximity -
lastTimePinged -

enqueue

public void enqueue(SourceRoute path,
                    java.lang.Object msg)
DESCRIBE THE METHOD

Parameters:
address - DESCRIBE THE PARAMETER
msg - DESCRIBE THE PARAMETER

receiveMessage

public void receiveMessage(java.lang.Object message,
                           int size,
                           java.net.InetSocketAddress from)
                    throws java.io.IOException
DESCRIBE THE METHOD

Parameters:
message - DESCRIBE THE PARAMETER
address - DESCRIBE THE PARAMETER
Throws:
java.io.IOException

read

public void read(java.nio.channels.SelectionKey key)
DESCRIBE THE METHOD

Overrides:
read in class SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

write

public void write(java.nio.channels.SelectionKey key)
DESCRIBE THE METHOD

Overrides:
write in class SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

modifyKey

public void modifyKey(java.nio.channels.SelectionKey key)
DESCRIBE THE METHOD

Overrides:
modifyKey in class SelectionKeyHandler
Parameters:
key - DESCRIBE THE PARAMETER

serialize

public static byte[] serialize(java.lang.Object message,
                               Environment environment,
                               Logger logger)
                        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(byte[] array,
                                           Environment env,
                                           SocketPastryNode spn,
                                           Logger logger)
                                    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

addHeader

public static byte[] addHeader(SourceRoute path,
                               java.lang.Object data,
                               EpochInetSocketAddress localAddress,
                               Environment env,
                               Logger logger)
                        throws java.io.IOException
Method which adds a header for the provided path to the given data.

Returns:
The messag with a header attached
Throws:
java.io.IOException

decodeHeader

public SourceRoute decodeHeader(byte[] header)
                         throws java.io.IOException
Method which adds a header for the provided path to the given data.

Returns:
The messag with a header attached
Throws:
java.io.IOException

readHeader

protected void readHeader(java.net.InetSocketAddress address)
                   throws java.io.IOException
Method which processes an incoming message and hands it off to the appropriate handler.

Throws:
java.io.IOException

ePOST API

Copyright © 2001-2005 - Rice Pastry.