org.kth.dks.dks_dht
Class DKSDHTImpl

java.lang.Object
  extended by org.kth.dks.dks_dht.DKSDHTImpl
All Implemented Interfaces:
FailedIntervalCallbackInterface, DKSAppInterface, DKSDHTInterface, DKSDHTVisualizationInterface, DKSInterface

public class DKSDHTImpl
extends java.lang.Object
implements DKSDHTInterface, DKSAppInterface, DKSDHTVisualizationInterface, FailedIntervalCallbackInterface


Field Summary
 DKSImpl myDKSImpl
           
 
Constructor Summary
DKSDHTImpl(ConnectionManager cm, DKSOverlayAddress over)
           
DKSDHTImpl(ConnectionManager cm, DKSOverlayAddress over, java.lang.Class ldht)
           
DKSDHTImpl(ConnectionManager cm, DKSOverlayAddress over, DKSDHTCallback cb)
          cb is the callback object
DKSDHTImpl(ConnectionManager cm, long nodeId, java.net.URL nodeAddress)
           
 
Method Summary
 boolean addMsgHandler(DKSMessage msg, java.lang.Object handlerObject, java.lang.String methodName)
          Registers a handler for a DKSMessage.
 void addToBinding(long key, DKSObject value)
          Value is added to the list of bindings associated with key.
 AsyncOperation[] addToBindingAsync(long key, DKSObject value)
           
 void broadcast(DKSObject message)
          Broadcast a message to all nodes
 void broadcastCallback(DKSObject payload)
          This callback routine is called when the node recieves a broadcast message.
 void broadcastRestricted(DKSObject message, long startId, long endId)
          Broadcasts to nodes with identifiers within the rand startId and endId []
 void changeBinding(long key, DKSObject oldValue, DKSObject newValue)
          All ocurrences of oldValue in the bindings associated with key are replaced by newValue.
 void create()
          Called by the first node in a ring, this will create a new DKS network containing one node only
static DKSDHTImpl createDKSDiskDHT(ConnectionManager cm, DKSOverlayAddress over)
           
 void failCallback(DKSRef failed, DKSRef failedPred)
          This callback routine is called at the successor of a filed node, when it detects its predecessor has failed.
 DKSRef findResponsible(long id)
          Will find the DKS node that is responsible for the given identifier
 DKSDHTImpl getDHT()
          Internal function to return the underlying DHT.
 DKSMarshal getDKSMarshal()
          end of interfaces
 DKSRef getDKSRef()
          Returns the DKSRef associated to this DKS node
 java.lang.String getDKSURL()
          Returns the DKSURL (stringified DKSRef) used by this DKS node
 long getKeyRange()
           
 int getMultipleLookupCount()
          Gets the number of concurrent lookups made (default 2), if >=1 then several lookups are made at the same time to different replicas to increase the fault-tolerance and the response time
 long getMyId()
           
 long getPredecessorId()
           
 int getReplicationDegree()
          Gets the number of times each item is replicated in the system (default 2) Postcondition: Return value must be >=1 and must divide getKeyRange()
 DHTStatistics getStatistics()
           
 DHTStorage[] getStorage()
           
 void join(DKSRef existingnodeAddress)
          Adds a new node to the network managed by the local DKS implementation.
 void join(long existingnodeId, java.net.URL existingnodeAddress)
          should be deprecated
 void joinCallback(DKSRef pred, DKSRef succ)
          This callback routine is called at the joining node, when the node is about to join INVARIANT: this method must make a callback to DKSCallbacks.joinCallbackReturn
 void leave()
          Disconnect the local node from the network.
 void leaveCallback(DKSRef pred, DKSRef succ)
          This callback routine is called at the leaving node, when the node is about to leave INVARIANT: this method must make a callback to DKSCallbacks.joinCallbackReturn
 void logLevel(int level)
          Set the logging level
 DKSObject[] lookupBinding(long key)
          Returns the list of bindings associated with key.
 DKSObject[] lookupBinding(long minKey, long maxKey)
          Returns a list of all bindings associated with keys greater than or equal to minKey, and less than or equal to maxKey.
static DKSObject message2obj(DKSMessage m)
           
 void printGraphRecv(java.lang.String id, java.lang.String cnt)
           
 void printGraphSend(java.lang.String id, java.lang.String cnt)
           
 void removeFromBinding(long key, DKSObject value)
          Value is removed from the list of bindings associated with key.
 void replicateH(DKSRef sender, ReplicateMsg msg)
           
 void replicationFinishedH(DKSRef sender, ReplicationFinishedMsg rfmsg)
           
 void RestoreItemsH(DKSRef sender, DHTRestoreItemsMsg msg)
           
 void restoreReplicas(DHTRestoreReplicasMsg repMsg)
           
 void retrieveItemsH(DKSRef sender, RetrieveItemsMsg msg)
           
 DKSObject route(long identifier, DKSObject payload)
          Will route a message the DKS node that is responsible for the given identifier, and call routeCallback() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller
 void routeAsync(long identifier, DKSObject payload)
          Will route a message the DKS node that is responsible for the given identifier, and call routeCallbackAsync() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller
 void routeAsyncFrom(long identifier, DKSObject payload, DKSRef fromNode)
          Will route a message, starting at firstNode, the DKS node that is responsible for the given identifier, and call routeCallbackAsync() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller.
 DKSObject routeCallback(long identifier, DKSObject payload)
          Is set in DKSInterface through setCallbackHandler().
 void routeCallbackAsync(long identifier, DKSObject payload)
          Is set in DKSInterface through setCallbackHandler().
 void send(DKSObject message, DKSRef rec)
          Broadcasts the given message.
 void send(DKSObject message, long recipientNodeId)
          Send the message to the specified recipient node.
 void send(DKSRef target, DKSMessage message)
          Sends a DKSMessage to a DKS node
 void sendRestoreIntervals(java.util.List intervals, int cc, int id)
          Instructs the callback system that a request should be sent for finding the information found in the passed intervals.
 void setDKSCallbacks(DKSCallbackInterface dksImpl)
           
 void setMultipleLookupCount(int k)
          Sets the number of concurrent lookups made when lookupBinding is called.
 void setReplicationDegree(int k)
          Sets the number of times items are replicated in the DHT precondition: k must divide getKeyRange() (or getKeyRange() must be a multiple of k) must be invoked before join() or create().
 void unregisterNode()
          Every object implementing this interface gets registered in a ConnectionManager, this method this method unregisters the object in the ConnectionManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myDKSImpl

public DKSImpl myDKSImpl
Constructor Detail

DKSDHTImpl

public DKSDHTImpl(ConnectionManager cm,
                  long nodeId,
                  java.net.URL nodeAddress)
           throws DKSNodeAlreadyRegistered
Throws:
DKSNodeAlreadyRegistered

DKSDHTImpl

public DKSDHTImpl(ConnectionManager cm,
                  DKSOverlayAddress over)
           throws DKSNodeAlreadyRegistered
Throws:
DKSNodeAlreadyRegistered

DKSDHTImpl

public DKSDHTImpl(ConnectionManager cm,
                  DKSOverlayAddress over,
                  java.lang.Class ldht)
           throws DKSNodeAlreadyRegistered
Throws:
DKSNodeAlreadyRegistered

DKSDHTImpl

public DKSDHTImpl(ConnectionManager cm,
                  DKSOverlayAddress over,
                  DKSDHTCallback cb)
           throws DKSNodeAlreadyRegistered
cb is the callback object

Throws:
DKSNodeAlreadyRegistered
Method Detail

createDKSDiskDHT

public static DKSDHTImpl createDKSDiskDHT(ConnectionManager cm,
                                          DKSOverlayAddress over)
                                   throws DKSNodeAlreadyRegistered
Throws:
DKSNodeAlreadyRegistered

create

public void create()
Description copied from interface: DKSInterface
Called by the first node in a ring, this will create a new DKS network containing one node only

Specified by:
create in interface DKSInterface

join

public void join(long existingnodeId,
                 java.net.URL existingnodeAddress)
          throws DKSTooManyRestartJoins,
                 DKSIdentifierAlreadyTaken
should be deprecated

Throws:
DKSTooManyRestartJoins
DKSIdentifierAlreadyTaken

join

public void join(DKSRef existingnodeAddress)
          throws DKSTooManyRestartJoins,
                 DKSIdentifierAlreadyTaken,
                 DKSRefNoResponse
Description copied from interface: DKSInterface
Adds a new node to the network managed by the local DKS implementation.

Specified by:
join in interface DKSInterface
Throws:
DKSTooManyRestartJoins
DKSIdentifierAlreadyTaken
DKSRefNoResponse

logLevel

public void logLevel(int level)
Description copied from interface: DKSInterface
Set the logging level

Specified by:
logLevel in interface DKSInterface
Parameters:
level - int, 0 means no logging, 1 means debug prints, 2 means XML dumps

leave

public void leave()
Disconnect the local node from the network.

Specified by:
leave in interface DKSInterface

addToBinding

public void addToBinding(long key,
                         DKSObject value)
Value is added to the list of bindings associated with key.

Specified by:
addToBinding in interface DKSDHTInterface

addToBindingAsync

public AsyncOperation[] addToBindingAsync(long key,
                                          DKSObject value)

route

public DKSObject route(long identifier,
                       DKSObject payload)
Description copied from interface: DKSInterface
Will route a message the DKS node that is responsible for the given identifier, and call routeCallback() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller

Specified by:
route in interface DKSInterface
Parameters:
identifier - whose responsible node being routed to
payload - to be sent to the responsible node
Returns:
DKSOBject payload sent back by the responsible node
See Also:
DKSAppInterface

routeAsync

public void routeAsync(long identifier,
                       DKSObject payload)
Description copied from interface: DKSInterface
Will route a message the DKS node that is responsible for the given identifier, and call routeCallbackAsync() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller

Specified by:
routeAsync in interface DKSInterface
Parameters:
identifier - whose responsible node being routed to
payload - to be sent to the responsible node
See Also:
DKSAppInterface

routeAsyncFrom

public void routeAsyncFrom(long identifier,
                           DKSObject payload,
                           DKSRef fromNode)
Description copied from interface: DKSInterface
Will route a message, starting at firstNode, the DKS node that is responsible for the given identifier, and call routeCallbackAsync() at that node and give it the payload, upon which the responsible node will respond with a payload which is returned to the caller.

Specified by:
routeAsyncFrom in interface DKSInterface
Parameters:
identifier - long
payload - DKSObject
fromNode - DKSRef

removeFromBinding

public void removeFromBinding(long key,
                              DKSObject value)
Value is removed from the list of bindings associated with key. Any ocurrence of value in the list is determined by comparison of the DKSObject content identifier.

Specified by:
removeFromBinding in interface DKSDHTInterface

changeBinding

public void changeBinding(long key,
                          DKSObject oldValue,
                          DKSObject newValue)
All ocurrences of oldValue in the bindings associated with key are replaced by newValue. Any ocurrence of value in the list is determined by comparison of the DKSObject content identifier.

Specified by:
changeBinding in interface DKSDHTInterface

lookupBinding

public DKSObject[] lookupBinding(long key)
Returns the list of bindings associated with key. Any ocurrence of value in the list is determined by comparison of the DKSObject content identifier.

Specified by:
lookupBinding in interface DKSDHTInterface
Parameters:
key - long specifying the key to be looked up
Returns:
DKSObject[] with values associated to key

lookupBinding

public DKSObject[] lookupBinding(long minKey,
                                 long maxKey)
Returns a list of all bindings associated with keys greater than or equal to minKey, and less than or equal to maxKey.

Specified by:
lookupBinding in interface DKSDHTInterface

send

public void send(DKSObject message,
                 long recipientNodeId)
Send the message to the specified recipient node.


send

public void send(DKSObject message,
                 DKSRef rec)
Broadcasts the given message.


broadcast

public void broadcast(DKSObject message)
Broadcast a message to all nodes

Specified by:
broadcast in interface DKSDHTInterface
Specified by:
broadcast in interface DKSInterface

broadcastRestricted

public void broadcastRestricted(DKSObject message,
                                long startId,
                                long endId)
Broadcasts to nodes with identifiers within the rand startId and endId []

Specified by:
broadcastRestricted in interface DKSInterface
Parameters:
message - DKSObject message to be sent
startId - long beginning of the interval
endId - long end of the interval

getDKSMarshal

public DKSMarshal getDKSMarshal()
end of interfaces


setDKSCallbacks

public void setDKSCallbacks(DKSCallbackInterface dksImpl)

message2obj

public static DKSObject message2obj(DKSMessage m)

routeCallbackAsync

public void routeCallbackAsync(long identifier,
                               DKSObject payload)
Description copied from interface: DKSAppInterface
Is set in DKSInterface through setCallbackHandler(). It is called at the responsible node when a route() message reaches its destination. as the DKSNode will not be able to receive response messages. Consider using routeAsync() in DKSInterface.

Specified by:
routeCallbackAsync in interface DKSAppInterface
Parameters:
identifier - long, the identifier searched for in route, maybe not interesting for the app in many cases.
payload - DKSObject, the actual payload sent by the source

routeCallback

public DKSObject routeCallback(long identifier,
                               DKSObject payload)
Description copied from interface: DKSAppInterface
Is set in DKSInterface through setCallbackHandler(). It is called at the responsible node when a route() message reaches its destination. It receives a DKSObject, and returns a possibly new DKSObject INVARIANT: the implementor of this method SHOULD immediately return, as otherwise the underlying DKSNode cannot process new messagesl, and consequently the method cannot recursively call other methods in the DKSInterface as the DKSNode will not be able to receive response messages. Consider using routeAsync() in DKSInterface.

Specified by:
routeCallback in interface DKSAppInterface
Parameters:
identifier - long, the identifier searched for in route, maybe not interesting for the app in many cases.
payload - DKSObject, the actual payload sent by the source
Returns:
DKSObject the payload to be routed back

failCallback

public void failCallback(DKSRef failed,
                         DKSRef failedPred)
Description copied from interface: DKSAppInterface
This callback routine is called at the successor of a filed node, when it detects its predecessor has failed.

Specified by:
failCallback in interface DKSAppInterface
Parameters:
failed - DKSRef to the failed node (useful for DHT impl)
failedPred - DKSRef to the failed nodes predecessor (useful for DHT impl)

retrieveItemsH

public void retrieveItemsH(DKSRef sender,
                           RetrieveItemsMsg msg)

replicateH

public void replicateH(DKSRef sender,
                       ReplicateMsg msg)

replicationFinishedH

public void replicationFinishedH(DKSRef sender,
                                 ReplicationFinishedMsg rfmsg)

RestoreItemsH

public void RestoreItemsH(DKSRef sender,
                          DHTRestoreItemsMsg msg)

restoreReplicas

public void restoreReplicas(DHTRestoreReplicasMsg repMsg)

broadcastCallback

public void broadcastCallback(DKSObject payload)
Description copied from interface: DKSAppInterface
This callback routine is called when the node recieves a broadcast message. Note that the sender of a broadcast also recieves a broadcast msg.

Specified by:
broadcastCallback in interface DKSAppInterface
Parameters:
payload - DKSObject, the actual payload sent by the source

joinCallback

public void joinCallback(DKSRef pred,
                         DKSRef succ)
Description copied from interface: DKSAppInterface
This callback routine is called at the joining node, when the node is about to join INVARIANT: this method must make a callback to DKSCallbacks.joinCallbackReturn

Specified by:
joinCallback in interface DKSAppInterface
Parameters:
pred - DKSRef predecessor reference, containing the identifier of the predecessor (useful for DHT impl)
succ - DKSRef successor, containing the identifier of the successor (useful for DHT impl)

leaveCallback

public void leaveCallback(DKSRef pred,
                          DKSRef succ)
Description copied from interface: DKSAppInterface
This callback routine is called at the leaving node, when the node is about to leave INVARIANT: this method must make a callback to DKSCallbacks.joinCallbackReturn

Specified by:
leaveCallback in interface DKSAppInterface
Parameters:
pred - DKSRef predecessor reference, containing the identifier of the predecessor (useful for DHT impl)
succ - DKSRef successor, containing the identifier of the successor (useful for DHT impl)

getStatistics

public DHTStatistics getStatistics()

getDKSURL

public java.lang.String getDKSURL()
Description copied from interface: DKSInterface
Returns the DKSURL (stringified DKSRef) used by this DKS node

Specified by:
getDKSURL in interface DKSInterface
Returns:
String
See Also:
DKSRef

getMyId

public long getMyId()

getPredecessorId

public long getPredecessorId()

getKeyRange

public long getKeyRange()

findResponsible

public DKSRef findResponsible(long id)
Description copied from interface: DKSInterface
Will find the DKS node that is responsible for the given identifier

Specified by:
findResponsible in interface DKSInterface
Parameters:
id - whose responsible node is being queried for
Returns:
DKSRef reference to the responsible node

unregisterNode

public void unregisterNode()
Description copied from interface: DKSInterface
Every object implementing this interface gets registered in a ConnectionManager, this method this method unregisters the object in the ConnectionManager. This method needs to be called especially if another object of this type is to be instantiated with the same DKSNetAddress (overlay identity)

Specified by:
unregisterNode in interface DKSInterface

getDHT

public DKSDHTImpl getDHT()
Description copied from interface: DKSDHTVisualizationInterface
Internal function to return the underlying DHT. Used in the visualizer

Specified by:
getDHT in interface DKSDHTVisualizationInterface

getStorage

public DHTStorage[] getStorage()

sendRestoreIntervals

public void sendRestoreIntervals(java.util.List intervals,
                                 int cc,
                                 int id)
Description copied from interface: FailedIntervalCallbackInterface
Instructs the callback system that a request should be sent for finding the information found in the passed intervals.

Specified by:
sendRestoreIntervals in interface FailedIntervalCallbackInterface
Parameters:
intervals - The searched for intervals.
cc - the congurence class that should be used.
id - identity of the request, used to identify later downcalls
See Also:
DKSCallBackInterface, DKSAppInterface

printGraphSend

public void printGraphSend(java.lang.String id,
                           java.lang.String cnt)

printGraphRecv

public void printGraphRecv(java.lang.String id,
                           java.lang.String cnt)

send

public void send(DKSRef target,
                 DKSMessage message)
Description copied from interface: DKSInterface
Sends a DKSMessage to a DKS node

Specified by:
send in interface DKSInterface
Parameters:
target - a DKSRef to a node in the system
message - a DKSMessage

getReplicationDegree

public int getReplicationDegree()
Gets the number of times each item is replicated in the system (default 2) Postcondition: Return value must be >=1 and must divide getKeyRange()

Returns:
int replication degree

getMultipleLookupCount

public int getMultipleLookupCount()
Gets the number of concurrent lookups made (default 2), if >=1 then several lookups are made at the same time to different replicas to increase the fault-tolerance and the response time

Returns:
int

setReplicationDegree

public void setReplicationDegree(int k)
Sets the number of times items are replicated in the DHT precondition: k must divide getKeyRange() (or getKeyRange() must be a multiple of k) must be invoked before join() or create().

Parameters:
k - int replication degree

setMultipleLookupCount

public void setMultipleLookupCount(int k)
Sets the number of concurrent lookups made when lookupBinding is called. must be invoked before join() or create(). if >=1 then several lookups are made at the same time to different replicas to increase the fault-tolerance and the response time

Parameters:
k - int

addMsgHandler

public boolean addMsgHandler(DKSMessage msg,
                             java.lang.Object handlerObject,
                             java.lang.String methodName)
Description copied from interface: DKSInterface
Registers a handler for a DKSMessage. DKS will invoke the handler whenever a DKSMessage of that type is received.

Specified by:
addMsgHandler in interface DKSInterface
Parameters:
msg - Some object which is a subclass of DKSMessage
handlerObject - Object whose method will be invoked upon receipt of a message of type DKSMessage
methodName - full case sensitive of the method to be invoked(without paranthesis). The method has a predefined signature as described in the following example. Example: if the method name is "handleStore", there should a method in handlerObject with the signature
public void handleStore(DKSRef sender, msgClass msg)
, where msgClass is the tye of the parameter msg.
Returns:
true if registration succeeded, or false if it failed (which can occur if a DKSMessage with the same internal string exists).
See Also:
DKSInterface.addMsgHandler()

getDKSRef

public DKSRef getDKSRef()
Description copied from interface: DKSInterface
Returns the DKSRef associated to this DKS node

Specified by:
getDKSRef in interface DKSInterface
Returns:
DKSRef
See Also:
DKSRef


Copyright © 2010. All Rights Reserved.