de.uniba.wiai.lspi.chord.service.impl
Class ChordImpl

java.lang.Object
  extended by de.uniba.wiai.lspi.chord.service.impl.ChordImpl
All Implemented Interfaces:
AsynChord, Chord, Report

public final class ChordImpl
extends java.lang.Object
implements Chord, Report, AsynChord

Implements all operations which can be invoked on the local node.

Version:
1.0.5 modified, 0.99b
Author:
Karsten Loesing, bojanm, francesco

Constructor Summary
ChordImpl()
          Creates a new instance of ChordImpl which initially is disconnected.
 
Method Summary
 void addNewFloor(Floor floor, URL nodeURL, int ns)
           
 void create()
          Creates a new chord network which is not connected to any other node.
 void create(URL localURL1)
          Creates a new chord network which is not connected to any other node.
 Floor createFloor(URL url)
           
 Floor createNewFloor(URL url)
          
 int generateNewTag(URL url)
          
 java.util.ArrayList<MyFloor> getAllFloors()
           
 Entries getEntriesForFloor(Floor floor)
          
 ID getIdForFloor(Floor floor)
           
 References getReferencesForFloor(Floor floor)
          
 int getTag_counter()
           
 int[] getTag()
           
 URL getURL()
          Returns the URL of the local node; is null if no network has been created or joined.
 boolean goodDeal(URL url, Floor floor)
          
 void initialJoin(Floor floor, URL bootstrapURL)
           
 void initialJoin(Floor floor, URL localURL1, URL bootstrapURL)
           
 boolean inMyFloorList(Floor floor)
          
 void insert(java.lang.String res, java.io.Serializable s)
          Inserts a new data object into the network stored under the given key.
 void insert(java.lang.String res, java.io.Serializable entry, ChordCallback callback)
          Asynchronous method to insert entry under the provided key.
 ChordFuture insertAsync(java.lang.String res, java.io.Serializable entry)
          Asynchronous method to insert entry with key.
 void insertNewTag(int t)
          
 boolean isTagInList(int t)
          
 void join(Floor floor, URL bootstrapURL)
          Joins an existing chord network and announces its presence to the other nodes.
 void join(Floor floor, URL localURL1, URL bootstrapURL)
          Joins an existing chord network and announces its presence to the other nodes.
 Floor join(URL bootstrapURL)
           
 void leave()
          Disconnects from the network.
 java.lang.String printEntries(Floor floor)
          Returns a formatted String containing all entries stored on this node.
 java.lang.String printFingerTable(Floor floor)
          Returns a formatted String containing all references stored in the finger table of this node.
 java.lang.String printPredecessor(Floor floor)
          Returns a formatted String containing the predecessor reference of this node.
 java.lang.String printReferences(Floor floor)
          Returns a formatted String containing all references stored on this node.
 java.lang.String printSuccessorList(Floor floor)
          Returns a formatted String containing all references stored in the successor list of this node.
 void remove(java.lang.String res, java.io.Serializable s)
          Removes the given object stored under given key from the network.
 void remove(java.lang.String res, java.io.Serializable entry, ChordCallback callback)
          Asynchronous method to remove entry under the provided key.
 ChordFuture removeAsync(java.lang.String res, java.io.Serializable entry)
          Asynchronous method to remove entry with key.
 java.util.Set<java.io.Serializable> retrieve(java.lang.String res)
          Attempts to find all objects with given key.
 void retrieve(java.lang.String res, ChordCallback callback)
          Asynchronous method to retrieve the entries associated with key.
 ChordRetrievalFuture retrieveAsync(java.lang.String res)
          Asynchronous method to retrieve the entries associated with key.
 void setURL(URL nodeURL)
          Sets the URL of the local node to the given value; only available before creating or joining a network.
 java.lang.String toString()
          Returns a human-readable string representation containing this node's node ID and URL.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChordImpl

public ChordImpl()
Creates a new instance of ChordImpl which initially is disconnected. Constructor is hidden. Only constructor.

Method Detail

addNewFloor

public final void addNewFloor(Floor floor,
                              URL nodeURL,
                              int ns)

create

public final void create()
                  throws ServiceException
Description copied from interface: Chord
Creates a new chord network which is not connected to any other node. Assumes that at least the node URL has been set before by Chord.setURL(de.uniba.wiai.lspi.chord.data.URL). If no ID has been set before, it is generated by applying a hash function on the node URL.

Specified by:
create in interface AsynChord
Specified by:
create in interface Chord
Throws:
ServiceException - Is thrown if creating the local chord node fails, e.g. due to unability of creating the endpoint for incoming messages. Is also thrown if no URL has been set before.

create

public final void create(URL localURL1)
                  throws ServiceException
Description copied from interface: Chord
Creates a new chord network which is not connected to any other node. The node ID is generated by applying a hash function on the node URL.

Specified by:
create in interface AsynChord
Specified by:
create in interface Chord
Parameters:
localURL1 - URL on which this node accepts incoming requests from other chord nodes. The ID of this node is generated by applying a hash function on the node URL.
Throws:
ServiceException - Is thrown if creating the local chord node fails, e.g. due to unability of creating the endpoint for incoming messages.

createNewFloor

public final Floor createNewFloor(URL url)


createFloor

public final Floor createFloor(URL url)

generateNewTag

public final int generateNewTag(URL url)


getAllFloors

public final java.util.ArrayList<MyFloor> getAllFloors()

getEntriesForFloor

public final Entries getEntriesForFloor(Floor floor)


getIdForFloor

public final ID getIdForFloor(Floor floor)

getReferencesForFloor

public final References getReferencesForFloor(Floor floor)


getTag

public int[] getTag()

getTag_counter

public final int getTag_counter()

getURL

public final URL getURL()
Description copied from interface: Chord
Returns the URL of the local node; is null if no network has been created or joined.

Specified by:
getURL in interface AsynChord
Specified by:
getURL in interface Chord
Returns:
URL of local node.

goodDeal

public final boolean goodDeal(URL url,
                              Floor floor)


initialJoin

public final void initialJoin(Floor floor,
                              URL bootstrapURL)
                       throws ServiceException
Specified by:
initialJoin in interface AsynChord
Specified by:
initialJoin in interface Chord
Throws:
ServiceException

initialJoin

public final void initialJoin(Floor floor,
                              URL localURL1,
                              URL bootstrapURL)
                       throws ServiceException
Specified by:
initialJoin in interface AsynChord
Specified by:
initialJoin in interface Chord
Throws:
ServiceException

inMyFloorList

public final boolean inMyFloorList(Floor floor)


insert

public final void insert(java.lang.String res,
                         java.io.Serializable s)
Description copied from interface: Chord
Inserts a new data object into the network stored under the given key. If two or more objects with same keys exist, all of them are stored.

Specified by:
insert in interface Chord
Parameters:
res - Res, under which the new item is stored.
s - Object for storage in the network.

insert

public final void insert(java.lang.String res,
                         java.io.Serializable entry,
                         ChordCallback callback)
Description copied from interface: AsynChord
Asynchronous method to insert entry under the provided key. Implementations of this method must return immediately and the completion of the insertion must be reported to the provided callback instance.

Specified by:
insert in interface AsynChord
entry - The entry to insert.
callback - The ChordCallback to which to pass the retrieval result.

insertAsync

public final ChordFuture insertAsync(java.lang.String res,
                                     java.io.Serializable entry)
Description copied from interface: AsynChord
Asynchronous method to insert entry with key. Implementations of this method must return immediately and return an implementation of ChordFuture, which can be used later on to determine completion of the insertion.

Specified by:
insertAsync in interface AsynChord
entry - The entry to insert.
Returns:
ChordFuture, which can be used later on to determine completion of the insertion.

insertNewTag

public final void insertNewTag(int t)


isTagInList

public final boolean isTagInList(int t)


join

public final void join(Floor floor,
                       URL bootstrapURL)
                throws ServiceException
Description copied from interface: Chord
Joins an existing chord network and announces its presence to the other nodes. Assumes that at least the node URL has been set before by Chord.setURL(de.uniba.wiai.lspi.chord.data.URL). If no ID has been set before, it is generated by applying a hash function on the node URL.

Specified by:
join in interface AsynChord
Specified by:
join in interface Chord
bootstrapURL - URL of one existing node which is used as bootstrap node.
Throws:
ServiceException - If joining fails this exception is thrown. This may be due to failure of establishing an endpoint or communication problems when contacting the bootstrap node. Is also thrown if no URL has been set before.

join

public final void join(Floor floor,
                       URL localURL1,
                       URL bootstrapURL)
                throws ServiceException
Description copied from interface: Chord
Joins an existing chord network and announces its presence to the other nodes. The node ID is generated by applying a hash function on the node URL.

Specified by:
join in interface AsynChord
Specified by:
join in interface Chord
localURL1 - The local node is made available under this URL.
bootstrapURL - URL of one existing node which is used as bootstrap node.
Throws:
ServiceException - If joining fails this exception is thrown. This may be due to failure of establishing an endpoint or communication problems when contacting the bootstrap node.

join

public Floor join(URL bootstrapURL)
           throws ServiceException
Throws:
ServiceException

leave

public final void leave()
Description copied from interface: Chord
Disconnects from the network.

Specified by:
leave in interface AsynChord
Specified by:
leave in interface Chord

printEntries

public final java.lang.String printEntries(Floor floor)
Description copied from interface: Report
Returns a formatted String containing all entries stored on this node.

Specified by:
printEntries in interface Report
Returns:
Formatted String containing all entries stored on this node.

printFingerTable

public final java.lang.String printFingerTable(Floor floor)
Description copied from interface: Report
Returns a formatted String containing all references stored in the finger table of this node.

Specified by:
printFingerTable in interface Report
Returns:
Formatted String containing all references stored in the finger table of this node.

printPredecessor

public final java.lang.String printPredecessor(Floor floor)
Description copied from interface: Report
Returns a formatted String containing the predecessor reference of this node.

Specified by:
printPredecessor in interface Report
Returns:
Formatted String containing the predecessor reference of this node.

printReferences

public final java.lang.String printReferences(Floor floor)
Description copied from interface: Report
Returns a formatted String containing all references stored on this node.

Specified by:
printReferences in interface Report
Returns:
Formatted String containing all references stored on this node.

printSuccessorList

public final java.lang.String printSuccessorList(Floor floor)
Description copied from interface: Report
Returns a formatted String containing all references stored in the successor list of this node.

Specified by:
printSuccessorList in interface Report
Returns:
Formatted String containing all references stored in the successor list of this node.

remove

public final void remove(java.lang.String res,
                         java.io.Serializable s)
Description copied from interface: Chord
Removes the given object stored under given key from the network.

Specified by:
remove in interface Chord
s - Object to remove from the network.

remove

public final void remove(java.lang.String res,
                         java.io.Serializable entry,
                         ChordCallback callback)
Description copied from interface: AsynChord
Asynchronous method to remove entry under the provided key. Implementations of this method must return immediately and the completion of the removal must be reported to the provided callback instance.

Specified by:
remove in interface AsynChord
entry - The entry to insert.
callback - The ChordCallback to which to pass the retrieval result.

removeAsync

public final ChordFuture removeAsync(java.lang.String res,
                                     java.io.Serializable entry)
Description copied from interface: AsynChord
Asynchronous method to remove entry with key. Implementations of this method must return immediately and return an implementation of ChordFuture, which can be used later on to determine completion of the removal.

Specified by:
removeAsync in interface AsynChord
entry - The entry to remove.
Returns:
ChordFuture, which can be used later on to determine completion of the removal.

retrieve

public final java.util.Set<java.io.Serializable> retrieve(java.lang.String res)
Description copied from interface: Chord
Attempts to find all objects with given key.

Specified by:
retrieve in interface Chord
Returns:
All objects stored under given key. Set of Serializable

retrieve

public final void retrieve(java.lang.String res,
                           ChordCallback callback)
Description copied from interface: AsynChord
Asynchronous method to retrieve the entries associated with key. Implementations of this method must return immediately and the result of the retrieval must be passed to the provided callback instance.

Specified by:
retrieve in interface AsynChord
callback - The ChordCallback to which to pass the retrieval result.

retrieveAsync

public final ChordRetrievalFuture retrieveAsync(java.lang.String res)
Description copied from interface: AsynChord
Asynchronous method to retrieve the entries associated with key. Implementations of this method must return immediately and return an implementation of ChordRetrievalFuture, which can be used later on to retrieve the retrieved results.

Specified by:
retrieveAsync in interface AsynChord
Returns:
ChordRetrievalFuture that represents the result of the retrieve method.

setURL

public final void setURL(URL nodeURL)
Description copied from interface: Chord
Sets the URL of the local node to the given value; only available before creating or joining a network.

Specified by:
setURL in interface AsynChord
Specified by:
setURL in interface Chord
Parameters:
nodeURL - New URL of local node.

toString

public final java.lang.String toString()
Returns a human-readable string representation containing this node's node ID and URL.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()