Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.pastry.socket
Class SocketCollectionManager

    java.lang.Object
      rice.selector.SelectionKeyHandler
          rice.pastry.socket.SocketCollectionManager

public class SocketCollectionManager
extends SelectionKeyHandler

Class which maintains all outgoing open sockets. It is responsible for keeping only MAX_OPEN_SOCKETS number of client sockets open at once. It also binds a ServerSocketChannel to the specified port and listens for incoming connections. Once a connections is established, it uses the interal SocketConnector to read the greeting message (HelloMessage) off of the stream, and hands the connection off to the appropriate node handle.

Version:
  $Id: SocketCollectionManager.java,v 1.3 2004/03/08 19:53:57 amislove Exp $
Author:
  Alan Mislove

Nested Class Summary
`protected class` | `SocketCollectionManager.DeadChecker` DESCRIBE THE CLASS
`protected class` | `SocketCollectionManager.MessageRetry` Internal class which represents a message which is currently delayed, waiting for an open socket.
`protected class` | `SocketCollectionManager.SocketAccepter` Internal class which reads the greeting message off of a newly-accepted socket.
`protected class` | `SocketCollectionManager.SourceRouteManager` Private class which is tasked with maintaining a source route which goes through this node.

Field Summary
`long` | `BACKOFF_INITIAL` DESCRIBE THE FIELD
`int` | `BACKOFF_LIMIT` DESCRIBE THE FIELD
`protected static byte[]` | `HEADER_DIRECT` DESCRIBE THE FIELD
`static int` | `HEADER_SIZE` DESCRIBE THE FIELD
`protected static byte[]` | `HEADER_SOURCE_ROUTE` DESCRIBE THE FIELD
`protected Logger` | `logger` DESCRIBE THE FIELD
`int` | `MAX_OPEN_SOCKETS` DESCRIBE THE FIELD
`int` | `MAX_OPEN_SOURCE_ROUTES` DESCRIBE THE FIELD
`int` | `NUM_PING_TRIES` DESCRIBE THE FIELD
`int` | `PING_DELAY` DESCRIBE THE FIELD
`int` | `PING_JITTER` DESCRIBE THE FIELD
`protected RandomSource` | `random` DESCRIBE THE FIELD
`int` | `SOCKET_BUFFER_SIZE` DESCRIBE THE FIELD
`java.util.Hashtable` | `sockets` DESCRIBE THE FIELD
`int` | `WRITE_WAIT_TIME` DESCRIBE THE FIELD

Constructor Summary
`SocketCollectionManager(SocketPastryNode node, SocketSourceRouteManager manager, EpochInetSocketAddress bindAddress, EpochInetSocketAddress proxyAddress, RandomSource random)` Constructs a new SocketManager.

Method Summary
`void` | `accept(java.nio.channels.SelectionKey key)` Specified by the SelectionKeyHandler interface.
`void` | `bootstrap(SourceRoute path, Message message)` Method which sends bootstraps a node by sending message across the wire, using a fake IP address in the header so that the local node is not marked alive, and then closes the connection.
`protected void` | `checkLiveness(SourceRoute path)` Initiates a liveness test on the given address, if the remote node does not respond, it is declared dead.
`protected void` | `closeSocket(SourceRoute path)` Method which cloeses a socket to a given remote node handle, and updates the bookkeeping to keep track of this closing.
`void` | `declaredDead(EpochInetSocketAddress address)` Method which should be called when a remote node is declared dead.
`void` | `destroy()` Makes this node resign from the network.
`int` | `getNumSockets()` Gets the NumSockets attribute of the SocketCollectionManager object
`int` | `getNumSourceRoutes()` Gets the NumSourceRoutes attribute of the SocketCollectionManager object
`PingManager` | `getPingManager()` Method which returns the internal PingManager
`protected SourceRoute` | `getSocketToClose()` Internal method which returns the next socket to be closed
`boolean` | `isOpen(SourceRoute route)` Returns whether or not a socket is currently open to the given route
`protected void` | `openSocket(SourceRoute path, boolean bootstrap)` Method which opens a socket to a given remote node handle, and updates the bookkeeping to keep track of this socket
`void` | `ping(SourceRoute route)` Method which suggests a ping to the remote node.
`void` | `send(SourceRoute path, Message message, SocketSourceRouteManager.AddressManager am)` Method which sends a message across the wire.
`protected boolean` | `sendInternal(SourceRoute path, Message message)` Method which sends a message across the wire.
`protected void` | `socketClosed(SourceRoute path, rice.pastry.socket.SocketCollectionManager.SocketManager manager)` Method which is designed to be called *ONCE THE SOCKET HAS BEEN CLOSED*.
`protected void` | `socketOpened(SourceRoute path, rice.pastry.socket.SocketCollectionManager.SocketManager manager)` Method which is designed to be called by node handles when they wish to open a socket to their remote node.
`protected void` | `socketUpdated(SourceRoute path)` Method which is designed to be called whenever a node has network activity.
`protected void` | `sourceRouteClosed(SocketCollectionManager.SourceRouteManager manager)` Method which is designed to be called *ONCE THE SOURCE ROUTE MANAGER HAS BEEN CLOSED*.
`protected void` | `sourceRouteOpened(SocketCollectionManager.SourceRouteManager manager)` Method which is designed to be called when a new source route manager is created.
`protected void` | `sourceRouteUpdated(SocketCollectionManager.SourceRouteManager manager)` Method which is designed to be called whenever a source route has network activity.
`void` | `stall()` Internal testing method which simulates a stall.

Methods inherited from class rice.selector.SelectionKeyHandler
`connect, modifyKey, read, write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MAX_OPEN_SOCKETS

    public final int MAX_OPEN_SOCKETS

  DESCRIBE THE FIELD

### MAX_OPEN_SOURCE_ROUTES

    public final int MAX_OPEN_SOURCE_ROUTES

  DESCRIBE THE FIELD

### SOCKET_BUFFER_SIZE

    public final int SOCKET_BUFFER_SIZE

  DESCRIBE THE FIELD

### PING_DELAY

    public final int PING_DELAY

  DESCRIBE THE FIELD

### PING_JITTER

    public final int PING_JITTER

  DESCRIBE THE FIELD

### NUM_PING_TRIES

    public final int NUM_PING_TRIES

  DESCRIBE THE FIELD

### WRITE_WAIT_TIME

    public final int WRITE_WAIT_TIME

  DESCRIBE THE FIELD

### BACKOFF_INITIAL

    public final long BACKOFF_INITIAL

  DESCRIBE THE FIELD

### BACKOFF_LIMIT

    public final int BACKOFF_LIMIT

  DESCRIBE THE FIELD

### sockets

    public java.util.Hashtable sockets

  DESCRIBE THE FIELD

### logger

    protected Logger logger

  DESCRIBE THE FIELD

### random

    protected RandomSource random

  DESCRIBE THE FIELD

### HEADER_DIRECT

    protected static byte[] HEADER_DIRECT

  DESCRIBE THE FIELD

### HEADER_SOURCE_ROUTE

    protected static byte[] HEADER_SOURCE_ROUTE

  DESCRIBE THE FIELD

### HEADER_SIZE

    public static int HEADER_SIZE

  DESCRIBE THE FIELD

Constructor Detail

### SocketCollectionManager

    public SocketCollectionManager(SocketPastryNode node,
                                   SocketSourceRouteManager manager,
                                   EpochInetSocketAddress bindAddress,
                                   EpochInetSocketAddress proxyAddress,
                                   RandomSource random)

  Constructs a new SocketManager.

Parameters:
  `node` - The pastry node this manager is serving
  `manager` - DESCRIBE THE PARAMETER
  `bindAddress` - DESCRIBE THE PARAMETER
  `proxyAddress` - DESCRIBE THE PARAMETER
  `random` - DESCRIBE THE PARAMETER

Method Detail

### isOpen

    public boolean isOpen(SourceRoute route)

  Returns whether or not a socket is currently open to the given route

  Parameters:
    `route` - The route
  Returns:
    Whether or not a socket is currently open to that route

### getSocketToClose

    protected SourceRoute getSocketToClose()

  Internal method which returns the next socket to be closed

  Returns:
    The next socket to be closed

### getNumSourceRoutes

    public int getNumSourceRoutes()

  Gets the NumSourceRoutes attribute of the SocketCollectionManager object

  Returns:
    The NumSourceRoutes value

### getNumSockets

    public int getNumSockets()

  Gets the NumSockets attribute of the SocketCollectionManager object

  Returns:
    The NumSockets value

### getPingManager

    public PingManager getPingManager()

  Method which returns the internal PingManager

  Returns:
    The PingManager value

### bootstrap

    public void bootstrap(SourceRoute path,
                          Message message)

  Method which sends bootstraps a node by sending message across the wire, using a fake IP address in the header so that the local node is not marked alive, and then closes the connection.

  Parameters:
    `message` - The message to send
    `path` - DESCRIBE THE PARAMETER

### send

    public void send(SourceRoute path,
                     Message message,
                     SocketSourceRouteManager.AddressManager am)

  Method which sends a message across the wire.

  Parameters:
    `message` - The message to send
    `path` - DESCRIBE THE PARAMETER
    `am` - DESCRIBE THE PARAMETER

### ping

    public void ping(SourceRoute route)

  Method which suggests a ping to the remote node.

  Parameters:
    `route` - The route to use

### checkLiveness

    protected void checkLiveness(SourceRoute path)

  Initiates a liveness test on the given address, if the remote node does not respond, it is declared dead.

  Parameters:
    `path` - DESCRIBE THE PARAMETER

### declaredDead

    public void declaredDead(EpochInetSocketAddress address)

  Method which should be called when a remote node is declared dead. This method will close any outstanding sockets, and will reroute any pending messages

  Parameters:
    `address` - The address which was declared dead

### sendInternal

    protected boolean sendInternal(SourceRoute path,
                                   Message message)

  Method which sends a message across the wire.

  Parameters:
    `message` - The message to send
    `path` - DESCRIBE THE PARAMETER
  Returns:
    DESCRIBE THE RETURN VALUE

### accept

    public void accept(java.nio.channels.SelectionKey key)

  Specified by the SelectionKeyHandler interface. Is called whenever a key has become acceptable, representing an incoming connection. This method will accept the connection, and attach a SocketConnector in order to read the greeting off of the channel. Once the greeting has been read, the connector will hand the channel off to the appropriate node handle.

  Overrides:
    `accept` in class `SelectionKeyHandler`
  Parameters:
    `key` - The key which is acceptable.

### openSocket

    protected void openSocket(SourceRoute path,
                              boolean bootstrap)

  Method which opens a socket to a given remote node handle, and updates the bookkeeping to keep track of this socket

  Parameters:
    `path` - DESCRIBE THE PARAMETER
    `bootstrap` - DESCRIBE THE PARAMETER

### closeSocket

    protected void closeSocket(SourceRoute path)

  Method which cloeses a socket to a given remote node handle, and updates the bookkeeping to keep track of this closing. Note that this method does not completely close the socket, rather, it simply calls shutdown(), which starts the shutdown process.

  Parameters:
    `path` - DESCRIBE THE PARAMETER

### socketOpened

    protected void socketOpened(SourceRoute path,
                                rice.pastry.socket.SocketCollectionManager.SocketManager manager)

  Method which is designed to be called by node handles when they wish to open a socket to their remote node. This method will determine if another node handle needs to disconnect, and will disconnect the ejected node handle if necessary.

  Parameters:
    `manager` - The manager for the remote address
    `path` - DESCRIBE THE PARAMETER

### socketClosed

    protected void socketClosed(SourceRoute path,
                                rice.pastry.socket.SocketCollectionManager.SocketManager manager)

  Method which is designed to be called *ONCE THE SOCKET HAS BEEN CLOSED*. This method simply updates the bookeeping, but does not actually close the socket.

  Parameters:
    `manager` - The manager for the remote address
    `path` - DESCRIBE THE PARAMETER

### socketUpdated

    protected void socketUpdated(SourceRoute path)

  Method which is designed to be called whenever a node has network activity. This is used to determine which nodes should be disconnected, should it be necessary (implementation of a LRU stack).

  Parameters:
    `path` - DESCRIBE THE PARAMETER

### sourceRouteOpened

    protected void sourceRouteOpened(SocketCollectionManager.SourceRouteManager manager)

  Method which is designed to be called when a new source route manager is created. This method will close another source route, if there are too many source routes already open through this node.

  Parameters:
    `manager` - The manager for the remote address

### sourceRouteClosed

    protected void sourceRouteClosed(SocketCollectionManager.SourceRouteManager manager)

  Method which is designed to be called *ONCE THE SOURCE ROUTE MANAGER HAS BEEN CLOSED*. This method simply updates the bookeeping, but does not actually close the source route.

  Parameters:
    `manager` - The manager for the remote address

### sourceRouteUpdated

    protected void sourceRouteUpdated(SocketCollectionManager.SourceRouteManager manager)

  Method which is designed to be called whenever a source route has network activity. This is used to determine which source routes should be disconnected, should it be necessary (implementation of a LRU stack).

  Parameters:
    `manager` - The manager with activity

### destroy

    public void destroy()
                 throws java.io.IOException

  Makes this node resign from the network. Is designed to be used for debugging and testing.

  Throws:
    `java.io.IOException` - DESCRIBE THE EXCEPTION

### stall

    public void stall()

  Internal testing method which simulates a stall. DO NOT USE!!!!!

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.