org.kth.dks.dks_dht
Class DKSMCastDHTImpl

java.lang.Object
  extended by org.kth.dks.dks_dht.DKSMCastDHTImpl
All Implemented Interfaces:
DKSDHTCallback, DKSDHTInterface, DKSDHTVisualizationInterface, DKSInterface, DKSMCastDHTInterface

public class DKSMCastDHTImpl
extends java.lang.Object
implements DKSMCastDHTInterface, DKSDHTCallback, DKSDHTVisualizationInterface


Constructor Summary
DKSMCastDHTImpl(ConnectionManager cm, DKSOverlayAddress over, DKSDHTCallback cb)
          cb is the callback object
 
Method Summary
 boolean addMsgHandler(DKSMessage msg, java.lang.Object handlerObject, java.lang.String methodName)
          Registers a handler for a DKSMessage.
 boolean addMsgHandler(java.lang.String messageClassZ, java.lang.String handlerClassZ, java.lang.String handlerMethodZ, java.lang.Object handlerObject)
          Install a message message handler, @see ObjectAdapter.addMsgHandler()
 void addToBinding(long key, DKSObject value)
          Value is added to the list of bindings associated with key.
 void broadcast(DKSObject message)
          Broadcast a message to all nodes
 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
 DKSMCastDHTInterface createGroup(long gid, DKSDHTCallback cb)
          Create a new multicast group with a specific group id.
 void dhtBroadcastCallback(DKSObject value)
          Receive a broadcast message
 DKSMessage dhtRouteCallback(long identifier, DKSMessage value)
          The callback is called at the responsible node when a route() message reaches its destination and the message is not handled at a lower abstraction layer.
 void dhtRouteCallbackAsync(long identifier, DKSMessage payload)
          The callback is called at the responsible node when a route() message reaches its destination and the message is not handled at a lower abstraction layer.
 DKSRef findResponsible(long identifier)
          Will find the DKS node that is responsible for the given identifier
 DKSDHTImpl getDHT()
          Return a reference to the underlying DKSDHT
 DKSRef getDKSRef()
          Returns the DKSRef associated to this DKS node
 java.lang.String getDKSURL()
          Returns the DKSURL (stringified DKSRef) used by this DKS node
 DKSRef[] getGroupInfo(long gid)
          Return the members of the group.
 void join(DKSRef existingnodeAddress)
          Adds a new node to the network managed by the local DKS implementation.
 DKSMCastDHTInterface joinGroup(long gid, DKSDHTCallback cb)
          Join an existing multicast group with a specific group id.
 void leave()
          Disconnect the local node from the network.
 void logLevel(int level)
          Set the logging level
 DKSObject[] lookupBinding(long key)
          Returns a vector of DKSObjects associated with key in the DHT
 DKSObject[] lookupBinding(long minKey, long maxKey)
          Returns an array of all bindings associated with keys greater than or equal to minKey, and less than or equal to maxKey.
 void removeFromBinding(long key, DKSObject value)
          Value is removed from the list of bindings associated with key.
 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 from fromNode to 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 send(DKSRef target, DKSMessage message)
          Sends a DKSMessage to a DKS node
 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
 

Constructor Detail

DKSMCastDHTImpl

public DKSMCastDHTImpl(ConnectionManager cm,
                       DKSOverlayAddress over,
                       DKSDHTCallback cb)
cb is the callback object

Method Detail

createGroup

public DKSMCastDHTInterface createGroup(long gid,
                                        DKSDHTCallback cb)
                                 throws DKSIdentifierAlreadyTaken,
                                        DKSTooManyRestartJoins
Create a new multicast group with a specific group id. Automatically become a member of the group if the group does not exists. If the group already exists DKSNodeAlreadyRegistered will be thrown.

Specified by:
createGroup in interface DKSMCastDHTInterface
Throws:
DKSIdentifierAlreadyTaken
DKSTooManyRestartJoins

joinGroup

public DKSMCastDHTInterface joinGroup(long gid,
                                      DKSDHTCallback cb)
                               throws DKSMCastNoSouchGroup,
                                      DKSIdentifierAlreadyTaken,
                                      DKSRefNoResponse
Join an existing multicast group with a specific group id. If the group does not exist DKSMCastNoSouchGroup is thrown.

Specified by:
joinGroup in interface DKSMCastDHTInterface
Throws:
DKSMCastNoSouchGroup
DKSIdentifierAlreadyTaken
DKSRefNoResponse

getGroupInfo

public DKSRef[] getGroupInfo(long gid)
                      throws DKSMCastNoSouchGroup
Return the members of the group.

Specified by:
getGroupInfo in interface DKSMCastDHTInterface
Throws:
DKSMCastNoSouchGroup

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

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 a vector of DKSObjects associated with key in the DHT

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 an array 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

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

join

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

Specified by:
join in interface DKSInterface
Parameters:
nodeId - The unique DKS node identifier (key) for the new node.
nodeAddress - The location of the new node on the physical underlying network.
Throws:
DKSIdentifierAlreadyTaken
DKSTooManyRestartJoins
DKSRefNoResponse

create

public void create()
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
Parameters:
existingnodeAddress - DKSOverlayAddress

logLevel

public void logLevel(int level)
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

findResponsible

public DKSRef findResponsible(long identifier)
Will find the DKS node that is responsible for the given identifier

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

route

public 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

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)
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)
Will route a message from fromNode to 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 - whose responsible node being routed to
payload - to be sent to the responsible node
fromNode - DKSRef
See Also:
DKSAppInterface

getDKSURL

public java.lang.String getDKSURL()
Returns the DKSURL (stringified DKSRef) used by this DKS node

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

unregisterNode

public void unregisterNode()
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

dhtBroadcastCallback

public void dhtBroadcastCallback(DKSObject value)
Receive a broadcast message

Specified by:
dhtBroadcastCallback in interface DKSDHTCallback

dhtRouteCallback

public DKSMessage dhtRouteCallback(long identifier,
                                   DKSMessage value)
The callback is called at the responsible node when a route() message reaches its destination and the message is not handled at a lower abstraction layer. It receives a DKSMessage, and returns a possibly new DKSMessage 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:
dhtRouteCallback in interface DKSDHTCallback
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 or null if the message is unhandled

dhtRouteCallbackAsync

public void dhtRouteCallbackAsync(long identifier,
                                  DKSMessage payload)
The callback is called at the responsible node when a route() message reaches its destination and the message is not handled at a lower abstraction layer. It receives a DKSMessage

Specified by:
dhtRouteCallbackAsync in interface DKSDHTCallback
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

getDHT

public DKSDHTImpl getDHT()
Return a reference to the underlying DKSDHT

Specified by:
getDHT in interface DKSDHTVisualizationInterface

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

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

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()

addMsgHandler

public boolean addMsgHandler(java.lang.String messageClassZ,
                             java.lang.String handlerClassZ,
                             java.lang.String handlerMethodZ,
                             java.lang.Object handlerObject)
Install a message message handler, @see ObjectAdapter.addMsgHandler()

Specified by:
addMsgHandler in interface DKSMCastDHTInterface


Copyright © 2010. All Rights Reserved.