public class WeatherTrigger extends AbstractTrigger implements ParameterDepending, Refreshing, AfterRegistering, EventTrigger, StatusProviding
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.
PropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
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.
|
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWNKEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORCONFIG, KEY_CLASSKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME| Constructor and Description |
|---|
WeatherTrigger(Map<String,String> prop)
Constructs a new weather trigger.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterAll()
We start ourself after one refresh cycle and yell if
parameters are missing.
|
String |
conciseStatus() |
Object |
extendedStatus()
The status is a string version of the votes table.
|
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.
|
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.
|
get, getElapsedToggleTime, isTrue, set, toggleTriggercreateParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, overrideDefaultName, register, rescanned, setName, toStringclone, 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, setObject, setProperties, setProperty, stringPropertiesequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdefaultBoolean, 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_WEATHERLIST
public static final String KEY_WEATHERTABLE
public static final String KEY_REFRESH
public static final String KEY_GOODSTABLE
private static final long DEFREFRESH
private static final int DEFGOODSTABLE
private Date toggle
private Boolean good
private int goodcount
private Object sleeper
public void init()
throws InitException
init in interface Initializableinit in class AbstractParameterInitExceptionpublic void registerParameter(Parameter p)
registerParameter in interface ParameterDependingpublic void afterAll()
afterAll in interface AfterRegisteringpublic long getRefreshInterval()
getRefreshInterval in interface Refreshingpublic boolean isFixedRate()
isFixedRate in interface Refreshingpublic Boolean getTrigger()
getTrigger in interface Triggeringpublic Boolean setTrigger(Boolean no)
setTrigger in interface Triggeringpublic Date getLastToggleTime()
getLastToggleTime in interface Triggeringpublic void refresh()
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.refresh in interface Refreshingpublic Object extendedStatus()
extendedStatus in interface StatusProvidingpublic String conciseStatus()
conciseStatus in interface StatusProvidingpublic Object registerMonitor(Object waiter)
registerMonitor in interface EventTriggerprivate void notifyMonitor()