stella.sensor
Class WeatherStation

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.AbstractWeatherSurveyor
                          extended by stella.sensor.WeatherStation
All Implemented Interfaces:
Cloneable, Remote, EventListener, Caster, ClusterDepending, Parameter, RmiWeatherCaster, RmiWeatherReporting, WeatherPredicting, WeatherSurveying, Trigger, WeatherCaster, WeatherListener, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing, StatusProviding
Direct Known Subclasses:
SimulatorWeather

public class WeatherStation
extends AbstractWeatherSurveyor
implements WeatherPredicting, WeatherListener, RmiWeatherReporting, Initializable

A class acting as a conductor of several WeatherSensors. Acts as a weather event listener and weather event caster but consideres a whole bunch of weather sensors for generating only a single weather events. This changes the behaviour in a way that it takes some burdon from classes that are interested in bad/good weather conditions. Weather events are now only generated if the combined vote of all sensor changes.

On construct the provided properties are scanned for the KEY_LIST. This should point to a file in the users personal java configuration directory Path where the names of the properties files for all sensor that comprise this weather station should be listed. Each entriy found is then used to generated a new Map object and pass it to the AbstractSensor.createSensor(java.util.Map) factory method. Additinally to the normal sensor construction the sensor properties are scanned for the necessity to register additional (sensors) to allow the weather judging capabilities of the newly generated sensor to unfold. Note that for RS485Sensors a PollingRS485Server has to be passed to the weather station prior to retrieving sensor data.
Note that this class is intended to use local sensors, but serves remote weather listeners.
This class serves remote error listeners.


Nested Class Summary
static class WeatherStation.Manage
          Allows rmi-access to the add/remove sensor properties of the weather station.
static class WeatherStation.Run
          Test purpose.
static class WeatherStation.WeatherStationData
          Implementation of the WeatherSurveying.DataBlock class.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Nested classes/interfaces inherited from interface stella.sensor.WeatherSurveying
WeatherSurveying.DataBlock
 
Field Summary
private  SimpleTrigger current
          The remote parameter value reporting true for currently good weather.
private static boolean DEFBIND
          The default auto-binding as a RmiWeatherCaster.
private static boolean DEFDAEMON
          The default name of the thread group to put all sensors into.
private static String DEFFILE
          The name of the file containing the default weather sensor list.
private  List drivers
          A list of all weather drivers registered to the weather station.
private  Vector errorList
          The error listeners to report to.
private  boolean isWeatherCaster
          The flag to indicate registering of the rmi weather event casting has already occured.
static String KEY_BIND
          The key referring to auto-binding of the weather station as an RmiWeatherCaster.
static String KEY_DAEMON
          The key referring to the thread group the sensors should run in.
static String KEY_DUMP
          The file where all parameter values should be stored on exit.
static String KEY_FILE
          The key to a file containing a (long) list of all sensors.
static String KEY_LIST
          The key to a comma-seperated list of all sensors.
static String KEY_NAME
          The key to the name of this weather station.
static String KEY_REPOSITORY
          The properties of the sensor repository.
private  WeatherEvent lastWeather
          The last weather event sent.
private  HashMap lookup
          The lookup table matching sensor to their votes.
private  SensorRepository repository
          A repository if the KEY_REPOSITORY is set.
private  Vector rmiList
          The weather listeners to report to.
private  Timer weatherSensors
          The timer where all weather sensors run.
 
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.RmiWeatherCaster
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
WeatherStation()
          Constructs a new weather station.
WeatherStation(Map qualify)
          Constructs a new weather station.
 
Method Summary
private  Telemetering addFromFile(String prop)
          Scans the resources for the properties given by a file name.
 void addRmiWeatherListener(RmiWeatherListener add)
          Adds a weather listener to this weather station.
 boolean addSensor(String properties)
          Adds a new sensor to an already running weather station.
private  Collection allSensorNames()
          Returns a collection of all sensors by name.
private  boolean check()
          Checks if all weather sensor report clear weather.
 boolean containsRemoteProperty(String key)
          Tests if this property container contains a certain property.
private  void crossRegister()
          Go thru the entire list of sensor and cross-register them if they are sensor depending.
 void exit()
          Exits the weather station and all sensors that are ExitCleaning instances.
 Object get()
          Serves the weather watching's remote parameter capability.
 Collection getAllSensorNames()
          Returns a Collection of all running weather sensors.
 Collection getAllSensors()
          Returns a collection of all sensors served by this weather station.
 int getCurrentlyRetarding()
          Returns the number of currently retarding sensors.
 WeatherEvent getCurrentWeather()
          Returns a weather event reflecting the current weather conditions.
 RmiDataCaster getDataSensor(String name)
          Returns a reference to the running weather sensor with the given name.
 long getElapsedToggleTime()
          Returns elapsed time since last toggle event.
 String getFormatted()
          Diverts to simple trigger.
 Date getLastToggleTime()
          Returns the last toggle time of the weather.
 String getName()
          Returns the name of this weather station.
 long getRemainsBadMaximum()
          throws UnsupportedOperationException();
 long getRemainsBadMinimum()
          Returns the time in ms the weather will stay bad for sure.
 long getRemainsGoodMaximum()
          Returns the time in ms the weather will stay good maximally (e.g until next sun rise).
 long getRemainsGoodMinimum()
          throws UnsupportedOperationException(); Returns the time in ms the weather will stay good.
 Map getRemoteProperties()
          Returns the entire properties of this object as a map.
 String getRemoteProperty(String key)
          Returns a special property of this property container.
 Telemetering getSensor(String name)
          Returns the sensor with the given name.
 String getStatus()
          Returns the status of the weather station.
 String getString()
          Diverts to simple trigger.
 Boolean getTrigger()
          Returns the combined status of all open-roof switches as a Boolean.
 void init()
          Initializes this weather station.
 boolean isTrue()
          Returns the combined status of all open-roof switches as a primitive boolean.
protected  void notifyWeatherListener(WeatherEvent we)
          Notifies all registered WeatherListeners.
 Object provideStatus()
          Returns a detailed description of the weather status.
 void registerCluster(ParameterClustering set)
          Registers a ParameterClustering instance to this weather station.
 void registerSensorDriver(Driver drv)
          Registers an instance of a polling rs485 server to all sensors that are instances of RS485Sensor.
 void removeRmiWeatherListener(RmiWeatherListener remove)
          Removes a weather listener from this weather station.
 boolean removeSensor(String name)
          Removes the weather sensor with the given name fro the weather station.
 Object set(Object to)
          Throws an unsupported exception.
 String setRemoteProperty(String key, String val)
          Sets a special property of this property container.
 Boolean setTrigger(Boolean to)
          Throws an unsupported exception.
 void startSensors()
          Starts all weather sensors.
 Boolean toggleTrigger()
          Throws an unsupported exception.
 String toString()
          Returns a very brief description of the weather station.
 void weatherChanged(WeatherEvent we)
          The receiver method of weather events.
 
Methods inherited from class stella.sensor.AbstractWeatherSurveyor
addWeatherListener, createWeatherSurveyor, removeWeatherListener, status
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, getBindName, isValid, unbindFromRegistry, unbindFromRegistry
 
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.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_NAME

public static final String KEY_NAME
The key to the name of this weather station.

See Also:
Constant Field Values

KEY_BIND

public static final String KEY_BIND
The key referring to auto-binding of the weather station as an RmiWeatherCaster.

See Also:
Constant Field Values

KEY_DAEMON

public static final String KEY_DAEMON
The key referring to the thread group the sensors should run in.

See Also:
Constant Field Values

KEY_LIST

public static final String KEY_LIST
The key to a comma-seperated list of all sensors.

See Also:
Constant Field Values

KEY_FILE

public static final String KEY_FILE
The key to a file containing a (long) list of all sensors.

See Also:
Constant Field Values

KEY_DUMP

public static final String KEY_DUMP
The file where all parameter values should be stored on exit.

See Also:
Constant Field Values

KEY_REPOSITORY

public static final String KEY_REPOSITORY
The properties of the sensor repository.

See Also:
Constant Field Values

DEFFILE

private static final String DEFFILE
The name of the file containing the default weather sensor list.

See Also:
Constant Field Values

DEFBIND

private static final boolean DEFBIND
The default auto-binding as a RmiWeatherCaster.

See Also:
Constant Field Values

DEFDAEMON

private static final boolean DEFDAEMON
The default name of the thread group to put all sensors into.

See Also:
Constant Field Values

repository

private SensorRepository repository
A repository if the KEY_REPOSITORY is set.


drivers

private List drivers
A list of all weather drivers registered to the weather station.


weatherSensors

private Timer weatherSensors
The timer where all weather sensors run.


lookup

private HashMap lookup
The lookup table matching sensor to their votes.


lastWeather

private WeatherEvent lastWeather
The last weather event sent.


isWeatherCaster

private boolean isWeatherCaster
The flag to indicate registering of the rmi weather event casting has already occured.


current

private SimpleTrigger current
The remote parameter value reporting true for currently good weather.


rmiList

private Vector rmiList
The weather listeners to report to.


errorList

private Vector errorList
The error listeners to report to.

Constructor Detail

WeatherStation

public WeatherStation()
               throws RemoteException
Constructs a new weather station. The list of all weather sensors to listen to is stored in the default properties file.

Throws:
RemoteException

WeatherStation

public WeatherStation(Map qualify)
Constructs a new weather station. The list of all weather sensors to listen to is generated from the properties. If the KEY_LIST is present it is used with higher priority as the KEY_FILE. The latter one should only be used if the list of sensors is so long that a comma-separated list is confusing.

The list of error listenerers and weather listeners is cleared.
To comprise all weather sensors into a distinct group a ThreadGroup is created.

Parameters:
qualify - The properties of this weather station.
Method Detail

init

public void init()
Initializes this weather station. This means reading the list file and converting the file names found in the list to sensor properties. The PropertySupplying.KEY_CLASS entry is used by the factory method AbstractSensor.createSensor(java.util.Map) to create new sensor instances. All entries are converted into weather sensors using a constructor that takes a single properties file as an argument. This implies that all subclasses of WeatherSensor must provide a constructor with a Map object as the argument!.
If the construction is successful the weather station registers itself as a weather listener to the newly created weather sensor and starts them within the sensor thread group. It maps the new sensor to a false boolean in the weather-conditions lookup table. If the sensor requires additional information to judge the weather situation the appropriate (sensors) objects are registered and can be querried by the get...SideInfoFor() methods.
Default bindings of the sensors are unimportant because all sensors must be locally accessible.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources
Parameters:
list - of Files, holding all the weather sensor properties to listen to.

addFromFile

private Telemetering addFromFile(String prop)
Scans the resources for the properties given by a file name. If properties are found, a new tlemetering instance is created and added to the look-up table.

Returns:
The newly created sensor.

crossRegister

private void crossRegister()
Go thru the entire list of sensor and cross-register them if they are sensor depending.


exit

public void exit()
Exits the weather station and all sensors that are ExitCleaning instances. If the KEY_DUMP property points to a file, the exit values of all sensors are written into that file.

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

registerSensorDriver

public void registerSensorDriver(Driver drv)
Registers an instance of a polling rs485 server to all sensors that are instances of RS485Sensor. The method parses through the set of weather sensors and registers the rs485 server to all sensors that can be cast to the RS485Sensor type.
If RS485Sensors are served within this weather station this method should be called before the sensors are started with startSensors(). If at least one sensor is of the RS485-type and the serial port is not already opened this method tries to open the serial port.

Specified by:
registerSensorDriver in interface WeatherSurveying

startSensors

public void startSensors()
Starts all weather sensors. This is separated from the construction phase to allow certain initialization steps to be performed prior to the actual start of sensor-data retrieval.

Specified by:
startSensors in interface WeatherSurveying

registerCluster

public void registerCluster(ParameterClustering set)
Registers a ParameterClustering instance to this weather station. If any sensor within the weather station is cluster depending, it receives this cluster. If we have ParameterDepending sensor in the station, they get all sensors within the cluster.

This method should always be called after the sensors has been constructed, before actually starting the sensors.

Specified by:
registerCluster in interface ClusterDepending

weatherChanged

public void weatherChanged(WeatherEvent we)
The receiver method of weather events. The weather station acts like a buffer for weather changes. It can generate weather events but only if the combined vote of all weather sensors in the weather station require a weather change. I.e. if the weather is bad and an additional sensor reports bad weather no weather event is generated. Only two toggle situations produce a weather event: Note that in both of the above cases a single weather event will be the event trigger. The source of this trigger event is copied to the source field of the weather event generated by the weather station.

Specified by:
weatherChanged in interface WeatherListener

getCurrentWeather

public WeatherEvent getCurrentWeather()
Returns a weather event reflecting the current weather conditions. This method is intended to be used only at or shortly after start-up before any weather events have been reported.

The weather event returned leaves its WeatherEvent.getReason() undefined.

Specified by:
getCurrentWeather in interface WeatherSurveying

getCurrentlyRetarding

public int getCurrentlyRetarding()
Returns the number of currently retarding sensors.

Specified by:
getCurrentlyRetarding in interface WeatherSurveying

getRemainsBadMinimum

public long getRemainsBadMinimum()
Returns the time in ms the weather will stay bad for sure. In an implementation consiting of a couple of served WeatherJudging instances, this method can return the maximum of all WeatherJudging.getMinClearUpTime().

Specified by:
getRemainsBadMinimum in interface WeatherPredicting

getRemainsBadMaximum

public long getRemainsBadMaximum()
throws UnsupportedOperationException();

Specified by:
getRemainsBadMaximum in interface WeatherPredicting

getRemainsGoodMinimum

public long getRemainsGoodMinimum()
throws UnsupportedOperationException(); Returns the time in ms the weather will stay good.

Specified by:
getRemainsGoodMinimum in interface WeatherPredicting

getRemainsGoodMaximum

public long getRemainsGoodMaximum()
Returns the time in ms the weather will stay good maximally (e.g until next sun rise).

Specified by:
getRemainsGoodMaximum in interface WeatherPredicting

check

private boolean check()
Checks if all weather sensor report clear weather. Returns false as soon as one sensor reports bad weather conditions or has not reported in. If for the first time we have a vote of all sensors, a weather event is generated anyhow.

This method notifies the weather listeners only on one occasion:

  1. If not all sensors have reported in, and the weather was either not determined before or was good before.


getRemoteProperties

public Map getRemoteProperties()
                        throws RemoteException
Returns the entire properties of this object as a map. Calls PropertyContainer.getProperties().

Specified by:
getRemoteProperties in interface RmiPropertyBearing
Overrides:
getRemoteProperties in class RmiPropertyContainer
Throws:
RemoteException

getRemoteProperty

public String getRemoteProperty(String key)
                         throws RemoteException
Returns a special property of this property container. Calls PropertyContainer.getProperty(java.lang.String).

Specified by:
getRemoteProperty in interface RmiPropertyBearing
Overrides:
getRemoteProperty in class RmiPropertyContainer
Parameters:
key - The key for the Map object.
Returns:
The value of the PropertyContainer.getProperty(java.lang.String) call.
Throws:
RemoteException

setRemoteProperty

public String setRemoteProperty(String key,
                                String val)
                         throws RemoteException
Sets a special property of this property container. Calls PropertyContainer.setProperty(java.lang.String, java.lang.String).

Specified by:
setRemoteProperty in interface RmiPropertyBearing
Overrides:
setRemoteProperty in class RmiPropertyContainer
Parameters:
key - The key for this Property.
value - The value of this Property.
Throws:
RemoteException

containsRemoteProperty

public boolean containsRemoteProperty(String key)
                               throws RemoteException
Tests if this property container contains a certain property. Calls PropertyContainer.has(java.lang.String).

Specified by:
containsRemoteProperty in interface RmiPropertyBearing
Overrides:
containsRemoteProperty in class RmiPropertyContainer
Throws:
RemoteException

getSensor

public Telemetering getSensor(String name)
Returns the sensor with the given name. Local access only, as defined in the WeatherSurveying interface.

Specified by:
getSensor in interface WeatherSurveying
Parameters:
name - The unique name of the sensor.

getAllSensors

public Collection getAllSensors()
Returns a collection of all sensors served by this weather station. Local access only, as defined in the WeatherSurveying interface.

Specified by:
getAllSensors in interface WeatherSurveying

getDataSensor

public RmiDataCaster getDataSensor(String name)
                            throws RemoteException
Returns a reference to the running weather sensor with the given name.

Specified by:
getDataSensor in interface RmiWeatherReporting
Throws:
RemoteException

getAllSensorNames

public Collection getAllSensorNames()
                             throws RemoteException
Returns a Collection of all running weather sensors.

Specified by:
getAllSensorNames in interface RmiWeatherReporting
Throws:
RemoteException

allSensorNames

private Collection allSensorNames()
Returns a collection of all sensors by name. Local access.


removeSensor

public boolean removeSensor(String name)
                     throws RemoteException
Removes the weather sensor with the given name fro the weather station.

Specified by:
removeSensor in interface RmiWeatherReporting
Returns:
True if a sensor of the given name was removed.
Throws:
RemoteException

addSensor

public boolean addSensor(String properties)
                  throws RemoteException
Adds a new sensor to an already running weather station. The argument to this method is a string that must be the filename of a properties file. This procedure will only work if:

Specified by:
addSensor in interface RmiWeatherReporting
Parameters:
properties - The name of the properties file of the sensor.
Returns:
True on success.
Throws:
RemoteException

getName

public String getName()
Returns the name of this weather station.

Specified by:
getName in interface Parameter

get

public Object get()
Serves the weather watching's remote parameter capability. Returns the status of the current weather as a remote parameter implementation. The returned object is always a Boolean instance.

Specified by:
get in interface Parameter

getTrigger

public Boolean getTrigger()
Returns the combined status of all open-roof switches as a Boolean.

Specified by:
getTrigger in interface Trigger

isTrue

public boolean isTrue()
Returns the combined status of all open-roof switches as a primitive boolean.

Specified by:
isTrue in interface Trigger

getLastToggleTime

public Date getLastToggleTime()
Returns the last toggle time of the weather.

Specified by:
getLastToggleTime in interface Trigger

getElapsedToggleTime

public long getElapsedToggleTime()
Returns elapsed time since last toggle event.

Specified by:
getElapsedToggleTime in interface Trigger

getFormatted

public String getFormatted()
Diverts to simple trigger.

Specified by:
getFormatted in interface Parameter

getString

public String getString()
Diverts to simple trigger.

Specified by:
getString in interface Parameter

set

public Object set(Object to)
Throws an unsupported exception.

Specified by:
set in interface Parameter
Returns:
The previous value of this parameter.

setTrigger

public Boolean setTrigger(Boolean to)
Throws an unsupported exception.

Specified by:
setTrigger in interface Trigger

toggleTrigger

public Boolean toggleTrigger()
Throws an unsupported exception.

Specified by:
toggleTrigger in interface Trigger

getStatus

public String getStatus()
                 throws RemoteException
Returns the status of the weather station. This is the remote-enabled method to AbstractWeatherSurveyor.status().

Specified by:
getStatus in interface RmiWeatherReporting
Throws:
RemoteException

provideStatus

public Object provideStatus()
Returns a detailed description of the weather status. This includes status from all registered telemetering instances.

Specified by:
provideStatus in interface StatusProviding

toString

public String toString()
Returns a very brief description of the weather station.

Overrides:
toString in class PropertyContainer

addRmiWeatherListener

public void addRmiWeatherListener(RmiWeatherListener add)
                           throws RemoteException
Adds a weather listener to this weather station. This class is also a RmiWeatherReporting instance, thus we notify all registering listeners about the current weather.

Specified by:
addRmiWeatherListener in interface RmiWeatherCaster
Throws:
RemoteException

removeRmiWeatherListener

public void removeRmiWeatherListener(RmiWeatherListener remove)
                              throws RemoteException
Removes a weather listener from this weather station.

Specified by:
removeRmiWeatherListener in interface RmiWeatherCaster
Throws:
RemoteException

notifyWeatherListener

protected void notifyWeatherListener(WeatherEvent we)
Notifies all registered WeatherListeners. This method parses through the Vector of WeatherListeners and passes the argument to their weatherChanged method. Additionally, this method sets the boolean trigger of the current weather condition to the value of the weather event's WeatherEvent.isGood() flag.

Overrides:
notifyWeatherListener in class AbstractWeatherSurveyor
Parameters:
we - The WeatherEvent to pass to the Listeners.