rice.pastry.socket
Class SocketPastryNodeFactory

java.lang.Object
  |
  +--rice.pastry.dist.DistPastryNodeFactory
        |
        +--rice.pastry.socket.SocketPastryNodeFactory
All Implemented Interfaces:
rice.pastry.PastryNodeFactory, TransportListener

public class SocketPastryNodeFactory
extends rice.pastry.dist.DistPastryNodeFactory
implements TransportListener

A direct mimic to WirePastryNodeFactory class. An abstraction of the nodeId factory for distributed nodes. In order to obtain a nodeId factory, a client should use the getFactory method, passing in either PROTOCOL_TCP or PROTOCOL_UDP as the protocol, and the port number the factory should use.

Version:
$Id: SocketPastryNodeFactory.java,v 1.5 2003/10/05 18:50:53 glchen Exp $
Author:
Guanling Chen, Alan Mislove

Field Summary
protected  EventFactory _factory
           
protected  java.net.InetSocketAddress _laddr
           
protected  rice.pastry.NodeIdFactory _nidFactory
           
protected  int _port
           
protected  int _protocol
           
protected  rice.pastry.wire.messaging.socket.NodeIdResponseMessage _response
           
protected  boolean _serialize
           
protected  Transport _transport
           
static int leafSetMaintFreq
           
static int lSetSize
           
static int maxOpenSockets
           
static int PROTOCOL_TCP
           
static int PROTOCOL_UDP
           
static int routeSetMaintFreq
           
static int rtMax
           
 
Fields inherited from class rice.pastry.dist.DistPastryNodeFactory
PROTOCOL_RMI, PROTOCOL_WIRE
 
Constructor Summary
SocketPastryNodeFactory(boolean serialize, rice.pastry.NodeIdFactory nf, int proto, int startPort)
           
 
Method Summary
 void connectionClosed(Address peer)
          Called when an connection closed.
 void connectionOpened(Address peer)
          Called when an connection opened.
 void dataReceived(Adu adu, Header header)
          Called when new data is received.
private  void debug(java.lang.String s)
           
 rice.pastry.NodeHandle generateNodeHandle(java.net.InetSocketAddress address)
          Method which contructs a node handle (using the wire protocol) for the node at address NodeHandle.
private  java.net.InetSocketAddress getAddress(int portNumber)
          Method which constructs an InetSocketAddres for the local host with the specifed port number.
static rice.pastry.dist.DistPastryNodeFactory getFactory(boolean serialize, rice.pastry.NodeIdFactory nf, int protocol, int port)
          Static method which is designed to be used by clients needing a distrubuted pastry node factory.
 rice.pastry.PastryNode newNode(rice.pastry.NodeHandle bootstrap)
          Method which creates a Pastry node from the next port with a randomly generated NodeId.
 rice.pastry.PastryNode newNode(rice.pastry.NodeHandle bootstrap, rice.pastry.NodeId nodeId)
          Method which creates a Pastry node from the next port with a randomly generated NodeId.
 
Methods inherited from class rice.pastry.dist.DistPastryNodeFactory
getFactory, getNodeHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_TCP

public static int PROTOCOL_TCP

PROTOCOL_UDP

public static int PROTOCOL_UDP

rtMax

public static final int rtMax
See Also:
Constant Field Values

lSetSize

public static final int lSetSize
See Also:
Constant Field Values

maxOpenSockets

public static final int maxOpenSockets
See Also:
Constant Field Values

leafSetMaintFreq

public static final int leafSetMaintFreq
See Also:
Constant Field Values

routeSetMaintFreq

public static final int routeSetMaintFreq
See Also:
Constant Field Values

_nidFactory

protected rice.pastry.NodeIdFactory _nidFactory

_protocol

protected int _protocol

_port

protected int _port

_serialize

protected boolean _serialize

_transport

protected Transport _transport

_factory

protected EventFactory _factory

_laddr

protected java.net.InetSocketAddress _laddr

_response

protected rice.pastry.wire.messaging.socket.NodeIdResponseMessage _response
Constructor Detail

SocketPastryNodeFactory

public SocketPastryNodeFactory(boolean serialize,
                               rice.pastry.NodeIdFactory nf,
                               int proto,
                               int startPort)
Method Detail

dataReceived

public void dataReceived(Adu adu,
                         Header header)
Description copied from interface: TransportListener
Called when new data is received.

Specified by:
dataReceived in interface TransportListener

connectionOpened

public void connectionOpened(Address peer)
Description copied from interface: TransportListener
Called when an connection opened.

Specified by:
connectionOpened in interface TransportListener

connectionClosed

public void connectionClosed(Address peer)
Description copied from interface: TransportListener
Called when an connection closed.

Specified by:
connectionClosed in interface TransportListener

generateNodeHandle

public rice.pastry.NodeHandle generateNodeHandle(java.net.InetSocketAddress address)
Method which contructs a node handle (using the wire protocol) for the node at address NodeHandle.

Specified by:
generateNodeHandle in class rice.pastry.dist.DistPastryNodeFactory
Parameters:
address - The address of the remote node.
Returns:
A NodeHandle cooresponding to that address

newNode

public rice.pastry.PastryNode newNode(rice.pastry.NodeHandle bootstrap)
Method which creates a Pastry node from the next port with a randomly generated NodeId.

Specified by:
newNode in interface rice.pastry.PastryNodeFactory
Specified by:
newNode in class rice.pastry.dist.DistPastryNodeFactory
Parameters:
bootstrap - Node handle to bootstrap from.
Returns:
A node with a random ID and next port number.

newNode

public rice.pastry.PastryNode newNode(rice.pastry.NodeHandle bootstrap,
                                      rice.pastry.NodeId nodeId)
Method which creates a Pastry node from the next port with a randomly generated NodeId.

Specified by:
newNode in interface rice.pastry.PastryNodeFactory
Specified by:
newNode in class rice.pastry.dist.DistPastryNodeFactory
Parameters:
bootstrap - Node handle to bootstrap from.
Returns:
A node with a random ID and next port number.

getAddress

private java.net.InetSocketAddress getAddress(int portNumber)
Method which constructs an InetSocketAddres for the local host with the specifed port number.

Parameters:
portNumber - The port number to create the address at.
Returns:
An InetSocketAddress at the localhost with port portNumber.

debug

private void debug(java.lang.String s)

getFactory

public static rice.pastry.dist.DistPastryNodeFactory getFactory(boolean serialize,
                                                                rice.pastry.NodeIdFactory nf,
                                                                int protocol,
                                                                int port)
Static method which is designed to be used by clients needing a distrubuted pastry node factory. The protocol should be one of PROTOCOL_TCP or PROTOCOL_UDP.

Parameters:
protocol - The protocol to use (PROTOCOL_TCP or PROTOCOL_UDP)
port - The starting port.
Returns:
A DistPastryNodeFactory using the given protocol and port.
Throws:
java.lang.IllegalArgumentException - If protocol is an unsupported port.