stella.sensor
Class DataSensor

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiCaster
                      extended by stella.sensor.AbstractSensor
                          extended by stella.sensor.TimerTaskSensor
                              extended by stella.sensor.DataSensor
All Implemented Interfaces:
Cloneable, Remote, Caster, DataCaster, RmiDataCaster, RmiErrorCaster, Telemetering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing
Direct Known Subclasses:
CumulativeSensor

public abstract class DataSensor
extends TimerTaskSensor
implements RmiDataCaster, DataCaster

A sensor that produces data events. The main difference to its superclass is the ability of this sensor to pack the data generated and pass them as an DataEvent to its registered listeners. On construct, it scans its property argument for the availability of KEY_REPORT, which should be mapped to an integer describing the number of individual data points to omit on listener notification. A value of zero means that data event generating is prohibited. If this key is not present, it defaults to DEFREPORT which is normally 10. As soon as the desired number of measurments is available, the run methods fork to the report() subroutine, which generates the data events and passes them to the registered listeners. Please ensure that the listeners method return immediately, otherwise some measurements will be lost. If a listener needs heavy processing of data, use a new thread instead.

This sensor adds the following properties if they are not set already (needs updating!):


Nested Class Summary
 
Nested classes/interfaces inherited from class stella.sensor.TimerTaskSensor
TimerTaskSensor.SensorRead
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  int count
          An integer counting the execution number.
private  Vector datalist
          The list of DataListeners.
(package private) static DecimalFormat DEFRAWFORMAT
          The default raw format String.
(package private) static int DEFREPORT
          The default report rate.
(package private) static DecimalFormat DEFSIGMAFORMAT
          The default format string for the values.
static String KEY_RAWFORMAT
          The key in the Map referring to the raw data format.
static String KEY_REPORT
          The name of the key for the report rate in this sensors properties.
static String KEY_SIGMAFORMAT
          The key to the sigma-format string.
private  NumberFormat rawform
          The decimal format for the raw values.
private  int reportrate
          The packing rate.
private  NumberFormat sigform
          The decimal format for the raw sigma values.
 
Fields inherited from class stella.sensor.TimerTaskSensor
KEY_RESPAWN
 
Fields inherited from class stella.sensor.AbstractSensor
KEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAME
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.rmi.RmiDataCaster
NAMING_EXTENSION
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected DataSensor(Map qualify)
          Constructs a fully-qualified data sensor.
 
Method Summary
 void addDataListener(DataListener ear)
          Adds a DataListener to the registered listeners.
 void addRmiDataListener(RmiDataListener ear)
          Adds a DataListener to the registered listeners.
protected  void conductOneMeasure()
          The modified version of the conductOneMeasure() method.
 void exit()
          Unbind from registry, if bound.
protected  DataEvent generateDataEvent()
          Takes the last sensor reading and produces a RawDataEvent out of it.
 NumberFormat getRawFormat()
          Returns the decimal format of the raw value.
 NumberFormat getSigmaFormat()
          Returns the decimal format of the sigma of the raw value.
 void removeDataListener(DataListener ear)
          Removes a DataListener from the registered listeners.
 void removeRmiDataListener(RmiDataListener ear)
          Removes a DataListener from the registered listeners.
protected  void report()
          This method is called repeatedly within the normal execution of this thread.
 
Methods inherited from class stella.sensor.TimerTaskSensor
cancel, equals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, initSensorTimerTask, isReady, newData, readSensor, regetRaw, setTimeOfRead, validReading
 
Methods inherited from class stella.sensor.AbstractSensor
addRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorInitInfo, getSensorName, init, notifyErrorListener, removeRmiErrorListener, setConvert, status, toString
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistry
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface stella.sensor.Telemetering
validReading
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_REPORT

public static final String KEY_REPORT
The name of the key for the report rate in this sensors properties.

See Also:
Constant Field Values

KEY_RAWFORMAT

public static final String KEY_RAWFORMAT
The key in the Map referring to the raw data format.

See Also:
Constant Field Values

KEY_SIGMAFORMAT

public static final String KEY_SIGMAFORMAT
The key to the sigma-format string.

See Also:
Constant Field Values

DEFREPORT

static final int DEFREPORT
The default report rate.

See Also:
Constant Field Values

DEFRAWFORMAT

static final DecimalFormat DEFRAWFORMAT
The default raw format String.


DEFSIGMAFORMAT

static final DecimalFormat DEFSIGMAFORMAT
The default format string for the values.


datalist

private transient Vector datalist
The list of DataListeners.


count

private int count
An integer counting the execution number.


reportrate

private int reportrate
The packing rate.


rawform

private NumberFormat rawform
The decimal format for the raw values.


sigform

private NumberFormat sigform
The decimal format for the raw sigma values.

Constructor Detail

DataSensor

protected DataSensor(Map qualify)
Constructs a fully-qualified data sensor. The name and the default respawn time and the default pack size are used to either construct a default Map object, or add this keys if not present in the Map object. Use of this constructor guarantees that the Map keys name, respawn, and pack are always set.

Parameters:
size - The maximum number of measurments to keep.
group - The ThreadGroup this thread belongs to.
name - The name of this thread (sensor).
qualify - The Map object describing this sensor.
Method Detail

exit

public void exit()
Unbind from registry, if bound. Signal data listeners that they should fuck off.

Specified by:
exit in interface ExitCleaning
Overrides:
exit in class AbstractSensor

addDataListener

public void addDataListener(DataListener ear)
Adds a DataListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addDataListener in interface DataCaster
Parameters:
ear - The listener to add.

removeDataListener

public void removeDataListener(DataListener ear)
Removes a DataListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeDataListener in interface DataCaster
Parameters:
ear - The listener to remove.

addRmiDataListener

public void addRmiDataListener(RmiDataListener ear)
                        throws RemoteException
Adds a DataListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addRmiDataListener in interface RmiDataCaster
Parameters:
ear - The listener to add.
Throws:
RemoteException

removeRmiDataListener

public void removeRmiDataListener(RmiDataListener ear)
                           throws RemoteException
Removes a DataListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeRmiDataListener in interface RmiDataCaster
Parameters:
ear - The listener to remove.
Throws:
RemoteException

getRawFormat

public NumberFormat getRawFormat()
Returns the decimal format of the raw value.


getSigmaFormat

public NumberFormat getSigmaFormat()
Returns the decimal format of the sigma of the raw value.


conductOneMeasure

protected void conductOneMeasure()
The modified version of the conductOneMeasure() method. Additionally to the readout of the sensor, the method report() is called as soon as the desired number of data points is present. If the pack rate is zero or negative this sensor does not export its reading as data events.

Overrides:
conductOneMeasure in class TimerTaskSensor

report

protected void report()
This method is called repeatedly within the normal execution of this thread. Depending on the report rate, defined by the KEY_REPORT property, this occurs on integer multiples of the readout time.

In the default behaviour, a RawDataEvent is generated and passed to all registered listeners. Please note that it is important that the listener's DataListener.dataAvailable(stella.DataEvent) returns immediately, otherwise some reading cycles will be skipped. No data is reported if the generateDataEvent() returns null.


generateDataEvent

protected DataEvent generateDataEvent()
Takes the last sensor reading and produces a RawDataEvent out of it. The error of the measurement is set to zero.