de.uniba.wiai.lspi.chord.com.local
Class ThreadProxy

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.local.ThreadProxy

public final class ThreadProxy
extends Proxy

This class represents a Proxy for the protocol that allows to be build a (local) chord network within one JVM.

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

Constructor Summary
ThreadProxy(URL creatorURL1, URL url)
          Creates a Proxy for the jchordlocal protocol.
 
Method Summary
 void disconnect()
          Closes the connection to the node.
 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.
 ThreadEndpoint getEndpoint()
          Get a reference to the endpoint this proxy delegates methods to.
 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> entries)
          Inserts replicates of the given entries for given floor.
 void invalidate()
          Invalidates this proxy.
 boolean isValid()
          Test if this Proxy is valid.
 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> entriesToRemove)
          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.
 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
 

Constructor Detail

ThreadProxy

public ThreadProxy(URL creatorURL1,
                   URL url)
            throws CommunicationException
Creates a Proxy for the jchordlocal protocol. The host name part of urlis the name of the node in the jchordlocal protocol.

Parameters:
creatorURL1 -
url - The URLof the node this proxy represents.
Throws:
CommunicationException
Method Detail

isValid

public boolean isValid()
Test if this Proxy is valid.

Returns:
true if this Proxy is valid.

invalidate

public void invalidate()
Invalidates this proxy.


getEndpoint

public ThreadEndpoint getEndpoint()
                           throws CommunicationException
Get a reference to the endpoint this proxy delegates methods to. If there is no endpoint a exception is thrown.

Returns:
Reference to the endpoint this proxy delegates methods to.
Throws:
CommunicationException - If there is no endpoint this exception is thrown.

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:
floor - Floor at which is searched being held.
key - Key for which the successor is searched for.
Returns:
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

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
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

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
entry - The entry to remove from the dht.
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

toString

public java.lang.String toString()
Overrides:
toString in class Node

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
Returns:
A list containing the predecessor at first position of the list and the successors in the rest of the list.
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 - Thrown if an unresolvable communication failure occurs.

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.

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
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

removeReplicas

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

Specified by:
removeReplicas in class Node
sendingNodeID - ID of sending node; if entriesToRemove is empty, all replicas with ID smaller than the sending node's ID are removed
entriesToRemove - Replicas to remove; if empty, all replicas with ID smaller than the sending node's ID are removed
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

insertReplicas

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

Specified by:
insertReplicas in class Node
entries - The entries that are replicated.
Throws:
CommunicationException - Thrown if an unresolvable communication failure occurs.

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
potentialPredecessor - Remote node which invokes this method
Returns:
References to predecessor and successors and the entries this node will be responsible for.
Throws:
CommunicationException

disconnect

public void disconnect()
Description copied from class: Node
Closes the connection to the node.

Specified by:
disconnect in class Node

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