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 Object
implements Chord, Report, AsynChord

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


Field Summary
protected  Logger logger
          Object logger.
protected  de.uniba.wiai.lspi.chord.service.impl.References references
          References to remote nodes.
 
Constructor Summary
ChordImpl()
          Creates a new instance of ChordImpl which initially is disconnected.
 
Method Summary
 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.
 void create(URL localURL1, ID localID1)
          Creates a new chord network which is not connected to any other node.
 ID getID()
          Returns the ID of the local node; is null if no network has been created or joined.
 URL getURL()
          Returns the URL of the local node; is null if no network has been created or joined.
 void insert(Key key, Serializable s)
          Inserts a new data object into the network stored under the given key.
 void insert(Key key, Serializable entry, ChordCallback callback)
          Asynchronous method to insert entry under the provided key.
 ChordFuture insertAsync(Key key, Serializable entry)
          Asynchronous method to insert entry with key.
 void join(URL bootstrapURL)
          Joins an existing chord network and announces its presence to the other nodes.
 void join(URL localURL1, ID localID1, URL bootstrapURL)
          Joins an existing chord network and announces its presence to the other nodes.
 void join(URL localURL1, URL bootstrapURL)
          Joins an existing chord network and announces its presence to the other nodes.
 void leave()
          Disconnects from the network.
 String printEntries()
          Returns a formatted String containing all entries stored on this node.
 String printFingerTable()
          Returns a formatted String containing all references stored in the finger table of this node.
 String printPredecessor()
          Returns a formatted String containing the predecessor reference of this node.
 String printReferences()
          Returns a formatted String containing all references stored on this node.
 String printSuccessorList()
          Returns a formatted String containing all references stored in the successor list of this node.
 void remove(Key key, Serializable s)
          Removes the given object stored under given key from the network.
 void remove(Key key, Serializable entry, ChordCallback callback)
          Asynchronous method to remove entry under the provided key.
 ChordFuture removeAsync(Key key, Serializable entry)
          Asynchronous method to remove entry with key.
 Set<Serializable> retrieve(Key key)
          Attempts to find all objects with given key.
 void retrieve(Key key, ChordCallback callback)
          Asynchronous method to retrieve the entries associated with key.
 ChordRetrievalFuture retrieveAsync(Key key)
          Asynchronous method to retrieve the entries associated with key.
 void setID(ID nodeID)
          Sets the ID of the local node to the given value; only available before creating or joining a network.
 void setURL(URL nodeURL)
          Sets the URL of the local node to the given value; only available before creating or joining a network.
 String toString()
          Returns a human-readable string representation containing this node's node ID and URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected Logger logger
Object logger.


references

protected de.uniba.wiai.lspi.chord.service.impl.References references
References to remote nodes.

Constructor Detail

ChordImpl

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

Method Detail

getURL

public final URL getURL()
Description copied from interface: AsynChord
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.

setURL

public final void setURL(URL nodeURL)
Description copied from interface: AsynChord
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.

getID

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

Specified by:
getID in interface AsynChord
Specified by:
getID in interface Chord
Returns:
ID of local node.

setID

public final void setID(ID nodeID)
Description copied from interface: AsynChord
Sets the ID of the local node to the given value; only available before creating or joining a network.

Specified by:
setID in interface AsynChord
Specified by:
setID in interface Chord
Parameters:
nodeID - New ID of local node.

create

public final void create()
                  throws ServiceException
Description copied from interface: AsynChord
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 AsynChord.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: AsynChord
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.

create

public final void create(URL localURL1,
                         ID localID1)
                  throws ServiceException
Description copied from interface: AsynChord
Creates a new chord network which is not connected to any other node.

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.
localID1 - ID of this node.
Throws:
ServiceException - Is thrown if creating the local chord node fails, e.g. due to unability of creating the endpoint for incoming messages.

join

public final void join(URL bootstrapURL)
                throws ServiceException
Description copied from interface: AsynChord
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 AsynChord.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
Parameters:
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(URL localURL1,
                       URL bootstrapURL)
                throws ServiceException
Description copied from interface: AsynChord
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
Parameters:
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 final void join(URL localURL1,
                       ID localID1,
                       URL bootstrapURL)
                throws ServiceException
Description copied from interface: AsynChord
Joins an existing chord network and announces its presence to the other nodes.

Specified by:
join in interface AsynChord
Specified by:
join in interface Chord
Parameters:
localURL1 - The local node is made available under this URL.
localID1 - ID of this node.
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.

leave

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

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

insert

public final void insert(Key key,
                         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:
key - Key, under which the new item is stored.
s - Object for storage in the network.

retrieve

public final Set<Serializable> retrieve(Key key)
Description copied from interface: Chord
Attempts to find all objects with given key.

Specified by:
retrieve in interface Chord
Parameters:
key - Key for which objects shall be retrieved.
Returns:
All objects stored under given key. Set of Serializable

remove

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

Specified by:
remove in interface Chord
Parameters:
key - Key under which the object currently is stored.
s - Object to remove from the network.

toString

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

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

printEntries

public final String printEntries()
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 String printFingerTable()
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.

printSuccessorList

public final String printSuccessorList()
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.

printReferences

public final String printReferences()
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.

printPredecessor

public final String printPredecessor()
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.

retrieve

public void retrieve(Key key,
                     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
Parameters:
key - The key for which the associated entries should be retrieved.
callback - The ChordCallback to which to pass the retrieval result.

insert

public void insert(Key key,
                   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
Parameters:
key - The Key to associate with entry
entry - The entry to insert.
callback - The ChordCallback to which to pass the retrieval result.

remove

public void remove(Key key,
                   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
Parameters:
key - The Key associated with entry
entry - The entry to insert.
callback - The ChordCallback to which to pass the retrieval result.

retrieveAsync

public ChordRetrievalFuture retrieveAsync(Key key)
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
Parameters:
key - The Key for that the associated entries should be retrieved.
Returns:
ChordRetrievalFuture that represents the result of the retrieve method.

insertAsync

public ChordFuture insertAsync(Key key,
                               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
Parameters:
key - The Key with which entry will be associated.
entry - The entry to insert.
Returns:
ChordFuture, which can be used later on to determine completion of the insertion.

removeAsync

public ChordFuture removeAsync(Key key,
                               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
Parameters:
key - The Key with which entry is associated.
entry - The entry to remove.
Returns:
ChordFuture, which can be used later on to determine completion of the removal.


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