stella.sensor
Class AbstractSensor

java.lang.Object
  extended by util.PropertyContainer
      extended by util.rmi.RmiPropertyContainer
          extended by util.rmi.AbstractRmiCaster
              extended by stella.sensor.AbstractSensor
All Implemented Interfaces:
Cloneable, Remote, RmiErrorCaster, Telemetering, ExitCleaning, Initializable, PropertyBearing, RmiCaster, RmiPropertyBearing
Direct Known Subclasses:
RS485RainSensor, TimerTaskSensor

public abstract class AbstractSensor
extends AbstractRmiCaster
implements Telemetering, RmiErrorCaster, ExitCleaning

The abstract base class used for reading abstract sensors. It is implemented as a demon thread, which, once started, keeps reading the sensor values at fixed time intervalls, until the method cancel() is called. The stop() method of Thread is deprecated and should not be used.
To work for different kind of sensors, it is assumed that any sensor has the following properties.

The properties for this class contain at least the following keys (values in parentheses are the default values): As from version 1.0.1, the timing of the readings is taking into account the readout time of the sensor: At start up, the actual time is recorded, and re-reads of the sensor are timed to occur on modulos of the respawn time. Additionally, the time consumed for reading out the sensor is checked and a warning message is issued, if the respawning is too fast. This warning message is issued to any registered RmiErrorListener.

This class and therefore all its subclasses support RMI access. In the basic version a sensor exports its properties to rmi clients via the stella.rmi.RmiPropertyBearing interface and allows rmi error listeners to register via the RmiErrorListener interface. Methods for registering this services to the rmi-registry are provided but must be called seperately. If the appropriate property is set the binding is done at construct.

See Also:
ConvertToPhysical, SmoothingSensor, CumulativeSensor

Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyContainer
PropertyContainer.URLResource
 
Field Summary
private  ConvertToPhysical convert
          The conversion tool to render physical quantities from raw readings.
private static boolean DEFBIND
          The default auto-binding.
private  Vector errlist
          The list of ErrorListeners.
static String KEY_BIND
          The key in the Map referring to auto-binding of the sensor.
static String KEY_BINDNAME
          The key in the Map referring to the bind name of the sensor.
static String KEY_CONVERT
          The key pointing to the properties file of the conversion object.
static String KEY_DESCRIPTION
          The key in the Map list referring to the name of the sensor.
static String KEY_SENSORNAME
          The key in the Map list referring to the name of the sensor.
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORT
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR, KEY_NOINITONCREATE, KEY_RESOURCEBUNDLES
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected AbstractSensor(Map qualify)
          Constructs a fully-qualified sensor.
 
Method Summary
 void addRmiErrorListener(RmiErrorListener ear)
          Adds an RmiErrorListener to the registered listeners.
static Telemetering createSensor(Map qualify)
          Creates a sensor using the class name found in the properties file.
 void exit()
          Unbind from registry, if bound.
 String getBindName()
          Returns the name of this sensor used for binding.
 ConvertToPhysical getConvert()
          Returns the ConvertToPhysical instance used by this data sensor or null if not defined.
 long getRespawn()
          Returns zero to indicate a threadless sensor.
 String getSensorDescription()
          Returns a lengthy description of this sensor by parsing through the properties for the KEY_DESCRIPTION entry.
 String getSensorInitInfo()
          After initialization, we know if we have a conversion object, if we are bound and our name.
 String getSensorName()
          Returns the name of this sensor.
 void init()
          Does some initialization immediately after the construction phase.
 TimerTask initSensorTimerTask()
          Returns null, meaning a thread-less sensor.
protected  void notifyErrorListener(ErrorEvent ee)
          Notifies all registered ErrorListeners.
 void removeRmiErrorListener(RmiErrorListener ear)
          Removes an RmiErrorListener from the registered listeners.
 void setConvert(ConvertToPhysical ctp)
          Sets the ConvertToPhysical instance used by this data sensor.
 String status()
          A String description of this sensor.
 String toString()
          A String description of this sensor.
 
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.PropertyContainer
augment, augment, augment, clone, createFrom, createFrom, createFrom, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getLocalClassLoader, getLocalized, getLocalized, getLocalizedString, getLocalizedString, getProperties, getPropertiesToKey, getPropertiesToKey, getProperty, getResource, getResourceAsStream, getResourceFromKey, getResources, has, isNew, keyCreate, keyCreate, parseObject, reload, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface stella.sensor.Telemetering
cancel, getReading, getTimeOfRead, validReading
 
Methods inherited from interface util.PropertyBearing
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getLocalized, getProperties, getProperty, getResource, getResourceAsStream, getResources, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 

Field Detail

KEY_SENSORNAME

public static final String KEY_SENSORNAME
The key in the Map list referring to the name of the sensor.

See Also:
Constant Field Values

KEY_DESCRIPTION

public static final String KEY_DESCRIPTION
The key in the Map list referring to the name of the sensor.

See Also:
Constant Field Values

KEY_BIND

public static final String KEY_BIND
The key in the Map referring to auto-binding of the sensor.

See Also:
Constant Field Values

KEY_BINDNAME

public static final String KEY_BINDNAME
The key in the Map referring to the bind name of the sensor.

See Also:
Constant Field Values

KEY_CONVERT

public static final String KEY_CONVERT
The key pointing to the properties file of the conversion object.

See Also:
Constant Field Values

DEFBIND

private static final boolean DEFBIND
The default auto-binding.

See Also:
Constant Field Values

errlist

private transient Vector errlist
The list of ErrorListeners.


convert

private ConvertToPhysical convert
The conversion tool to render physical quantities from raw readings.

Constructor Detail

AbstractSensor

protected AbstractSensor(Map qualify)
Constructs a fully-qualified sensor. The name and the default respawn time is used to construct a default Map object, if the given Map object is null. Use of this constructor guarantees that the Map keys name and respawn are always set.
The Sensor automatically sets its priority to a daemon thread.

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

init

public void init()
Does some initialization immediately after the construction phase. This construct can be used to circumvent timing conflicts during the construction phase. E.g. subclasses can override this method by a simple empty method, comence the construction with the super keyword and add another init routine after the construction phase that eventually calls this method.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyContainer

exit

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

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

getConvert

public ConvertToPhysical getConvert()
Returns the ConvertToPhysical instance used by this data sensor or null if not defined.

Specified by:
getConvert in interface Telemetering

setConvert

public void setConvert(ConvertToPhysical ctp)
Sets the ConvertToPhysical instance used by this data sensor.

Specified by:
setConvert in interface Telemetering

initSensorTimerTask

public TimerTask initSensorTimerTask()
Returns null, meaning a thread-less sensor. Sensors that actually need a thread must override this method.

Specified by:
initSensorTimerTask in interface Telemetering
Returns:
The ready-to-start timer-task of this sensor.
See Also:
Telemetering.getRespawn()

getRespawn

public long getRespawn()
Returns zero to indicate a threadless sensor. Sensors that actually need a thread must override this method.

Specified by:
getRespawn in interface Telemetering
Returns:
Zero, if this sensor does not need a thread.

createSensor

public static Telemetering createSensor(Map qualify)
Creates a sensor using the class name found in the properties file. If the class construction fails for any reason a error message is printed to system err and the thrown exception is propagated up. Note that direct notification of RmiErrorListeners is not possible prior to sensor construction.

Parameters:
qualify - The properties of the new sensor.

getSensorName

public String getSensorName()
Returns the name of this sensor. Using one of the non-trivial constructors gurantees that the name property is set.
Note that the name should be unique.

Specified by:
getSensorName in interface Telemetering
Returns:
A qualifying name.

getBindName

public String getBindName()
Returns the name of this sensor used for binding. Note that this name is per definition unique.

Overrides:
getBindName in class AbstractRmiCaster
Returns:
A qualifying name.

getSensorDescription

public String getSensorDescription()
Returns a lengthy description of this sensor by parsing through the properties for the KEY_DESCRIPTION entry. If this property is not set, we return the sensor name.

Specified by:
getSensorDescription in interface Telemetering

getSensorInitInfo

public String getSensorInitInfo()
After initialization, we know if we have a conversion object, if we are bound and our name. This info is returned in a comprehensive way.

Specified by:
getSensorInitInfo in interface Telemetering

addRmiErrorListener

public void addRmiErrorListener(RmiErrorListener ear)
                         throws RemoteException
Adds an RmiErrorListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addRmiErrorListener in interface RmiErrorCaster
Parameters:
ear - The listener to add.
Throws:
RemoteException
Since:
1.0.1

removeRmiErrorListener

public void removeRmiErrorListener(RmiErrorListener ear)
                            throws RemoteException
Removes an RmiErrorListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeRmiErrorListener in interface RmiErrorCaster
Parameters:
ear - The listener to remove.
Throws:
RemoteException
Since:
1.0.1

toString

public String toString()
A String description of this sensor. Returns the name of the sensor.

Overrides:
toString in class PropertyContainer

status

public String status()
A String description of this sensor. Returns the name and readiung of the sensor.

Specified by:
status in interface Telemetering

notifyErrorListener

protected void notifyErrorListener(ErrorEvent ee)
Notifies all registered ErrorListeners. This method parses through the Vector of ErrorListeners and passes the argument to their errorOccured method. Per default the SystemErrListener is registered, which simply outputs the error message to System.err.

Parameters:
ee - The ErrorEvent to pass to the Listeners.
Since:
1.0.1