planet.generic.commonapi
Class NodeImpl

java.lang.Object
  extended byplanet.generic.commonapi.NodeImpl
All Implemented Interfaces:
Node, java.io.Serializable
Direct Known Subclasses:
ChordNode, SymphonyNode

public abstract class NodeImpl
extends java.lang.Object
implements Node, java.io.Serializable

Superclass which represents a node in a peer-to-peer system, regardless of the underlying protocol. All nodes, implement the methods of this class.

Author:
Pedro García, Carles Pairot, Ruben Mondejar
See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable endpoints
          Local EndPoints.
protected  Id id
           
protected  java.util.Hashtable listeners
           
protected  NodeHandle nodeHandle
          NodeHandle for the actual Node.
 
Constructor Summary
NodeImpl(Id id)
          Constructor, create a new Node instance with node Id
 
Method Summary
 void addMessageListener(java.lang.String key, MessageListener listener)
          Adds a listener to the node so that it executes herself when the message response arrives
 Id getId()
          Returns the id of the node *
 IdFactory getIdFactory()
          Returns a factory for Ids specific to this node's protocol.
abstract  java.util.Hashtable getInfo()
          Returns information of the node
 NodeHandle getLocalHandle()
          Returns the local NodeHandle
 Application[] getRegisteredApplications()
          Returns all references of the applications that mantains this node.
protected  boolean hasMoreMessages()
          Checks if the incoming queue have a messages to send
abstract  void join(Id nodeId)
          The node joins in the network
abstract  void leave()
          The node leaves the network
abstract  void lookup(Id key)
          Lookup of a key
protected  RouteMessage nextMessage()
          Return the next message and dequeue this of the incoming queue
 Queue outMessages()
          Returns the present outgoing queue of this node
 boolean process(int actualStep)
          Given a time fraction, the node it can do everything what needs during this
 void receive(RouteMessage msg)
          Puts a message in the incoming queue of this node
 EndPoint registerApplication(Application app, java.lang.String instance)
          This returns a VirtualizedNode specific to the given application and instance name to the application, which the application can then use in order to send an receive messages.
 void removeMessageListener(java.lang.String key)
          Remove the message listener of the node
 void send(RouteMessage msg)
          Puts a message in the outcoming queue of this node
 void setTimer(TimerTask task, long firstTime)
          Sets a task to be executed only one time at specified firstTime.
 void setTimer(TimerTask task, long firstTime, long period)
          Sets a task to be executed periodicly at each period of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface planet.commonapi.Node
broadcast, fail, getPred, getSuccList, isAlive, localLookup, neighborSet, prettyPrintNode, printNode, range, replicaSet, routeData
 

Field Detail

id

protected Id id

listeners

protected transient java.util.Hashtable listeners

nodeHandle

protected NodeHandle nodeHandle
NodeHandle for the actual Node.


endpoints

protected java.util.Hashtable endpoints
Local EndPoints.

Constructor Detail

NodeImpl

public NodeImpl(Id id)
         throws InitializationException
Constructor, create a new Node instance with node Id

Parameters:
id - Id
Method Detail

join

public abstract void join(Id nodeId)
The node joins in the network

Specified by:
join in interface Node
Parameters:
nodeId - Id of Node to join to the actual ring.

leave

public abstract void leave()
The node leaves the network

Specified by:
leave in interface Node

lookup

public abstract void lookup(Id key)
Lookup of a key

Parameters:
key - Id

process

public boolean process(int actualStep)
Given a time fraction, the node it can do everything what needs during this

Specified by:
process in interface Node
Parameters:
actualStep - Actual step in simulation time.
Returns:
Always true.

receive

public void receive(RouteMessage msg)
             throws QueueFull
Puts a message in the incoming queue of this node

Specified by:
receive in interface Node
Parameters:
msg - received Message
Throws:
QueueFull - if the incoming queue of the actual Node is full.

send

public void send(RouteMessage msg)
          throws QueueFull
Puts a message in the outcoming queue of this node

Specified by:
send in interface Node
Parameters:
msg - sended Message
Throws:
QueueFull - if the outgoing queue of the actual Node is full.

outMessages

public Queue outMessages()
Returns the present outgoing queue of this node

Specified by:
outMessages in interface Node
Returns:
outgoing Queue of Messages

hasMoreMessages

protected boolean hasMoreMessages()
Checks if the incoming queue have a messages to send

Returns:
return true if has incoming messages to process

nextMessage

protected RouteMessage nextMessage()
Return the next message and dequeue this of the incoming queue

Returns:
return the next Message

getId

public Id getId()
Returns the id of the node *

Specified by:
getId in interface Node
Returns:
Id node identificator

addMessageListener

public void addMessageListener(java.lang.String key,
                               MessageListener listener)
Adds a listener to the node so that it executes herself when the message response arrives

Parameters:
key - String representation of id routing message
listener - MessageListener linked to Message

removeMessageListener

public void removeMessageListener(java.lang.String key)
Remove the message listener of the node

Parameters:
key - String representation of id routing message

getInfo

public abstract java.util.Hashtable getInfo()
Returns information of the node

Returns:
info Hashtable with the information

getLocalHandle

public NodeHandle getLocalHandle()
Returns the local NodeHandle

Specified by:
getLocalHandle in interface Node
Returns:
The actual local NodeHandle
See Also:
Node.getLocalHandle()

setTimer

public void setTimer(TimerTask task,
                     long firstTime,
                     long period)
Sets a task to be executed periodicly at each period of time.

Specified by:
setTimer in interface Node
Parameters:
task - Job to do at each activation of the task.
firstTime - First activation of the task, measured in steps or millis. Its value is the relative time, not in absolute time.
period - Number of steps or millis to periodicly execute the task.
See Also:
Node.setTimer(planet.util.timer.TimerTask, long, long)

setTimer

public void setTimer(TimerTask task,
                     long firstTime)
Sets a task to be executed only one time at specified firstTime.

Specified by:
setTimer in interface Node
Parameters:
task - Job to do at activation.
firstTime - Moment to be activated, in steps or millis, measured in relative time, not in absolute time.
See Also:
Node.setTimer(planet.util.timer.TimerTask, long)

registerApplication

public EndPoint registerApplication(Application app,
                                    java.lang.String instance)
This returns a VirtualizedNode specific to the given application and instance name to the application, which the application can then use in order to send an receive messages.

Specified by:
registerApplication in interface Node
Parameters:
instance - An identifier for a given instance
Returns:
The endpoint specific to this application, which can be used for message sending/receiving. Return null if cannot build the required EndPoint.

getRegisteredApplications

public Application[] getRegisteredApplications()
Returns all references of the applications that mantains this node.

Specified by:
getRegisteredApplications in interface Node
Returns:
An array with all references to the applications that they are mantained for this node.

getIdFactory

public IdFactory getIdFactory()
                       throws InitializationException
Returns a factory for Ids specific to this node's protocol.

Specified by:
getIdFactory in interface Node
Returns:
A factory for creating Ids.
Throws:
InitializationException - if occurs any problem with IdFactory initialization.