org.hackystat.sensorshell.command
Class SensorDataCommand

java.lang.Object
  extended by org.hackystat.sensorshell.command.Command
      extended by org.hackystat.sensorshell.command.SensorDataCommand

public class SensorDataCommand
extends Command

Implements the SensorData commands, of which there is "add", "send", and "statechange".

Author:
Philip Johnson

Field Summary
 
Fields inherited from class org.hackystat.sensorshell.command.Command
cr, email, host, password, properties, shell
 
Constructor Summary
SensorDataCommand(SingleSensorShell shell, SensorShellProperties properties, PingCommand pingCommand, org.hackystat.sensorbase.client.SensorBaseClient client)
          Creates the SensorDataCommand.
 
Method Summary
 void add(java.util.Map<java.lang.String,java.lang.String> keyValMap)
          Given a Map containing key-value pairs corresponding to SensorData fields and properties, constructs a SensorData instance and stores it for subsequent sending to the SensorBase.
 void add(org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData data)
          Adds the SensorData instance, invoking send if the max buffer size has been exceeded.
 long getTotalSent()
          Returns the total number of sensor data instances sent so far.
 boolean hasUnsentData()
          Returns true if this SensorDataCommand instance has remaining unsent data.
 int send()
          Sends accumulated data, including offline and current data from the AddCommand.
 void statechange(long resourceCheckSum, java.util.Map<java.lang.String,java.lang.String> keyValMap)
          Provides an easy way for sensors to implement "StateChange" behavior.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SensorDataCommand

public SensorDataCommand(SingleSensorShell shell,
                         SensorShellProperties properties,
                         PingCommand pingCommand,
                         org.hackystat.sensorbase.client.SensorBaseClient client)
Creates the SensorDataCommand.

Parameters:
shell - The sensorshell.
properties - The sensorproperties.
pingCommand - The Ping Command.
client - The SensorBase client.
Method Detail

send

public int send()
         throws SensorShellException
Sends accumulated data, including offline and current data from the AddCommand. If server not pingable, then the offline data is saved for a later attempt.

Returns:
The number of sensor data instances that were sent.
Throws:
SensorShellException - If problems occur sending the data.

add

public void add(java.util.Map<java.lang.String,java.lang.String> keyValMap)
         throws SensorShellException
Given a Map containing key-value pairs corresponding to SensorData fields and properties, constructs a SensorData instance and stores it for subsequent sending to the SensorBase.

Parameters:
keyValMap - The map of key-value pairs.
Throws:
SensorShellException - If problems occur sending the data.

add

public void add(org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData data)
         throws SensorShellException
Adds the SensorData instance, invoking send if the max buffer size has been exceeded.

Parameters:
data - The SensorData instance to be added.
Throws:
SensorShellException - If problems occur sending the data.

statechange

public void statechange(long resourceCheckSum,
                        java.util.Map<java.lang.String,java.lang.String> keyValMap)
                 throws java.lang.Exception
Provides an easy way for sensors to implement "StateChange" behavior. From the sensor side, StateChange can be implemented by creating a timer process that wakes up at regular intervals and gets the file (resource) that the current active buffer is attached to, plus a "checksum" (typically the size of the resource in characters or bytes or whatever). Then, the timer process simply creates the appropriate keyValMap as if for an 'add' event, and provides it to this method along with the buffer size. This method will check the passed buffer size and the Resource field against the values for these two fields passed in the last call of this method, and if either one has changed, then the "add" method is called with the keyValMap.

Parameters:
resourceCheckSum - Indicates the state of the resource, typically via its size.
keyValMap - The map of key-value pairs.
Throws:
java.lang.Exception - If problems occur while invoking the 'add' command.

getTotalSent

public long getTotalSent()
Returns the total number of sensor data instances sent so far.

Returns:
The total sent so far by this instance of SensorDataCommand.

hasUnsentData

public boolean hasUnsentData()
Returns true if this SensorDataCommand instance has remaining unsent data.

Returns:
True if there is data remaining to be sent.