stella.sensor
Class SensorRepository

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.SensorRepository
All Implemented Interfaces:
Cloneable, Remote, EventListener, DataListener, RmiDataDepositing, RmiParameterClustering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing

public class SensorRepository
extends AbstractRmiCaster
implements RmiParameterClustering, RmiDataDepositing, Initializable, DataListener

This class acts as a repository for a whole bundle of sensor values. It has to have local access to the sensors, thus it must be started within the same virtual machine as the sensors it monitors, thus it will be started from within a weather station.


Nested Class Summary
protected  class SensorRepository.Averager
          This class collects all data events generated during the averaging interval.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Map<String,List<DataEvent>> average
          The hash map used for buffering the data events.
private  SensorRepository.Averager averagethread
          The average thread for notification of data listeners.
private  List<Object> collect
          The data-collector classes to use for processing the averages.
private static boolean DEFBIND
          The default auto-binding.
static String DEFBINDNAME
          The default binding name.
static long DEFTIMERINTERVAL
          The default sampling intervall.
private  boolean isScheduled
          Averager scheduling may not start before the first data event.
static String KEY_BIND
          The referring to auto-binding of the sensor repository.
static String KEY_DATACOLLECTOR
          The key linked to the properties of the data collector class.
static String KEY_IGNORE
          The key linked to the sensor that should not be monitored.
static String KEY_TIMERINTERVAL
          The key linked to the scheduling intervall of the timer, in ms.
private  Shelf<Map<String,DataEvent>> longterm
          Stores a number of averaged data events mappings.
private  Map<String,DataEvent> lookup
          The look-up table matching sensor names to actual data events.
private  Timer schedule
          The timer class used for scheduling the data collector.
private  WeatherSurveying station
          A reference to the weather station for deregistering on exit.
private  Map<String,Boolean> valid
          The last data event received was valid.
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_BINDNAME, 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.RmiDataDepositing
NAMING_EXTENSION
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
SensorRepository(Map<String,String> prop)
          Constructs a new readout-repository.
 
Method Summary
 boolean addRmiDataCollector(RmiDataCollecting rmicollect)
          Registers late-comming rmi data-collectors.
 void dataAvailable(DataEvent de)
          Receives an incoming DataEvent.
 void exit()
          Exits the read-out repository.
 DataEvent getActualData(String name)
          Returns the last data event received from the sensor with the given name.
 long getBaseInterval()
          For convenience, return the base timer interval.
 void init()
          Initializes the read-out repository.
protected  void initTimer(List<String> files)
          Initializes the timer class scheduler and the DataCollecting classes for use with this short-average repository.
 boolean isValidData(String name)
          Returns true, if the last data event received for the given sensor name was a valid one.
 void registerSensors(WeatherSurveying caller)
          Initalizes the repository sensors.
 boolean removeRmiDataCollector(RmiDataCollecting rmicollect)
          Deregisters an rmi data-collector.
 void rmiAddParameter(URL info)
          Throws an unsupported operation exception-sensors are read-only.
 Object rmiGet(String name)
          Returns the actual value of the stated sensor.
 Set<String> rmiGetAllParameterNames()
          Returns the names of all sensors observed by this repository as a set.
 void rmiRemoveParameter(String info)
          Throws an unsupported operation exception-sensors are read-only.
 Object rmiSet(String name, Object to)
          Throws an unsupported operation exception-sensors are read-only.
 String toString()
          Returns the list of served sensor names.
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, 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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
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
 

Field Detail

KEY_IGNORE

public static final String KEY_IGNORE
The key linked to the sensor that should not be monitored.

See Also:
Constant Field Values

KEY_BIND

public static final String KEY_BIND
The referring to auto-binding of the sensor repository.

See Also:
Constant Field Values

KEY_DATACOLLECTOR

public static final String KEY_DATACOLLECTOR
The key linked to the properties of the data collector class.

See Also:
Constant Field Values

KEY_TIMERINTERVAL

public static final String KEY_TIMERINTERVAL
The key linked to the scheduling intervall of the timer, in ms.

See Also:
Constant Field Values

DEFBIND

private static final boolean DEFBIND
The default auto-binding.

See Also:
Constant Field Values

DEFBINDNAME

public static final String DEFBINDNAME
The default binding name.

See Also:
Constant Field Values

DEFTIMERINTERVAL

public static final long DEFTIMERINTERVAL
The default sampling intervall.

See Also:
Constant Field Values

station

private WeatherSurveying station
A reference to the weather station for deregistering on exit.


lookup

private Map<String,DataEvent> lookup
The look-up table matching sensor names to actual data events.


valid

private Map<String,Boolean> valid
The last data event received was valid.


average

private Map<String,List<DataEvent>> average
The hash map used for buffering the data events.


longterm

private Shelf<Map<String,DataEvent>> longterm
Stores a number of averaged data events mappings.


schedule

private Timer schedule
The timer class used for scheduling the data collector.


averagethread

private SensorRepository.Averager averagethread
The average thread for notification of data listeners.


isScheduled

private boolean isScheduled
Averager scheduling may not start before the first data event.


collect

private List<Object> collect
The data-collector classes to use for processing the averages.

Constructor Detail

SensorRepository

public SensorRepository(Map<String,String> prop)
                 throws RemoteException
Constructs a new readout-repository. Construction fails if neither of the two #KEY_LIST or the #KEY_FILE keys are given.
Prior to using the repository, the registerSensors(stella.sensor.WeatherSurveying) method must be called.

Throws:
RemoteException
Method Detail

init

public void init()
Initializes the read-out repository. This means binding it to the registry, if binding is intended via the (KEY_BIND key.

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

exit

public void exit()
Exits the read-out repository. This means unbinding it from the registry, if binding is intended via the (KEY_BIND key.

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

registerSensors

public void registerSensors(WeatherSurveying caller)
Initalizes the repository sensors. This method is calls back the WeatherSurveying for its list of sensors and registers to all of them that are not explicetly forbidden in the KEY_IGNORE list.


dataAvailable

public void dataAvailable(DataEvent de)
Receives an incoming DataEvent. This data event is stored in the lookup-table, using its RmiEvent.getSourceName() method as a key.

Specified by:
dataAvailable in interface DataListener

getActualData

public DataEvent getActualData(String name)
Returns the last data event received from the sensor with the given name. If the name is not in the list, or no data has ever been received, this method returns null.


isValidData

public boolean isValidData(String name)
Returns true, if the last data event received for the given sensor name was a valid one.


getBaseInterval

public long getBaseInterval()
For convenience, return the base timer interval.


rmiGet

public Object rmiGet(String name)
              throws RemoteException
Returns the actual value of the stated sensor. If the data event linked to the stated sensor has an undefined RawDataEvent.getPhysical(), the sensor's raw data, as returned by the RawDataEvent.getRaw() method is returned.

Specified by:
rmiGet in interface RmiParameterClustering
Returns:
A Double object carrying the actual sensor data
Throws:
RemoteException

rmiSet

public Object rmiSet(String name,
                     Object to)
              throws RemoteException
Throws an unsupported operation exception-sensors are read-only.

Specified by:
rmiSet in interface RmiParameterClustering
Returns:
The old parameter value.
Throws:
RemoteException

rmiAddParameter

public void rmiAddParameter(URL info)
                     throws RemoteException
Throws an unsupported operation exception-sensors are read-only.

Specified by:
rmiAddParameter in interface RmiParameterClustering
Throws:
RemoteException

rmiRemoveParameter

public void rmiRemoveParameter(String info)
                        throws RemoteException
Throws an unsupported operation exception-sensors are read-only.

Specified by:
rmiRemoveParameter in interface RmiParameterClustering
Throws:
RemoteException

rmiGetAllParameterNames

public Set<String> rmiGetAllParameterNames()
                                    throws RemoteException
Returns the names of all sensors observed by this repository as a set. Note that only sensors that have already sent at least one data event are considered.

Specified by:
rmiGetAllParameterNames in interface RmiParameterClustering
Throws:
RemoteException

addRmiDataCollector

public boolean addRmiDataCollector(RmiDataCollecting rmicollect)
                            throws RemoteException
Registers late-comming rmi data-collectors. Additionally to adding the data collector to the repositories notification list, the rmimap is passed to the registering instance.

Specified by:
addRmiDataCollector in interface RmiDataDepositing
Returns:
True on success.
Throws:
RemoteException

removeRmiDataCollector

public boolean removeRmiDataCollector(RmiDataCollecting rmicollect)
                               throws RemoteException
Deregisters an rmi data-collector. Should be called by the data collector as it goes offline.

Specified by:
removeRmiDataCollector in interface RmiDataDepositing
Throws:
RemoteException

toString

public String toString()
Returns the list of served sensor names.

Overrides:
toString in class PropertyContainer

initTimer

protected void initTimer(List<String> files)
Initializes the timer class scheduler and the DataCollecting classes for use with this short-average repository. All valid data collectors (non-null returns from AbstractDataCollector.createDataCollector(java.util.Map)) are than servered within one timer task. Note that it is not possible to use one short-average repository with different averaging intervalls, but the registered listeners can define different multiples of the base interval.