de.uniba.wiai.lspi.chord.com
Class Endpoint

java.lang.Object
  extended by de.uniba.wiai.lspi.chord.com.Endpoint
Direct Known Subclasses:
SocketEndpoint, ThreadEndpoint

public abstract class Endpoint
extends java.lang.Object

This class represents an endpoint, which wraps a Node, so that other nodes can connect to the node using a protocol.

This class must be extended by endpoints that support a certain protocol as e.g. RMI or a protocol over Sockets.

This is the abstract class that has to be implemented by all Endpoints. An Endpoint enables other chord peers to connect to a node with help of a given protocol. Each node in a chord network has to have exactly one endpoint.

For each protocol that shall be supported a separate endpoint has to be implemented. To initialise endpoints for a Node an URL has to be provided to the createEndpoint(Node, URL) endpoint factory method. This methods tries to determine the endpoint with help of the protocol names defined by the url. Supported protocols can be found in the URL class.

An Endpoint can be in three states:

In state STARTED the endpoint has been initialised but does not listen to (possibly) incoming messages from the chord network. An endpoint gets into this state if it is created with help of its constructor.

In state LISTENING the endpoint accepts messages that are received from the chord network to update the finger table or request the predecessor or successor of the node of this endpoint. The transition to this state is made by invocation of listen().

In state ACCEPT_ENTRIES. This endpoint accepts messages from the chord network, that request storage or removal of entries from the DHT. The transition to this state is made by invocation of acceptEntries().

Version:
1.0.5 modified, 0.99b
Author:
sven, bojanm, francesco

Field Summary
static int ACCEPT_ENTRIES
          Integer representation of state.
static int DISCONNECTED
          Integer representation of state.
static int LISTENING
          Integer representation of state.
static java.util.List<java.lang.String> METHODS_ALLOWED_IN_ACCEPT_ENTRIES
          Array containing names of methods only allowed to be invoked in state ACCEPT_ENTRIES.
static int STARTED
          Integer representation of state.
 
Method Summary
 void acceptEntries()
          Tell this endpoint that the node is now able to receive messages that request the storage and removal of entries.
static Endpoint createEndpoint(Node node, URL url)
          Create the endpoints for the protocol given by url.
 void deregister(EndpointStateListener listener)
          Remove a listener that listened for state changes of this endpoint.
 void disconnect()
          Tell this endpoint to disconnect and close all connections.
static Endpoint getEndpoint(URL url)
          Get the Endpoint for the given url.
 Node getNode()
           
 int getState()
           
 URL getURL()
          Get the URLof this endpoint.
 void listen()
          Tell this endpoint that it can listen to incoming messages from other chord nodes.
 void register(EndpointStateListener listener)
          Register a listener that is notified when the state of this endpoint changes.
 java.lang.String toString()
          Overwritten from Object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STARTED

public static final int STARTED
Integer representation of state.

See Also:
Constant Field Values

LISTENING

public static final int LISTENING
Integer representation of state.

See Also:
Constant Field Values

ACCEPT_ENTRIES

public static final int ACCEPT_ENTRIES
Integer representation of state.

See Also:
Constant Field Values

DISCONNECTED

public static final int DISCONNECTED
Integer representation of state.

See Also:
Constant Field Values

METHODS_ALLOWED_IN_ACCEPT_ENTRIES

public static final java.util.List<java.lang.String> METHODS_ALLOWED_IN_ACCEPT_ENTRIES
Array containing names of methods only allowed to be invoked in state ACCEPT_ENTRIES. Remember to eventually edit this array if you change the methods in interface Node. The method names contained in this array must be sorted!

Method Detail

getNode

public final Node getNode()
Returns:
Returns the node.

register

public final void register(EndpointStateListener listener)
Register a listener that is notified when the state of this endpoint changes.

Parameters:
listener - The listener to register.

deregister

public final void deregister(EndpointStateListener listener)
Remove a listener that listened for state changes of this endpoint.

Parameters:
listener - The listener instance to be removed.

getURL

public URL getURL()
Get the URLof this endpoint.

Returns:
The URLthat can be used to connect to this endpoint.

getState

public final int getState()
Returns:
Returns the state.

listen

public final void listen()
Tell this endpoint that it can listen to incoming messages from other chord nodes.


acceptEntries

public final void acceptEntries()
Tell this endpoint that the node is now able to receive messages that request the storage and removal of entries.


disconnect

public final void disconnect()
Tell this endpoint to disconnect and close all connections. If this method has been invoked the endpoint must be not reused!!!


createEndpoint

public static Endpoint createEndpoint(Node node,
                                      URL url)
Create the endpoints for the protocol given by url. An URL must have a known protocol. An endpoint for an URL can only be create once and then be obtained with help of getEndpoint(URL). An endpoint for an url must again be created if the disconnect() has been invoked.

Parameters:
node - The node to which this endpoint delegates incoming requests.
url - The URL under which node will be reachable by other nodes.
Returns:
The endpoint created for node for the protocol specified in url.
Throws:
java.lang.RuntimeException - This can occur if any error that cannot be handled by this method occurs during endpoint creation.

getEndpoint

public static Endpoint getEndpoint(URL url)
Get the Endpoint for the given url.

Parameters:
url -
Returns:
The endpoint for provided url.

toString

public java.lang.String toString()
Overwritten from Object.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this endpoint.