stella.sensor
Class ReadoutRepository

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiListener
                      extended by stella.sensor.ReadoutRepository
All Implemented Interfaces:
Cloneable, Remote, EventListener, RmiDataListener, RmiParameterClustering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiEventListener, RmiListener, RmiPropertyBearing

public class ReadoutRepository
extends AbstractRmiListener
implements RmiParameterClustering, RmiDataListener, Initializable

This class acts as a repository for a whole bundle of sensor values. On initialisation it tries to register to all the sensors given with either the KEY_LIST or the KEY_FILE keys as a RmiDataListener. Incoming DataEvents from these sensors are buffered and can be retrieved with the getActualData(java.lang.String) method.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static int COUNT
          An internal counter for automatic naming.
private static boolean DEFBIND
          The default auto-binding.
private static String DEFBINDNAME
          The default binding name.
private static String DEFURLRESOURCES
          The resources to scout.
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_FILE
          The key linked to the sensor names.
static String KEY_LIST
          The key linked to the sensor names.
private  HashMap lookup
          The look-up table matching sensor names to actual data events.
 
Fields inherited from class util.rmi.AbstractRmiListener
KEY_ALIVE, KEY_EXPORTPORT, KEY_INIT, KEY_LISTENERNAME, KEY_RETRY, KEY_RETRYSLEEP, KEY_SHUTDOWNDELAY
 
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 util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
ReadoutRepository(Map prop)
          Constructs a new readout-repository.
 
Method Summary
 boolean bindToRegistry()
          Binds this repository's casting capabilities to a running registry.
protected  boolean deregisterAtCaster(RmiCaster rmi, Class single)
          Registers at the given caster.
 void exit()
          Exits the read-out repository.
 DataEvent getActualData(String name)
          Returns the last data event received from the sensor with the given name.
 void init()
          Initializes the read-out repository.
private static int nextCount()
          Gets the next available number at automatic naming.
protected  boolean registerAtCaster(RmiCaster rmi, Class single)
          Registers at the given caster.
 void registerSensors()
          Initalizes the repository sensors.
 void rmiAddParameter(URL info)
          Throws an unsupported operation exception-sensors are read-only.
 void rmiDataAvailable(DataEvent de)
          Receives an incoming DataEvent.
 Object rmiGet(String name)
          Returns the actual value of the stated sensor.
 Set 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.
 boolean unbindFromRegistry()
          Unbinds this repository from the registry.
 
Methods inherited from class util.rmi.AbstractRmiListener
allBound, blockBinding, blockBinding, disconnect, getIP, getListenerName, isConnected, listenerName, releaseBinding, releaseBinding, rescanned, startBinding, startBinding
 
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, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiEventListener
getListenerName
 
Methods inherited from interface util.rmi.RmiListener
disconnect, isConnected
 
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_LIST

public static final String KEY_LIST
The key linked to the sensor names. Given as a comma-separated list.

See Also:
Constant Field Values

KEY_FILE

public static final String KEY_FILE
The key linked to the sensor names. Given in a separate file.

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

DEFBIND

private static final boolean DEFBIND
The default auto-binding.

See Also:
Constant Field Values

DEFBINDNAME

private static final String DEFBINDNAME
The default binding name.

See Also:
Constant Field Values

DEFURLRESOURCES

private static final String DEFURLRESOURCES
The resources to scout.

See Also:
Constant Field Values

lookup

private HashMap lookup
The look-up table matching sensor names to actual data events.


COUNT

private static int COUNT
An internal counter for automatic naming.

Constructor Detail

ReadoutRepository

public ReadoutRepository(Map 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() method must be called.

Throws:
RemoteException
Method Detail

nextCount

private static int nextCount()
Gets the next available number at automatic naming.


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 AbstractRmiListener

bindToRegistry

public boolean bindToRegistry()
                       throws RemoteException
Binds this repository's casting capabilities to a running registry.

Throws:
RemoteException

unbindFromRegistry

public boolean unbindFromRegistry()
                           throws RemoteException
Unbinds this repository from the registry.

Throws:
RemoteException

registerSensors

public void registerSensors()
Initalizes the repository sensors. Each sensor-binding name given in the list is converted into a RmiDataCaster reference. The repository then registers at this caster as a listener. Note that construction of the lookup-table is done in this method, but the mapping is constructed as the first data-event from the specific source is received.

See Also:
registerAtCaster(util.rmi.RmiCaster, java.lang.Class)

rmiDataAvailable

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

Specified by:
rmiDataAvailable in interface RmiDataListener
Throws:
RemoteException

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.


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 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

registerAtCaster

protected boolean registerAtCaster(RmiCaster rmi,
                                   Class single)
Registers at the given caster. Only if the given caster is an instance of a RmiDataCaster, the repository registers at it.

Specified by:
registerAtCaster in class AbstractRmiListener
Returns:
True, if registering at the caster was successful.

deregisterAtCaster

protected boolean deregisterAtCaster(RmiCaster rmi,
                                     Class single)
Registers at the given caster. Only if the given caster is an instance of a RmiDataCaster, the repository registers at it.

Specified by:
deregisterAtCaster in class AbstractRmiListener
Returns:
True, if registering at the caster was successful.