ist.palcom.services
Class AbstractService

java.lang.Object
  extended by ist.palcom.services.AbstractService
All Implemented Interfaces:
Service, IHgraphNode
Direct Known Subclasses:
AbstractAccompliceService, AISReaderService, AlarmHRHRService, AlarmService, Assembly, AssemblyLauncherService, AssemblyManager, AxisControllerService, BioBeltService, BreathingInspectionService, CliHgraphBrowserService, CompassService, ConfigureHRHRAlarmService, ConnectivityService, ContingencyManager, ContingencyMonitor, CoordinateStufferService, DiabetesService, DisplayerControlProvider, DisplayerCustomer, DisplayService, DisplayService, DisplayService, EchoService, GeneratorControlProvider, GeoConverterService, GoogleEarthService, GPSParserService, GpsService, HeartrateInspectionService, HgraphBrowserService, HgraphManagerService, ImageProvider, ImageViewerCustomer, IncubatorController, LEDService, MattressService, MStoneService, NewResourceManager, PhotoDBService, PhotoService, PictureService, PoetryProvider, PositionService, ProximityService, PuzzleAssembler, PuzzleGame, ResourceDirectory, RespiratorService, RFIDService, SaturimeterService, SelfTestProvider, ServiceManager, StorageService, TimerService, TouchService

public abstract class AbstractService
extends java.lang.Object
implements Service

AbstractService is the superclass of all services written in the framework. It has name and address information about the service. Subclasses implement the actual functionality of the service.


Field Summary
protected  HgraphNode _node
          hgraph impl
protected  ist.palcom.services.AbstractService.ConnectionsMonitor connectionsMonitor
           
protected  DeviceContext context
           
protected  PRDService info
          The info about the service.
protected  ServiceInstanceID siid
           
 
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
AbstractService(DeviceContext context, java.lang.String serviceName, boolean hasDesc, boolean remoteConnect, byte distribution, java.lang.String protocol, boolean reliable, java.lang.String versionName, java.lang.String helpText)
           
AbstractService(DeviceContext context, java.lang.String name, boolean hasDesc, boolean remoteConnect, byte distribution, java.lang.String protocol, boolean reliable, java.lang.String readableVersionName, java.lang.String serviceHelpText, LocalSID localSID)
          Create a new service instance.
AbstractService(DeviceContext context, java.lang.String serviceName, boolean hasDesc, boolean remoteConnect, byte distribution, java.lang.String protocol, boolean reliable, java.lang.String versionName, java.lang.String helpText, ServiceProxy sp)
           
AbstractService(DeviceContext context, java.lang.String serviceName, boolean hasDesc, boolean remoteConnect, byte distribution, java.lang.String protocol, boolean reliable, java.lang.String versionName, java.lang.String helpText, ServiceProxy sp, LocalSID localSID)
           
AbstractService(DeviceContext context, java.lang.String serviceName, boolean hasDesc, boolean remoteConnect, java.lang.String protocol, boolean reliable, java.lang.String versionName, java.lang.String helpText, ServiceProxy sp, LocalSID localSID, GroupID groupID)
          Constructor for Groupcast services.
AbstractService(DeviceContext context, java.lang.String serviceName, boolean hasDesc, boolean remoteConnect, java.lang.String protocol, boolean reliable, java.lang.String versionName, java.lang.String helpText, ServiceProxy sp, LocalSID localSID, Topic topic)
          Constructor for Broadcast services.
 
Method Summary
 int addNodeChild(IHgraphNode node, Path callerPath)
          Adds a child to the node's private list of children.
 void addServiceProxyListener(PalcomThread listener)
          Add a listener for received ServiceProxies, for established connections to providers.
protected  void connectionClosed(UnicastConnection connection)
          Notification that a connection has been closed.
protected  void connectionCreated(UnicastConnection connection)
          Notification that a new connection has been established.
 void connectTo(LocalSID localSID)
          Connect to the service identified by localSID.
 void disconnectFrom(LocalSID serviceLocalSID)
          Closes the connection to the given provider and removes it from the list of connections.
 java.util.Iterator getChildIterator()
           
protected  java.util.ArrayList getConnections()
          Method for testing.
 FuncFunc getFuncFunc()
           
 java.lang.String getNodeName()
          hgraph impl below
 IHgraphNode getNodeParent()
           
 Path getPath()
           
protected  ServiceProxy getRemoteServiceProxy(LocalSID localSID)
           
 Selector getSelector()
           
abstract  ServiceID getServiceID()
           
 PRDService getServiceInfo()
           
 ServiceInstanceID getServiceInstanceID()
           
 ServiceProxy getServiceProxy()
           
 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.
protected  java.util.Iterator remoteServiceProxyIterator()
           
 int removeNodeChild(java.lang.String name, Path callerPath)
          Removes a child based on its name.
 void removeServiceProxyListener(PalcomThread listener)
          Remove a listener for ServiceProxies.
protected  void sendToAll(Message message)
           
 void setGroupID(java.lang.String groupID)
           
 void setLocalSID(LocalSID localSID)
          Sets the LocalSID service.
 void setName(java.lang.String name)
          Sets the name of the service to name.
 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.
 void setServiceInstanceID(ServiceInstanceID instanceID)
          Sets the ServiceInstanceID for this service.
 void setServiceProxy(ServiceProxy proxy)
           
 void setStatus(byte status, java.lang.String helpText)
          Set the status for the service.
 void setTopic(java.lang.String topic)
           
 void start()
          Start the service.
 void stop()
           
 java.lang.String toXML()
           
 java.lang.String toXMLFull()
           
 java.lang.String toXMLFullRecursively()
           
 java.lang.String toXMLRecursively()
           
 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

context

protected final DeviceContext context

info

protected final PRDService info
The info about the service.


siid

protected ServiceInstanceID siid

connectionsMonitor

protected ist.palcom.services.AbstractService.ConnectionsMonitor connectionsMonitor

_node

protected HgraphNode _node
hgraph impl

Constructor Detail

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String name,
                       boolean hasDesc,
                       boolean remoteConnect,
                       byte distribution,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String readableVersionName,
                       java.lang.String serviceHelpText,
                       LocalSID localSID)
                throws java.io.IOException
Create a new service instance.

Parameters:
context - The device context of the service
name - The human-readable name of the service
hasDesc - Does the service have a description
remoteConnect - Will the service act on RemoteConnect messages
distribution - The way the service connects to other services
protocol - The service interaction protocol spoken by the service
reliable - Do connecting services have to use reliable communication
readableVersionName - A version presentation for the service
serviceHelpText - A describing text for the service
localSID - A Local ServiceID for the service
Throws:
java.io.IOException

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String serviceName,
                       boolean hasDesc,
                       boolean remoteConnect,
                       byte distribution,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String versionName,
                       java.lang.String helpText,
                       ServiceProxy sp,
                       LocalSID localSID)
                throws java.io.IOException
Throws:
java.io.IOException

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String serviceName,
                       boolean hasDesc,
                       boolean remoteConnect,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String versionName,
                       java.lang.String helpText,
                       ServiceProxy sp,
                       LocalSID localSID,
                       Topic topic)
                throws java.io.IOException
Constructor for Broadcast services.

Throws:
java.io.IOException

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String serviceName,
                       boolean hasDesc,
                       boolean remoteConnect,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String versionName,
                       java.lang.String helpText,
                       ServiceProxy sp,
                       LocalSID localSID,
                       GroupID groupID)
                throws java.io.IOException
Constructor for Groupcast services.

Throws:
java.io.IOException

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String serviceName,
                       boolean hasDesc,
                       boolean remoteConnect,
                       byte distribution,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String versionName,
                       java.lang.String helpText,
                       ServiceProxy sp)
                throws java.io.IOException
Throws:
java.io.IOException

AbstractService

public AbstractService(DeviceContext context,
                       java.lang.String serviceName,
                       boolean hasDesc,
                       boolean remoteConnect,
                       byte distribution,
                       java.lang.String protocol,
                       boolean reliable,
                       java.lang.String versionName,
                       java.lang.String helpText)
                throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getServiceInfo

public PRDService getServiceInfo()
Specified by:
getServiceInfo in interface Service

getSelector

public Selector getSelector()

setLocalSID

public void setLocalSID(LocalSID localSID)
Sets the LocalSID service. The LocalSID will be used for uniquely identifying the service. The LocalSID must contain deviceID.

Throws:
java.lang.IllegalStateException - If the LocalSID has already been set.

setServiceInstanceID

public void setServiceInstanceID(ServiceInstanceID instanceID)
Sets the ServiceInstanceID for this service. This method must be called exactly once. The DiscoveryManager will be updated with this info.


getServiceID

public abstract ServiceID getServiceID()
Returns:
the ServiceID of the service.

getServiceInstanceID

public ServiceInstanceID getServiceInstanceID()
Returns:
the ServiceInstanceID, or null if none has been set

setStatus

public void setStatus(byte status,
                      java.lang.String helpText)
Set the status for the service. The byte representations for the status can be found in PRDData.


setName

public void setName(java.lang.String name)
Sets the name of the service to name.


start

public void start()
           throws java.io.IOException
Start the service. The LocalSID must be set before calling this method (through a constructor, or through a call to the setLocalSID method). If the service is started already, nothing happens. The DiscoveryManager will be updated with info about the service.

Throws:
java.lang.IllegalStateException - if the LocalSID has not been set.
java.io.IOException

stop

public void stop()
          throws java.io.IOException
Throws:
java.io.IOException

setTopic

public void setTopic(java.lang.String topic)

setGroupID

public void setGroupID(java.lang.String groupID)

setServiceProxy

public void setServiceProxy(ServiceProxy proxy)

getServiceProxy

public ServiceProxy getServiceProxy()
Specified by:
getServiceProxy in interface Service

connectTo

public void connectTo(LocalSID localSID)
Connect to the service identified by localSID. If there is already a connection to that service, nothing happens. Subclasses are notified by a call to connectionCreated, and InfoEvents are sent to registered listeners, once the connection is established (may happen after this method has returned). ConnectionInfoEvents will be sent to registered listeners if a new connection is established.

Specified by:
connectTo in interface Service
Parameters:
localSID - ID of the service to connect to.

addServiceProxyListener

public void addServiceProxyListener(PalcomThread listener)
Add a listener for received ServiceProxies, for established connections to providers.


removeServiceProxyListener

public void removeServiceProxyListener(PalcomThread listener)
Remove a listener for ServiceProxies.


getRemoteServiceProxy

protected ServiceProxy getRemoteServiceProxy(LocalSID localSID)

remoteServiceProxyIterator

protected java.util.Iterator remoteServiceProxyIterator()

disconnectFrom

public void disconnectFrom(LocalSID serviceLocalSID)
                    throws java.io.IOException
Closes the connection to the given provider and removes it from the list of connections. InfoEvents are sent to registered listeners. serviceLocalSID must include deviceID.

Specified by:
disconnectFrom in interface Service
Throws:
java.io.IOException

sendToAll

protected void sendToAll(Message message)

connectionCreated

protected void connectionCreated(UnicastConnection connection)
Notification that a new connection has been established. Service-specific things may be performed by subclasses. The default implementation here is empty.


connectionClosed

protected void connectionClosed(UnicastConnection connection)
Notification that a connection has been closed. Service-specific things may be performed by subclasses. The default implementation here is empty.


getConnections

protected java.util.ArrayList getConnections()
Method for testing.

Returns:
All connections to customers.

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