ist.palcom.communication
Class CommunicationManager

java.lang.Object
  extended by ist.palcom.communication.CommunicationManager
All Implemented Interfaces:
IHgraphNode

public class CommunicationManager
extends java.lang.Object
implements IHgraphNode

This class is the base in the communication layer and handles communication with the media managers through a routing manager. It also handles reliable communication by using acknowledge and resend messages.


Nested Class Summary
protected  class CommunicationManager.BroadcastDistributor
          Class for distributing publish (broadcasted) messages.
 class CommunicationManager.DistributorThread
          Thread for receiving messages from the routing layer and distributing them to the correct listener by the use of selectors.
protected  class CommunicationManager.ReliableMessageHandler
          Handles reliable messages
protected  class CommunicationManager.UnicastDistributor
          Class for distributing (unicast) messages by selectors.
 
Field Summary
protected  HgraphNode _node
           
 
Fields inherited from interface ist.palcom.hgraph.IHgraphNode
CHILD_NAME_CLASH, CIRCULARITY_CLASH, COMMAND_OR_NODE_MISSING, ERROR, HANDLER_MISSING, INVOKATOR_MISSING, LISTENER_MISSING, NODE_NOT_CHILD, PATH_MISSING, SIBLING_ALREADY_EXISTS, SIBLING_NONEXISTENT, SIBLING_REFERENCE_ALREADY_EXISTS, SIBLING_REFERENCE_NONEXISTENT, STATUS_OK, VALUE_ALREADY_EXISTS, VALUE_NOT_PRESENT
 
Constructor Summary
CommunicationManager(PalcomScheduler scheduler, RoutingManager routingManager)
           
 
Method Summary
 void addErrorHandler(PalcomThread handler)
          Subscribe to error events from all media managers.
 int addNodeChild(IHgraphNode node, Path callerPath)
          Adds a child to the node's private list of children.
 java.util.Iterator getChildIterator()
           
 FuncFunc getFuncFunc()
           
 java.lang.String getLocalDeviceCache()
          Returns the device cache for this device.
 Selector getNewSelector()
          Allocate a new selector and return it.
 java.lang.String getNodeName()
          hgraph impl below
 IHgraphNode getNodeParent()
           
 Path getPath()
           
 SiblingFunc getSiblingFunc()
           
 ValueFunc getValueFunc()
           
 boolean hasChildNamed(java.lang.String name)
          Checks whether the node has a child with a given name
 boolean isAncestorOf(IHgraphNode node)
          Checks whether this node is an ancestor of the parameter node.
 void registerForHeartBeats(PalcomThread resourceManager)
          Register as a listener for heartBeatEvents.
 int removeNodeChild(java.lang.String name, Path callerPath)
          Removes a child based on its name.
 boolean send(Message message, DeviceID receiverDeviceID, boolean reliable)
          Send a message to a receiver at a given device and selector, with selector set.
 void sendBroadcast(Message message)
          Send out a broadcast message, with required message header nodes inserted before.
 void sendHeartAttack()
          Send a message saying that the device will close down
 void sendHeartBeat(boolean isHeartBeatAck)
          Send a heartbeat message to all devices saying that this device is still active.
 boolean sendSingleShot(Message message, DeviceID receiverDeviceID, Selector receiverSelector, Selector senderSelector, boolean reliable)
          Send a single-shot message to a given device.
 void setDiscoverySelector(Selector selector)
          Set the discovery selector for this device.
 void setDistributorThreadAsListener()
          Used for test purposes only.
 void setLocalDeviceCache(java.lang.String localDeviceCache)
          Set the device cache information for the device.
 void setLocalDeviceID(DeviceID localDeviceID)
          Set the device ID for this device.
 void setLocalDiscoveryVersion(java.lang.String discoveryVersion)
          Set the discovery version for this device.
 void setLocalStatusFlag(byte statusFlag)
          Set the status flag for this device.
 int setNodeName(java.lang.String name, Path callerPath)
          Sets the name of the node.
 int setNodeParent(IHgraphNode newParent, Path callerPath)
          Sets the parent of the HgraphNode.
 Selector startReceiving2(PalcomThread receiver)
          Start receiving point-to-point messages.
 void startReceivingBroadcast(java.lang.String topic, PalcomThread receiver)
          Start receiving broadcast messages on topic topic.
 void startReceivingGroupcast(java.lang.String groupID, PalcomThread receiver)
          Start receiving groupcast messages on groupID groupID.
 void startReceivingRadiocast(DeviceID remoteDeviceID, Selector remoteSelector, PalcomThread receiver)
          Start receiving radiocast messages from device with DeviceID remoteDeviceID and selector remoteSelector.
 void stop()
          Stop the routing manager and all MediaManagers as well as the internal thread.
 void stopReceiving(PalcomThread receiver)
          Stop receiving messages for a receiver.
 void stopReceiving(Selector selector)
          Stop receiving messages at a selector.
 void stopReceivingBroadcast()
          Stop receiving broadcast messages on all topics.
 void stopReceivingBroadcast(java.lang.String topic, PalcomThread receiver)
          Stop receiving messages on topic for a receiver.
 void stopReceivingGroupcast(java.lang.String groupID, PalcomThread receiver)
          Stop receiving messages from group on groupID for a receiver.
 void stopReceivingRadiocast(DeviceID remoteDeviceID, Selector remoteSelector, PalcomThread receiver)
          Stop receiving radiocast messages on selector at device specified by remoteDeviceID.
 java.lang.String toXML()
           
 java.lang.String toXMLFull()
           
 java.lang.String toXMLFullRecursively()
           
 java.lang.String toXMLRecursively()
           
 void unregisterDevice(DeviceID deviceID)
          Remove the device with ID deviceID from the list of registered devices.
 void updatePath()
          Updates the path of the H-Graph node along with its offspring recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_node

protected HgraphNode _node
Constructor Detail

CommunicationManager

public CommunicationManager(PalcomScheduler scheduler,
                            RoutingManager routingManager)
Method Detail

setDistributorThreadAsListener

public void setDistributorThreadAsListener()
Used for test purposes only.


setLocalDeviceCache

public void setLocalDeviceCache(java.lang.String localDeviceCache)
Set the device cache information for the device.


getLocalDeviceCache

public java.lang.String getLocalDeviceCache()
Returns the device cache for this device.


setLocalDeviceID

public void setLocalDeviceID(DeviceID localDeviceID)
Set the device ID for this device.


setLocalStatusFlag

public void setLocalStatusFlag(byte statusFlag)
Set the status flag for this device.


setLocalDiscoveryVersion

public void setLocalDiscoveryVersion(java.lang.String discoveryVersion)
Set the discovery version for this device.


setDiscoverySelector

public void setDiscoverySelector(Selector selector)
Set the discovery selector for this device.


send

public boolean send(Message message,
                    DeviceID receiverDeviceID,
                    boolean reliable)
Send a message to a receiver at a given device and selector, with selector set.


sendSingleShot

public boolean sendSingleShot(Message message,
                              DeviceID receiverDeviceID,
                              Selector receiverSelector,
                              Selector senderSelector,
                              boolean reliable)
Send a single-shot message to a given device. Any additional header nodes except the one used for single-shot messages must be inserted before calling this method.

Parameters:
message - The message, possibly with extra header nodes already set.
receiverDeviceID - The ID of the device which to send the message.
receiverSelector - The selector of the listening service.
senderSelector - The selector of the sending service.

sendBroadcast

public void sendBroadcast(Message message)
Send out a broadcast message, with required message header nodes inserted before.


sendHeartAttack

public void sendHeartAttack()
Send a message saying that the device will close down


startReceiving2

public Selector startReceiving2(PalcomThread receiver)
Start receiving point-to-point messages.

Returns:
Selector to be used for sending messages to this receiver.

stop

public void stop()
Stop the routing manager and all MediaManagers as well as the internal thread.


getNewSelector

public Selector getNewSelector()
Allocate a new selector and return it. Used for instance by radiocasted services.


unregisterDevice

public void unregisterDevice(DeviceID deviceID)
Remove the device with ID deviceID from the list of registered devices. Also removes any waiting reliable messages which are to be sent to the lost device.


sendHeartBeat

public void sendHeartBeat(boolean isHeartBeatAck)
Send a heartbeat message to all devices saying that this device is still active.

Parameters:
isHeartBeatAck - should the heartbeat be answered by other devices or not.

registerForHeartBeats

public void registerForHeartBeats(PalcomThread resourceManager)
Register as a listener for heartBeatEvents. This method is used by test programs and the ResourceManager. Currently only one listener at a time is supported.


addErrorHandler

public void addErrorHandler(PalcomThread handler)
Subscribe to error events from all media managers. Unhandled errors within the MediaManagers will be send to the handler in the form of MALErrorEvent events. Notice: Currently, only one error handler at a time is supported


startReceivingBroadcast

public void startReceivingBroadcast(java.lang.String topic,
                                    PalcomThread receiver)
Start receiving broadcast messages on topic topic.


startReceivingRadiocast

public void startReceivingRadiocast(DeviceID remoteDeviceID,
                                    Selector remoteSelector,
                                    PalcomThread receiver)
Start receiving radiocast messages from device with DeviceID remoteDeviceID and selector remoteSelector.


startReceivingGroupcast

public void startReceivingGroupcast(java.lang.String groupID,
                                    PalcomThread receiver)
Start receiving groupcast messages on groupID groupID.


stopReceiving

public void stopReceiving(Selector selector)
Stop receiving messages at a selector.


stopReceiving

public void stopReceiving(PalcomThread receiver)
Stop receiving messages for a receiver.


stopReceivingBroadcast

public void stopReceivingBroadcast(java.lang.String topic,
                                   PalcomThread receiver)
Stop receiving messages on topic for a receiver.


stopReceivingGroupcast

public void stopReceivingGroupcast(java.lang.String groupID,
                                   PalcomThread receiver)
Stop receiving messages from group on groupID for a receiver.


stopReceivingRadiocast

public void stopReceivingRadiocast(DeviceID remoteDeviceID,
                                   Selector remoteSelector,
                                   PalcomThread receiver)
Stop receiving radiocast messages on selector at device specified by remoteDeviceID.


stopReceivingBroadcast

public void stopReceivingBroadcast()
Stop receiving broadcast messages on all topics.


getNodeName

public java.lang.String getNodeName()
hgraph impl below

Specified by:
getNodeName in interface IHgraphNode
Returns:
The name of the node.

setNodeName

public int setNodeName(java.lang.String name,
                       Path callerPath)
Description copied from interface: IHgraphNode
Sets the name of the node. If a sibling already has the name, an error control message is returned

Specified by:
setNodeName in interface IHgraphNode
Parameters:
name - The new name
Returns:
IHgraphNode.STATUS_OK if the change succeeded. IHgraphNode.CHILD_NAME_CLASH if a sibling with the given name already exists.

getPath

public Path getPath()
Specified by:
getPath in interface IHgraphNode
Returns:
the Path object pertaining to the path of the node

updatePath

public void updatePath()
Description copied from interface: IHgraphNode
Updates the path of the H-Graph node along with its offspring recursively. The path is updated when the node name and the node parent is sat.

Specified by:
updatePath in interface IHgraphNode

hasChildNamed

public boolean hasChildNamed(java.lang.String name)
Description copied from interface: IHgraphNode
Checks whether the node has a child with a given name

Specified by:
hasChildNamed in interface IHgraphNode
Parameters:
name - The name to check
Returns:
True iff the node has an actual child with the given name. False if not.

isAncestorOf

public boolean isAncestorOf(IHgraphNode node)
Description copied from interface: IHgraphNode
Checks whether this node is an ancestor of the parameter node. It does so with a depth-first sharch of its offspring (children etc.)

Specified by:
isAncestorOf in interface IHgraphNode
Returns:
true if this node is an ancestor of the parameter node. false if not.

removeNodeChild

public int removeNodeChild(java.lang.String name,
                           Path callerPath)
Description copied from interface: IHgraphNode
Removes a child based on its name.

Specified by:
removeNodeChild in interface IHgraphNode
Parameters:
name - The name of the child to be removed
Returns:
IHgraphNode.STATUS_OK if the operation succeeds

toXML

public java.lang.String toXML()
Specified by:
toXML in interface IHgraphNode
Returns:
A simple xml'ified String of the node (type, name, path, children)

toXMLFull

public java.lang.String toXMLFull()
Specified by:
toXMLFull in interface IHgraphNode
Returns:
A complete xml'ified String of the node (same as simple + handlers, invokators, listeners, values)

toXMLRecursively

public java.lang.String toXMLRecursively()
Specified by:
toXMLRecursively in interface IHgraphNode
Returns:
A simple recursive xml'ified String of the node (type, name, path, children)

toXMLFullRecursively

public java.lang.String toXMLFullRecursively()
Specified by:
toXMLFullRecursively in interface IHgraphNode
Returns:
A complete recursive xml'ified String of the node (same as simple + handlers, invokators, listeners, values) HEAVY!!!

setNodeParent

public int setNodeParent(IHgraphNode newParent,
                         Path callerPath)
Description copied from interface: IHgraphNode
Sets the parent of the HgraphNode. This triggers a recalculation of the path of the node and its offspring

Specified by:
setNodeParent in interface IHgraphNode
Parameters:
newParent - the new parent
Returns:
IHgraphNode.STATUS_OK if the operation succeeds. IHgraphNode.CIRCULARITY_CLASH if the operation causes a circularity.

addNodeChild

public int addNodeChild(IHgraphNode node,
                        Path callerPath)
Description copied from interface: IHgraphNode
Adds a child to the node's private list of children. Ensures that names amongst children are unique

Specified by:
addNodeChild in interface IHgraphNode
Parameters:
node - The new child to be added
Returns:
IHgraphNode.STATUS_OK if the change succeeded. IHgraphNode.CHILD_NAME_CLASH if a sibling with the given name already exists.

getSiblingFunc

public SiblingFunc getSiblingFunc()
Specified by:
getSiblingFunc in interface IHgraphNode
Returns:
The SiblingFunc Sibling functionality object for the given node.

getValueFunc

public ValueFunc getValueFunc()
Specified by:
getValueFunc in interface IHgraphNode
Returns:
The ValueFunc Value functionality object for the given node.

getFuncFunc

public FuncFunc getFuncFunc()
Specified by:
getFuncFunc in interface IHgraphNode
Returns:
The FuncFunc functional functionality (ie. handlers, invokators and listeners) object for the given node.

getNodeParent

public IHgraphNode getNodeParent()
Specified by:
getNodeParent in interface IHgraphNode
Returns:
The parent of the node. null if the parent is root

getChildIterator

public java.util.Iterator getChildIterator()
Specified by:
getChildIterator in interface IHgraphNode
Returns:
An Iterator over the children of the node