de.uniba.wiai.lspi.chord.com.socket
Class SocketProxy

java.lang.Object
  extended by de.uniba.wiai.lspi.chord.com.Node
      extended by de.uniba.wiai.lspi.chord.com.Proxy
          extended by de.uniba.wiai.lspi.chord.com.socket.SocketProxy
All Implemented Interfaces:
Runnable

public final class SocketProxy
extends Proxy
implements Runnable

This is the implementation of Proxy for the socket protocol. This connects to the endpoint of the node it represents by means of Sockets.


Field Summary
 
Fields inherited from class de.uniba.wiai.lspi.chord.com.Node
nodeID, nodeURL
 
Constructor Summary
protected SocketProxy(URL url, URL urlOfLocalNode1, ID nodeID1)
          Corresponding constructor to factory method create(URL, URL, ID).
 
Method Summary
static SocketProxy create(URL urlOfLocalNode, URL url)
          Establishes a connection from urlOfLocalNode to url.
protected static SocketProxy create(URL url, URL urlOfLocalNode, ID nodeID)
          Creates a SocketProxy representing the connection from urlOfLocalNode to url.
 void disconnect()
          Tells this proxy that it is not needed anymore.
protected  void finalize()
          Finalization ensures that the socket is closed if this proxy is not needed anymore.
 Node findSuccessor(ID key)
          Returns the Chord node which is responsible for the given key.
 void insertEntry(Entry entry)
          Stores the given object under the given ID.
 void insertReplicas(Set<Entry> replicas)
          Inserts replicates of the given entries.
 void leavesNetwork(Node predecessor)
          Inform a node that its predecessor leaves the network.
 List<Node> notify(Node potentialPredecessor)
          Requests this node's predecessor in result[0] and successor list in result[1..length-1].
 RefsAndEntries notifyAndCopyEntries(Node potentialPredecessor)
          Requests this node's predecessor, successor list and entries.
 void ping()
          Requests a sign of live.
 void removeEntry(Entry entry)
          Removes the given object from the list stored under the given ID.
 void removeReplicas(ID sendingNodeID, Set<Entry> replicas)
          Removes replicates of the given entries.
 Set<Entry> retrieveEntries(ID id)
          Returns all entries stored under the given ID.
 void run()
          The run methods waits for incoming Response made by this proxy and puts them into a datastructure from where the can be collected by the associated method call that made a Request to the Node, that this is the proxy for.
 String toString()
           
 
Methods inherited from class de.uniba.wiai.lspi.chord.com.Proxy
createConnection
 
Methods inherited from class de.uniba.wiai.lspi.chord.com.Node
equals, getNodeID, getNodeURL, hashCode, setNodeID, setNodeURL
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocketProxy

protected SocketProxy(URL url,
                      URL urlOfLocalNode1,
                      ID nodeID1)
Corresponding constructor to factory method create(URL, URL, ID).

Parameters:
url -
urlOfLocalNode1 -
nodeID1 -
See Also:
create(URL, URL, ID)
Method Detail

create

public static SocketProxy create(URL urlOfLocalNode,
                                 URL url)
                          throws CommunicationException
Establishes a connection from urlOfLocalNode to url. The connection is represented by the returned SocketProxy.

Parameters:
url - The URL to connect to.
urlOfLocalNode - URL of local node that establishes the connection.
Returns:
SocketProxy representing the established connection.
Throws:
CommunicationException - Thrown if establishment of connection to url failed.

create

protected static SocketProxy create(URL url,
                                    URL urlOfLocalNode,
                                    ID nodeID)
Creates a SocketProxy representing the connection from urlOfLocalNode to url. The connection is established when the first (remote) invocation with help of the SocketProxy occurs.

Parameters:
url - The URL of the remote node.
urlOfLocalNode - The URL of local node.
nodeID - The ID of the remote node.
Returns:
SocketProxy

findSuccessor

public Node findSuccessor(ID key)
                   throws CommunicationException
Description copied from class: Node
Returns the Chord node which is responsible for the given key.

Specified by:
findSuccessor in class Node
Parameters:
key -
Returns:
The successor of key.
Throws:
CommunicationException

notify

public List<Node> notify(Node potentialPredecessor)
                  throws CommunicationException
Description copied from class: Node
Requests this node's predecessor in result[0] and successor list in result[1..length-1]. This method is invoked by another node which thinks it is this node's predecessor.

Specified by:
notify in class Node
Parameters:
potentialPredecessor -
Returns:
List of references for the node invoking this method. See Node.notify(Node).
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

ping

public void ping()
          throws CommunicationException
Description copied from class: Node
Requests a sign of live. This method is invoked by another node which thinks it is this node's successor.

Specified by:
ping in class Node
Throws:
CommunicationException

insertEntry

public void insertEntry(Entry entry)
                 throws CommunicationException
Description copied from class: Node
Stores the given object under the given ID.

Specified by:
insertEntry in class Node
Parameters:
entry -
Throws:
CommunicationException

insertReplicas

public void insertReplicas(Set<Entry> replicas)
                    throws CommunicationException
Description copied from class: Node
Inserts replicates of the given entries.

Specified by:
insertReplicas in class Node
Parameters:
replicas -
Throws:
CommunicationException

leavesNetwork

public void leavesNetwork(Node predecessor)
                   throws CommunicationException
Description copied from class: Node
Inform a node that its predecessor leaves the network.

Specified by:
leavesNetwork in class Node
Parameters:
predecessor -
Throws:
CommunicationException

removeEntry

public void removeEntry(Entry entry)
                 throws CommunicationException
Description copied from class: Node
Removes the given object from the list stored under the given ID.

Specified by:
removeEntry in class Node
Parameters:
entry -
Throws:
CommunicationException

removeReplicas

public void removeReplicas(ID sendingNodeID,
                           Set<Entry> replicas)
                    throws CommunicationException
Description copied from class: Node
Removes replicates of the given entries.

Specified by:
removeReplicas in class Node
Parameters:
sendingNodeID -
replicas -
Throws:
CommunicationException

retrieveEntries

public Set<Entry> retrieveEntries(ID id)
                           throws CommunicationException
Description copied from class: Node
Returns all entries stored under the given ID.

Specified by:
retrieveEntries in class Node
Returns:
A Set of entries associated with id.
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

finalize

protected void finalize()
                 throws Throwable
Finalization ensures that the socket is closed if this proxy is not needed anymore.

Overrides:
finalize in class Object
Throws:
Throwable

disconnect

public void disconnect()
Tells this proxy that it is not needed anymore.

Specified by:
disconnect in class Node

run

public void run()
The run methods waits for incoming Response made by this proxy and puts them into a datastructure from where the can be collected by the associated method call that made a Request to the Node, that this is the proxy for.

Specified by:
run in interface Runnable

notifyAndCopyEntries

public RefsAndEntries notifyAndCopyEntries(Node potentialPredecessor)
                                    throws CommunicationException
Description copied from class: Node
Requests this node's predecessor, successor list and entries.

Specified by:
notifyAndCopyEntries in class Node
Parameters:
potentialPredecessor -
Returns:
See Node.notifyAndCopyEntries(Node).
Throws:
CommunicationException

toString

public String toString()
Overrides:
toString in class Node
Returns:
String representation of this.


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