public class WeatherStation extends AbstractWeatherSurveyor implements WeatherPredicting, WeatherListener, RmiWeatherReporting, Initializable
WeatherSensors. Acts as a
weather event listener and weather event caster but considers a whole
bunch of weather sensors for generating only a single weather event.
This changes the behavior in a way that 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<java.lang.String, java.lang.String>) 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.
| Modifier and Type | Class and Description |
|---|---|
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. |
PropertyResources.Load, PropertyResources.URLResourceWeatherSurveying.DataBlock| Modifier and Type | Field and Description |
|---|---|
private Triggering |
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<Driver> |
drivers
A list of all weather drivers registered to the weather station.
|
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 Map<Telemetering,Boolean> |
lookup
The lookup table matching sensor to their votes.
|
private SensorRepository |
repository
A repository if the
KEY_REPOSITORY is set. |
private Vector<RmiWeatherListener> |
rmilist
The weather listeners to report to.
|
private Timer |
weathersensors
The timer where all weather sensors run.
|
ALTERNATEHOST, ALTERNATEPORT, KEY_BINDNAME, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORTKEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORNAMING_EXTENSIONCONFIG, KEY_CLASSKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME| Constructor and Description |
|---|
WeatherStation()
Constructs a new weather station.
|
WeatherStation(Map<String,String> qualify)
Constructs a new weather station.
|
| Modifier and Type | Method and Description |
|---|---|
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<String> |
allSensorNames()
Returns a collection of all sensors by name.
|
private boolean |
check()
Checks if all weather sensor report clear weather.
|
String |
conciseStatus() |
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 |
extendedStatus()
Returns a detailed description of the weather status.
|
Object |
get()
Serves the weather watching's remote parameter capability.
|
Collection<String> |
getAllSensorNames()
Returns a Collection of all running weather sensors.
|
Collection<Telemetering> |
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<String,Object> |
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.
|
void |
registerGlobals(GlobalGrouping set)
Registers a
GlobalGrouping 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.
|
addWeatherListener, createWeatherSurveyor, removeWeatherListener, statusbindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, getBindName, isValid, unbindFromRegistry, unbindFromRegistryclone, createFrom, createFrom, createFrom, createInstance, getApplet, getAsResources, getLocate, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, hasLocalURLs, initProperties, keyCreate, keyCreate, reload, setAppletaugment, augment, 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, parseObject, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringPropertiesequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbindToRegistry, isValid, unbindFromRegistrydefaultBoolean, 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, stringPropertiespublic static final String KEY_NAME
public static final String KEY_BIND
RmiWeatherCaster.public static final String KEY_DAEMON
public static final String KEY_LIST
public static final String KEY_FILE
public static final String KEY_DUMP
public static final String KEY_REPOSITORY
private static final String DEFFILE
private static final boolean DEFBIND
RmiWeatherCaster.private static final boolean DEFDAEMON
private SensorRepository repository
KEY_REPOSITORY is set.private List<Driver> drivers
private Timer weathersensors
private Map<Telemetering,Boolean> lookup
private WeatherEvent lastweather
private Triggering current
private Vector<RmiWeatherListener> rmilist
public WeatherStation()
throws RemoteException
RemoteExceptionpublic WeatherStation(Map<String,String> qualify)
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.
qualify - The properties of this weather station.public void init()
PropertySupplying.KEY_CLASS entry is used by the
factory
method AbstractSensor.createSensor(java.util.Map<java.lang.String, java.lang.String>) 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!.init in interface Initializablelist - of Files, holding all the weather sensor properties to
listen to.InitExceptionprivate Telemetering addFromFile(String prop)
private void crossRegister()
public void exit()
ExitCleaning
instances. If the KEY_DUMP property points to a file, the
exit values of all sensors are written into that file.exit in interface ExitCleaningexit in class AbstractRmiCasterpublic void registerSensorDriver(Driver drv)
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.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.registerSensorDriver in interface WeatherSurveyingpublic void startSensors()
startSensors in interface WeatherSurveyingpublic void registerGlobals(GlobalGrouping set)
GlobalGrouping 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.
registerGlobals in interface GlobalDependingpublic void weatherChanged(WeatherEvent we)
weatherChanged in interface WeatherListenerpublic WeatherEvent getCurrentWeather()
The weather event returned leaves its WeatherEvent.getReason()
undefined.
getCurrentWeather in interface WeatherSurveyingpublic int getCurrentlyRetarding()
getCurrentlyRetarding in interface WeatherSurveyingpublic long getRemainsBadMinimum()
WeatherJudging
instances, this method can return the
maximum of all WeatherJudging.getMinClearUpTime().getRemainsBadMinimum in interface WeatherPredictingpublic long getRemainsBadMaximum()
getRemainsBadMaximum in interface WeatherPredictingpublic long getRemainsGoodMinimum()
getRemainsGoodMinimum in interface WeatherPredictingpublic long getRemainsGoodMaximum()
getRemainsGoodMaximum in interface WeatherPredictingprivate boolean check()
This method notifies the weather listeners only on one occasion:
public Map<String,Object> getRemoteProperties() throws RemoteException
PropertyContainer.getProperties().getRemoteProperties in interface RmiPropertyBearinggetRemoteProperties in class RmiPropertyContainerRemoteExceptionpublic String getRemoteProperty(String key) throws RemoteException
PropertyContainer.getProperty(java.lang.String).getRemoteProperty in interface RmiPropertyBearinggetRemoteProperty in class RmiPropertyContainerkey - The key for the Map object.PropertyContainer.getProperty(java.lang.String) call.RemoteExceptionpublic String setRemoteProperty(String key, String val) throws RemoteException
PropertyContainer.setProperty(java.lang.String, java.lang.String).setRemoteProperty in interface RmiPropertyBearingsetRemoteProperty in class RmiPropertyContainerkey - The key for this Property.value - The value of this Property.RemoteExceptionpublic boolean containsRemoteProperty(String key) throws RemoteException
PropertyContainer.has(java.lang.String).containsRemoteProperty in interface RmiPropertyBearingcontainsRemoteProperty in class RmiPropertyContainerRemoteExceptionpublic Telemetering getSensor(String name)
WeatherSurveying interface.getSensor in interface WeatherSurveyingname - The unique name of the sensor.public Collection<Telemetering> getAllSensors()
WeatherSurveying interface.getAllSensors in interface WeatherSurveyingpublic RmiDataCaster getDataSensor(String name) throws RemoteException
getDataSensor in interface RmiWeatherReportingRemoteExceptionpublic Collection<String> getAllSensorNames() throws RemoteException
getAllSensorNames in interface RmiWeatherReportingRemoteExceptionprivate Collection<String> allSensorNames()
public boolean removeSensor(String name) throws RemoteException
removeSensor in interface RmiWeatherReportingRemoteExceptionpublic boolean addSensor(String properties) throws RemoteException
addSensor in interface RmiWeatherReportingproperties - The name of the properties file of the sensor.RemoteExceptionpublic String getName()
public Object get()
public Boolean getTrigger()
getTrigger in interface Triggeringpublic boolean isTrue()
isTrue in interface Triggeringpublic Date getLastToggleTime()
getLastToggleTime in interface Triggeringpublic long getElapsedToggleTime()
getElapsedToggleTime in interface Triggeringpublic String getFormatted()
getFormatted in interface Parameterpublic String getString()
public Boolean setTrigger(Boolean to)
setTrigger in interface Triggeringpublic Boolean toggleTrigger()
toggleTrigger in interface Triggeringpublic String getStatus() throws RemoteException
AbstractWeatherSurveyor.status().getStatus in interface RmiWeatherReportingRemoteExceptionpublic Object extendedStatus()
extendedStatus in interface StatusProvidingpublic String conciseStatus()
conciseStatus in interface StatusProvidingpublic String toString()
toString in class PropertyContainerpublic void addRmiWeatherListener(RmiWeatherListener add) throws RemoteException
RmiWeatherReporting instance, thus we notify all registering
listeners about the current weather.addRmiWeatherListener in interface RmiWeatherCasterRemoteExceptionpublic void removeRmiWeatherListener(RmiWeatherListener remove) throws RemoteException
removeRmiWeatherListener in interface RmiWeatherCasterRemoteExceptionprotected void notifyWeatherListener(WeatherEvent we)
WeatherEvent.isGood() flag.notifyWeatherListener in class AbstractWeatherSurveyorwe - The WeatherEvent to pass to the Listeners.