stella.parameter
Class WeatherTrigger

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.AbstractTrigger
                      extended by stella.parameter.WeatherTrigger
All Implemented Interfaces:
Cloneable, EventListener, EventTrigger, Parameter, AfterRegistering, ParameterDepending, Trigger, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, Refreshing, ResourceSupplying, StatusProviding

public class WeatherTrigger
extends AbstractTrigger
implements ParameterDepending, Refreshing, AfterRegistering, EventTrigger, StatusProviding

A weather trigger takes a list of SensorValues, named according to KEY_WEATHERLIST. In principle it is also possible to incorporate any Value, both mostly readings from wether sensor will be used. In KEY_WEATHERTABLE, each of these names is coupled to two values, a minimum and a maximum. If the minimum is lower than the maximum, the allowed data range for this sensor is between min/max, if ordered such that the first value is higher than the second, the allowed range is outside min/max. The trigger is updated every KEY_REFRESH ms - make this number not too small, otherwise you will link to identical data events from the sensors. Toggling from good (=true) weather to bad always occurs immediately, toggling from bad to good is only effective, if stable for at least KEY_GOODSTABLE refresh cycles. Toggle times are always counted from true toggles, i.e. the toggling to good might be prolonged.

To allow immediate notification of bad weather event, this class also implements the EventTrigger interface.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Map<String,Boolean> absent
          For logging to avoid flooding.
private static int DEFGOODSTABLE
          Per default we toggle immediately.
private static long DEFREFRESH
          The default refresh interval.
private  Boolean good
          The current vote.
private  int goodcount
          Count consecuetive godds after a bad.
static String KEY_GOODSTABLE
          The required refresh intervals to toggle from bad to good.
static String KEY_REFRESH
          The refreshing intervall in ms.
static String KEY_WEATHERLIST
          Points to the list of data values we depend our vote on.
static String KEY_WEATHERTABLE
          Points to the min/max pairs for the allowed range of the sensors.
private  Map<String,Vector2D> minmax
          The mapping of names to their min/max.
private  List<String> sensors
          This are the parameters we need to register to.
private  Object sleeper
          This object is notified in case of weather changes.
private  Date toggle
          The time we realized a weather toggle.
private  Map<String,Value> weather
          The mapping of value names to the Value objects.
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
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
WeatherTrigger(Map<String,String> prop)
          Constructs a new weather trigger.
 
Method Summary
 void afterAll()
          We start ourself after one refresh cycle and yell if parameters are missing.
 Date getLastToggleTime()
          Returns the last toggle time or null, if weather has never toggled.
 long getRefreshInterval()
          Our refresh interval.
 Boolean getTrigger()
          Returns the current weather vote.
private  Map<String,Boolean> getVotes()
          We go through the list of all sesnors and derive a vote for each.
 void init()
          On init, we create the parameter list we register to and initialize the minmax table.
 boolean isFixedRate()
          False.
private  void notifyMonitor()
          The weather has changed.
 Object provideStatus()
          The status is a string version of the votes table.
 void refresh()
          On refresh, we check all registered values if their reading are in the appropriate range.
 Object registerMonitor(Object waiter)
          Sets or unsets the monitor to receive weather changes.
 void registerParameter(Parameter p)
          Registers a parameter.
 Boolean setTrigger(Boolean no)
          This is not allowed.
 
Methods inherited from class stella.parameter.AbstractTrigger
get, getElapsedToggleTime, isTrue, set, toggleTrigger
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, rescanned, setName, toString
 
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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface stella.Parameter
get, getFormatted, getName, getString, set
 
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_WEATHERLIST

public static final String KEY_WEATHERLIST
Points to the list of data values we depend our vote on.

See Also:
Constant Field Values

KEY_WEATHERTABLE

public static final String KEY_WEATHERTABLE
Points to the min/max pairs for the allowed range of the sensors.

See Also:
Constant Field Values

KEY_REFRESH

public static final String KEY_REFRESH
The refreshing intervall in ms.

See Also:
Constant Field Values

KEY_GOODSTABLE

public static final String KEY_GOODSTABLE
The required refresh intervals to toggle from bad to good.

See Also:
Constant Field Values

DEFREFRESH

private static final long DEFREFRESH
The default refresh interval.

See Also:
Constant Field Values

DEFGOODSTABLE

private static final int DEFGOODSTABLE
Per default we toggle immediately.

See Also:
Constant Field Values

sensors

private List<String> sensors
This are the parameters we need to register to.


weather

private Map<String,Value> weather
The mapping of value names to the Value objects.


absent

private Map<String,Boolean> absent
For logging to avoid flooding.


minmax

private Map<String,Vector2D> minmax
The mapping of names to their min/max.


toggle

private Date toggle
The time we realized a weather toggle.


good

private Boolean good
The current vote.


goodcount

private int goodcount
Count consecuetive godds after a bad.


sleeper

private Object sleeper
This object is notified in case of weather changes.

Constructor Detail

WeatherTrigger

public WeatherTrigger(Map<String,String> prop)
Constructs a new weather trigger. Fails if the list or the table is not set.

Method Detail

init

public void init()
On init, we create the parameter list we register to and initialize the minmax table. If the value pair denoting min max is in order max min, the good intervall is outside.

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

registerParameter

public void registerParameter(Parameter p)
Registers a parameter. If the parameter is a value and found in our names list, we keep a reference. After all parameters have been registered, we check, if all have shown up.

Specified by:
registerParameter in interface ParameterDepending

afterAll

public void afterAll()
We start ourself after one refresh cycle and yell if parameters are missing. The delayed start should help registered parameters to attain a correct value.

Specified by:
afterAll in interface AfterRegistering

getRefreshInterval

public long getRefreshInterval()
Our refresh interval.

Specified by:
getRefreshInterval in interface Refreshing

isFixedRate

public boolean isFixedRate()
False.

Specified by:
isFixedRate in interface Refreshing
See Also:
Timer

getTrigger

public Boolean getTrigger()
Returns the current weather vote. If called before the first refresh, null is returned.

Specified by:
getTrigger in interface Trigger

setTrigger

public Boolean setTrigger(Boolean no)
This is not allowed.

Specified by:
setTrigger in interface Trigger

getLastToggleTime

public Date getLastToggleTime()
Returns the last toggle time or null, if weather has never toggled.

Specified by:
getLastToggleTime in interface Trigger

refresh

public void refresh()
On refresh, we check all registered values if their reading are in the appropriate range. Non-valid sensor are ignored. Changes from good to bad are notified immediately, from bad to good only if good stays at good for at least KEY_GOODSTABLE, which in the default implementation is also immediate. If no object has been registered to receive notification events, the current state of the weather might still be ascertainable by a getTrigger() call.

Specified by:
refresh in interface Refreshing

provideStatus

public Object provideStatus()
The status is a string version of the votes table.

Specified by:
provideStatus in interface StatusProviding

registerMonitor

public Object registerMonitor(Object waiter)
Sets or unsets the monitor to receive weather changes.

Specified by:
registerMonitor in interface EventTrigger

notifyMonitor

private void notifyMonitor()
The weather has changed. We record the time and notify possible sleepers


getVotes

private Map<String,Boolean> getVotes()
We go through the list of all sesnors and derive a vote for each. Null values return a null vote, otherwise true for good, false for bad.