com.pervasa.atlas.dev.service
Class AtlasServiceClass

java.lang.Object
  extended bycom.pervasa.atlas.dev.service.AtlasServiceClass
All Implemented Interfaces:
AtlasService

public class AtlasServiceClass
extends java.lang.Object
implements AtlasService

Class providing basic Atlas Service functions Developers who write their own Atlas Service bundles need to make their implementation extend the AtlasServiceClass

Author:
rbose

Field Summary
protected  NodeServiceHandler handler
           
protected static boolean isSubscribe
           
protected  java.util.Properties serviceProperties
           
 
Constructor Summary
AtlasServiceClass()
           
 
Method Summary
protected  void addProperty(java.lang.String key, java.lang.String value)
          Method provided for adding any additional properties for this service Can be used by authors of service bundles for putting in properties in addition to the default ones already provided by the middleware.
 void DataHandler(java.lang.String data, java.lang.String channel)
          Event Handler Method called by the node service handler when data arrives from the node.
protected  void getData(AtlasService serv)
          Pull Data from node.
protected  java.util.Properties getProperties()
          Get the properties associated with this service
 boolean isSubscriber()
          Checks if this service is a subscriber (i.e.
protected  void removeProperty(java.lang.String key, java.lang.String value)
          Method provided for removing any properties associated with this service Use carefully since removing properties might make some applications behave abnormally
protected  void sendCommand(AtlasService serv, java.lang.String command)
          Send a Low-level command to the Node.
 void setNodeServiceHandler(NodeServiceHandler handler)
          Called by the node service handler to bind itself to this Service.
 void setProperties(java.util.Properties props)
          Method called by NodeServiceHandler to set properties associated with the device being represented by this service.
protected  void subscribe(AtlasService serv)
          Become a subscriber to the sensor data.
protected  void unsubscribe(AtlasService serv)
          Unsubscribe from the sensor data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handler

protected NodeServiceHandler handler

isSubscribe

protected static boolean isSubscribe

serviceProperties

protected java.util.Properties serviceProperties
Constructor Detail

AtlasServiceClass

public AtlasServiceClass()
Method Detail

setNodeServiceHandler

public final void setNodeServiceHandler(NodeServiceHandler handler)
Called by the node service handler to bind itself to this Service. DO NOT call this method in your code!

Specified by:
setNodeServiceHandler in interface AtlasService
Parameters:
handler - - NodeServiceHandler bound to this service

setProperties

public final void setProperties(java.util.Properties props)
Method called by NodeServiceHandler to set properties associated with the device being represented by this service. DO NOT call this method in your code!

Specified by:
setProperties in interface AtlasService
Parameters:
props - - The properties associated with this service
See Also:
Properties object will contain the following standard property keys (* = optional): node-id (specified by middleware) - NodeId of node to which device is connected ; channel (specified by middleware) - Channel of node to which device is connected ; bundle-id (specified by middleware) - BundleId of service bundle which is bound to this device ; bundle-location (specified by middleware) - Physical location on disk of bundle ; location* (specified by user who configured the node) - Location of device eg. door, bedroom etc. ; label* (specified by user who configured the node)- Label attached to device eg. doorsensor-1,ps5 etc. ; measure-type* (can be specified by service bundle using addProperty()) - Type of measurement; eg. temperature, pressure etc. ; measure-unit* (specified by service bundle using addProperty()) - Unit of measurement; eg. celcius, psi etc. ; data-type* (specified by the service bundle using addProperty()) - Type of reading data; int, float, double, long or string device-type* (specified by service bundle using addProperty()) - Type of device; eg. Sensor, Actuator or Hybrid(ie both)

getProperties

protected final java.util.Properties getProperties()
Get the properties associated with this service

Returns:
Properties object associated with this service

addProperty

protected final void addProperty(java.lang.String key,
                                 java.lang.String value)
Method provided for adding any additional properties for this service Can be used by authors of service bundles for putting in properties in addition to the default ones already provided by the middleware. For details see the setProperties description

Parameters:
key -
value -

removeProperty

protected final void removeProperty(java.lang.String key,
                                    java.lang.String value)
Method provided for removing any properties associated with this service Use carefully since removing properties might make some applications behave abnormally

Parameters:
key -

DataHandler

public void DataHandler(java.lang.String data,
                        java.lang.String channel)
Event Handler Method called by the node service handler when data arrives from the node. This method needs to be implemented by the author of the service bundle with author specific code for handling the data

Specified by:
DataHandler in interface AtlasService
Parameters:
data - The data arriving from the device
channel - The channel to which device is connected

isSubscriber

public final boolean isSubscriber()
Checks if this service is a subscriber (i.e. if data is pushed to it automatically)

Specified by:
isSubscriber in interface AtlasService
Returns:
true if service is a subscriber false if service is not a subscriber

getData

protected final void getData(AtlasService serv)
Pull Data from node. If data is not pushed to this service then it can call this method to get sensor data. This method is non-blocking. When data arrives in response to this method being called, the DataHandler method is called. This method is useful when a service does not require a continous stream of data from the sensor and only needs sensor data at certain times

Parameters:
serv - The AtlasService object which is calling this method

subscribe

protected final void subscribe(AtlasService serv)
Become a subscriber to the sensor data. In this case data will get pushed automatically to the Service and the getData() method does not need to be called periodically.

Parameters:
serv - The AtlasService object which is calling this method

unsubscribe

protected final void unsubscribe(AtlasService serv)
Unsubscribe from the sensor data. In this case the data stream from the sensor is terminated and the Service will need to call getData() in order to get further sensor readings

Parameters:
serv - The AtlasService object which is calling this method

sendCommand

protected final void sendCommand(AtlasService serv,
                                 java.lang.String command)
Send a Low-level command to the Node. This method is usually called by Actuator Services which require low level device specific commands to be executed by the node in order to control an actuator

Parameters:
serv - The AtlasService object which is calling this method
command - The low-level Command String to be executed by the Node