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:
java.lang.Runnable

public final class SocketProxy
extends Proxy
implements java.lang.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.

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

Method Summary
static SocketProxy create(URL urlOfLocalNode, URL url)
          Establishes a connection from urlOfLocalNode to url.
 void disconnect()
          Tells this proxy that it is not needed anymore.
 java.util.List<ResponsibleNode> findSuccessor(int tag, java.lang.String res, URL url)
          Returns the node which is responsible for the given resource.
 Node findSuccessorAtFloor(Floor floor, ID key)
          Returns the node which is responsible for the given key at given floor.
 Floor getFirstFloor()
           
 ID getIdForFloor(Floor floor)
           
 void insertEntry(Floor floor, Entry entry)
          Stores the given object under the given ID at given floor.
 void insertReplicas(Floor floor, java.util.Set<Entry> replicas)
          Inserts replicates of the given entries for given floor.
 void leavesNetwork(Floor floor, Node predecessor)
          Inform all predecessor of given node that it leaves the network.
 java.util.List<Node> notify(Floor floor, Node potentialPredecessor)
          Requests this node's predecessor at given floor in result[0] and successor list in result[1..length-1].
 RefsAndEntries notifyAndCopyEntries(Floor floor, Node potentialPredecessor)
          Requests this node's predecessor, successor list and entries at given floor.
 void ping()
          Requests a sign of live.
 void removeEntry(Floor floor, Entry entry)
          Removes the given object from the list stored under the given ID at given floor.
 void removeReplicas(Floor floor, ID sendingNodeID, java.util.Set<Entry> replicas)
          Removes replicates of the given entries for given floor.
 java.util.Set<Entry> retrieveEntries(Floor floor, 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.
 java.lang.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, getNodeURL, hashCode
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

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.

findSuccessorAtFloor

public Node findSuccessorAtFloor(Floor floor,
                                 ID key)
                          throws CommunicationException
Description copied from class: Node
Returns the node which is responsible for the given key at given floor.

Specified by:
findSuccessorAtFloor in class Node
Parameters:
key -
floor - Floor at which is searched being held.
Returns:
The successor of key.
Throws:
CommunicationException

findSuccessor

public java.util.List<ResponsibleNode> findSuccessor(int tag,
                                                     java.lang.String res,
                                                     URL url)
                                              throws CommunicationException
Description copied from class: Node
Returns the node which is responsible for the given resource.

Specified by:
findSuccessor in class Node
Parameters:
tag - Tag for checking is the request is already processed.
res - Resource for which the successor is searched for.
url - URL of the node which successor is searched for.
Returns:
Throws:
CommunicationException

notify

public java.util.List<Node> notify(Floor floor,
                                   Node potentialPredecessor)
                            throws CommunicationException
Description copied from class: Node
Requests this node's predecessor at given floor 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(Floor floor,
                        Entry entry)
                 throws CommunicationException
Description copied from class: Node
Stores the given object under the given ID at given floor.

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

insertReplicas

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

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

leavesNetwork

public void leavesNetwork(Floor floor,
                          Node predecessor)
                   throws CommunicationException
Description copied from class: Node
Inform all predecessor of given node that it leaves the network.

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

removeEntry

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

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

removeReplicas

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

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

retrieveEntries

public java.util.Set<Entry> retrieveEntries(Floor floor,
                                            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.

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 java.lang.Runnable

notifyAndCopyEntries

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

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

toString

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

getIdForFloor

public ID getIdForFloor(Floor floor)
Specified by:
getIdForFloor in class Node

getFirstFloor

public Floor getFirstFloor()
                    throws CommunicationException
Specified by:
getFirstFloor in class Node
Throws:
CommunicationException