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

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

public abstract class Endpoint
extends 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().


Field Summary
static int ACCEPT_ENTRIES
          Integer representation of state.
static int DISCONNECTED
          Integer representation of state.
protected static Map<URL,Endpoint> endpoints
          Map containing all endpoints.
static int LISTENING
          Integer representation of state.
static List<String> METHODS_ALLOWED_IN_ACCEPT_ENTRIES
          Array containing names of methods only allowed to be invoked in state ACCEPT_ENTRIES.
protected  Node node
          The nodeon which this endpoint invokes methods.
static int STARTED
          Integer representation of state.
protected  URL url
          The URLthat can be used to connect to this endpoint.
 
Constructor Summary
protected Endpoint(Node node1, URL url1)
           
 
Method Summary
 void acceptEntries()
          Tell this endpoint that the node is now able to receive messages that request the storage and removal of entries.
protected abstract  void closeConnections()
          This method has to be overwritten by sub classes and is invoked by disconnect()to close all connections from the chord network.
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.
protected abstract  void entriesAcceptable()
          This method has to be overwritten by subclasses.
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.
protected  void notify(int s)
          Method to notify listeners about a change in state of this endpoint.
protected abstract  void openConnections()
          To implemented by sub classes.
 void register(EndpointStateListener listener)
          Register a listener that is notified when the state of this endpoint changes.
protected  void setState(int state1)
           
 String toString()
          Overwritten from Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

endpoints

protected static final Map<URL,Endpoint> endpoints
Map containing all endpoints. Key: URL. Value: Endpoint.


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 List<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!


url

protected URL url
The URLthat can be used to connect to this endpoint.


node

protected Node node
The nodeon which this endpoint invokes methods.

Constructor Detail

Endpoint

protected Endpoint(Node node1,
                   URL url1)
Parameters:
node1 - The Node this is the Endpoint for.
url1 - The URL that describes the location of this endpoint.
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.

notify

protected void notify(int s)
Method to notify listeners about a change in state of this endpoint.

Parameters:
s - The integer identifying the state to that the endpoint switched. See ACCEPT_ENTRIES, DISCONNECTED, LISTENING, and STARTED.

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.

setState

protected final void setState(int state1)
Parameters:
state1 - The state to set.

listen

public final void listen()
Tell this endpoint that it can listen to incoming messages from other chord nodes. TODO: This method may throw an exception when starting to listen for incoming connections.


openConnections

protected abstract void openConnections()
To implemented by sub classes. This method is called by listen()to make it possible for other chord nodes to connect to the node on that this endpoint invocates methods. TODO: This method may throw an exception when starting to listen for incoming connections.


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.


entriesAcceptable

protected abstract void entriesAcceptable()
This method has to be overwritten by subclasses. It is called from acceptEntries()to indicate that entries can now be accepted. So maybe if an endpoint queues incoming requests for storage or removal of entries this requests can be answered when endpoint changes it state to ACCEPT_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!!!


closeConnections

protected abstract void closeConnections()
This method has to be overwritten by sub classes and is invoked by disconnect()to close all connections from the chord network.


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:
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 String toString()
Overwritten from Object.

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


Copyright © 2004-2008 Karsten Loesing, Sven Kaffille - Distributed and Mobile Systems Group, Lehrstuhl für Praktische Informatik, Universität Bamberg. All Rights Reserved.