stella.sensor
Class DatabaseNow

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.DatabaseNow
All Implemented Interfaces:
Cloneable, Remote, EventListener, Logging, RmiDataListener, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiEventListener, RmiListener, RmiPropertyBearing

public class DatabaseNow
extends AbstractRmiListener
implements RmiDataListener, Initializable, ExitCleaning, Logging

A class that registers as an rmi-data listener to the stated list of sources Whenever a data event is received, the physical value is passed to a database, that only caches the most recent values.


Nested Class Summary
static class DatabaseNow.Run
          A class to create a a database now instance and run it.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static String DEFHOST
          The default host.
private static String DEFMAPPING
          All sensors that provide a key here have an sql-field value.
private static String DEFSENSORS
          The default list of sensors.
private static String DEFWHERE
           
private  Map fields
          The mapping of sensor names as in the dataevents to sql fields.
static String KEY_HOST
          The host where the data events are generated.
static String KEY_MAPPING
          A look-up table linking sensor names to sql fields.
static String KEY_SENSORS
          The list of binding names of the sensors.
static String KEY_WHERE
          The key to the where clause for database replacements.
private  GenericSql sql
          The sql-interface.
private  boolean virginfail
          False if a propbaly recurrent error has occured.
 
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.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
DatabaseNow(Map props)
          Constructs a new databaseNow! object.
 
Method Summary
protected  boolean deregisterAtCaster(RmiCaster test, Class single)
          Unregisters from an rmi-data caster.
 boolean deregisterCaster(Caster dummy)
          This weather database never needs external casters, it only registers at weather sensors.
 Thread getLoggerThread(ThreadGroup grp)
          This logger is a pure listener, it has now run method.
 void init()
          Initializes the database-now object.
protected  boolean registerAtCaster(RmiCaster test, Class single)
          Registers the database now to this caster, if it is an rmi-data caster.
 boolean registerCaster(Caster dummy)
          This weather database never needs external casters, it only registers at weather sensors.
 void rmiDataAvailable(DataEvent de)
          Receives a data event.
 
Methods inherited from class util.rmi.AbstractRmiListener
allBound, blockBinding, blockBinding, disconnect, exit, 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.ExitCleaning
exit
 
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_HOST

public static final String KEY_HOST
The host where the data events are generated.

See Also:
Constant Field Values

KEY_SENSORS

public static final String KEY_SENSORS
The list of binding names of the sensors.

See Also:
Constant Field Values

KEY_MAPPING

public static final String KEY_MAPPING
A look-up table linking sensor names to sql fields.

See Also:
Constant Field Values

KEY_WHERE

public static final String KEY_WHERE
The key to the where clause for database replacements.

See Also:
Constant Field Values

DEFHOST

private static final String DEFHOST
The default host.

See Also:
Constant Field Values

DEFSENSORS

private static final String DEFSENSORS
The default list of sensors.

See Also:
Constant Field Values

DEFMAPPING

private static final String DEFMAPPING
All sensors that provide a key here have an sql-field value.

See Also:
Constant Field Values

DEFWHERE

private static final String DEFWHERE
See Also:
Constant Field Values

sql

private GenericSql sql
The sql-interface. Also constructed with my properties.


fields

private Map fields
The mapping of sensor names as in the dataevents to sql fields.


virginfail

private boolean virginfail
False if a propbaly recurrent error has occured.

Constructor Detail

DatabaseNow

public DatabaseNow(Map props)
Constructs a new databaseNow! object. The mapping has no default value. The sql-access is constructed with identical properties as the database now! object.

Method Detail

init

public void init()
Initializes the database-now object. This means that the database now registers at all its listed data sensors. Additionally, the link to the database is opened. It remains open until the AbstractRmiListener.exit() method is called.
Registering to the sensors is a little bit awkward, because each sensor has three, possible different identifiers: One is the binding name on the sensor's host registry, one is the global and unique sensor name and another is the sql-field representing the sensor. The handling is done such that the sensor list provided with KEY_SENSORS points to the list of binding names of the sensor. Each entry found here is combined with the sensor's host to yield a binding name. Entries in the KEY_MAPPING link the sensor name as provided in the sensor data event to the appropriate SQL field. To allow data collection from sensors on different host, the KEY_HOST property is actually a list of hosts, while the KEY_SENSORS is a double-list (see StringTool.doubleTokenize(java.lang.String)). It is within the responsibility of the user to provide equal-size lists in the KEY_HOST and the outer KEY_SENSORS double list.

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

registerAtCaster

protected boolean registerAtCaster(RmiCaster test,
                                   Class single)
Registers the database now to this caster, if it is an rmi-data caster.

Specified by:
registerAtCaster in class AbstractRmiListener
Returns:
True, if this listener can register at the specified caster

deregisterAtCaster

protected boolean deregisterAtCaster(RmiCaster test,
                                     Class single)
Unregisters from an rmi-data caster.

Specified by:
deregisterAtCaster in class AbstractRmiListener
Returns:
True, if this listener can deregister at the specified caster

rmiDataAvailable

public void rmiDataAvailable(DataEvent de)
Receives a data event. If the data event is a RawDataEvent, first the data events source is matched to the appropriate KEY_MAPPING sql-field. If the sql-connection is open, the data is then updated in the database using the GenericSql.replace(java.util.Map, java.lang.String) method with the KEY_WHERE clause and using a mapping of the sql-name of the sensor to its value.

Specified by:
rmiDataAvailable in interface RmiDataListener

registerCaster

public boolean registerCaster(Caster dummy)
This weather database never needs external casters, it only registers at weather sensors.

Specified by:
registerCaster in interface Logging
Returns:
false

deregisterCaster

public boolean deregisterCaster(Caster dummy)
This weather database never needs external casters, it only registers at weather sensors.

Specified by:
deregisterCaster in interface Logging
Returns:
false

getLoggerThread

public Thread getLoggerThread(ThreadGroup grp)
This logger is a pure listener, it has now run method.

Specified by:
getLoggerThread in interface Logging
Parameters:
grp - The thread group the logger must run in.
Returns:
null