Package nl.tue.id.oocsi.client.data
Class OOCSIVariable<T>
java.lang.Object
nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator<T>
nl.tue.id.oocsi.client.data.OOCSIVariable<T>
- Type Parameters:
T
-
- Direct Known Subclasses:
OOCSIBoolean
,OOCSIDouble
,OOCSIFloat
,OOCSIInt
,OOCSILong
,OOCSIString
public class OOCSIVariable<T> extends OOCSISystemCommunicator<T>
OOCSIVariable is a system-level primitive that allows for automatic synchronizing of local variables (read and write)
with different OOCSI clients on the same channel. This realizes synchronization on a single data variable without
aggregation. OOCSIVariable is a parameterized class, that means, once the data type is set it can reliably used in
reading and writing.
OOCSIVariable supports internal aggregation in the form of smoothing (use smooth(n) for n sample window length). The
range of the variable can be restricted by using an upper or lower bound or both. When smoothing, a mean-deviation
parameter sigma can be added to filter out outliers in the input data.
- Author:
- matsfunk
-
Nested Class Summary
Nested classes/interfaces inherited from class nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator
OOCSISystemCommunicator.SystemFilter<K>
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<OOCSIVariable<T>>
forwarders
protected T
lastInput
protected T
max
protected T
mean
protected T
min
protected T
sigma
protected java.util.concurrent.ArrayBlockingQueue<T>
values
protected int
windowLength
Fields inherited from class nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator
channelName, client, HANDLE
-
Constructor Summary
Constructors Constructor Description OOCSIVariable(OOCSIClient client, java.lang.String channelName, java.lang.String key)
Constructor for a simple OOCSI variable to sync on a given channel and keyOOCSIVariable(OOCSIClient client, java.lang.String channelName, java.lang.String key, T referenceValue)
Constructor for a simple OOCSI variable to sync on a given channel and key, in case no value can be retrieved from the channel a reference value is provided which will be set automatically after a timeout of 2000 ms (2 seconds)OOCSIVariable(OOCSIClient client, java.lang.String channelName, java.lang.String key, T referenceValue, int timeout)
Constructor for a simple OOCSI variable to sync on a given channel and key, in case no value can be retrieved from the channel a reference value is provided which will be set automatically after the given timeoutOOCSIVariable(T referenceValue, int timeout)
Constructor for a local OOCSI variable that does not sync on a given channel and key, a reference value is provided which will be set automatically after the given timeout -
Method Summary
Modifier and Type Method Description protected T
adapt(T var)
adaptation of the variable based on the recent history (values) and the newly entered variable settingvoid
connect(OOCSIVariable<T> forward)
connect the given variable to this variable, so whenever this variable is set, the connected given variable will be set as wellvoid
disconnect(OOCSIVariable<T> forward)
disconnect the given variable from this variable; no more events will be sentprotected T
extractValue(OOCSIEvent event, java.lang.String key)
safely extract the message value in the right typeprotected T
filter(T var)
filter the newly entered variable setting (if variable type is numerical, this could be a min/max filter and additional filtering based on the standard deviation, or a different filter)long
fresh()
retrieve the number of milliseconds that have passed since the last setting of the variable by another OOCSI clientOOCSIVariable<T>
generator(long periodMS)
creates a periodic feedback loop that feed either the last input value or the reference value into the variable (locally).OOCSIVariable<T>
generator(long periodMS, java.lang.String outputChannel, java.lang.String outputKey)
creates a periodic feedback loop that feed either the last input value or the reference value into the variable (locally).T
get()
retrieve the current value of the variable (will check for expiration if a timeout is given; in this case the reference value is set)T
last()
retrieve the last input valueOOCSIVariable<T>
limit(int rate, int seconds)
set the limiting of incoming events in terms of "rate" and "seconds" timeframe; supports chained invocationvoid
localUpdate()
notifier for a local variable update; override to get notified about thisOOCSIVariable<T>
max(T max)
set the maximum value for (upper-)bounded variable (also possible during operation); supports chained invocationOOCSIVariable<T>
min(T min)
set the minimum value for (lower-)bounded variable (also possible during operation); supports chained invocationT
reference()
retrieve the reference valueOOCSIVariable<T>
reference(T reference)
set the reference value (also possible during operation); supports chained invocationvoid
remoteUpdate()
notifier for a remote variable update (from another client); override to get notified about thisvoid
set()
update the setting of the variable, but only if it is different from the reference value; and then let the channel knowvoid
set(T var)
set the variable and, if successful, let the channel knowOOCSIVariable<T>
smooth(int windowLength)
set the length of the smoothing window, i.e., the buffer of historical values of this variable (also possible during operation, however, this will reset the buffer); supports chained invocationOOCSIVariable<T>
smooth(int windowLength, T sigma)
set the length of the smoothing window, i.e., the buffer of historical values of this variable (also possible during operation, however, this will reset the buffer); supports chained invocation.OOCSIVariable<T>
timeout(int timeoutMS)
set the timeout in milliseconds (also possible during operation); supports chained invocationvoid
update()
notifier for a variable update; override to get notified about thisMethods inherited from class nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator
addFilter, getHandle, message, message, message, subscribe, triggerHandler, updateFilter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
min
-
max
-
sigma
-
mean
-
values
-
windowLength
protected int windowLength -
lastInput
-
forwarders
-
-
Constructor Details
-
OOCSIVariable
Constructor for a simple OOCSI variable to sync on a given channel and key- Parameters:
client
-channelName
-key
-
-
OOCSIVariable
public OOCSIVariable(OOCSIClient client, java.lang.String channelName, java.lang.String key, T referenceValue)Constructor for a simple OOCSI variable to sync on a given channel and key, in case no value can be retrieved from the channel a reference value is provided which will be set automatically after a timeout of 2000 ms (2 seconds)- Parameters:
client
-channelName
-key
-referenceValue
-
-
OOCSIVariable
public OOCSIVariable(OOCSIClient client, java.lang.String channelName, java.lang.String key, T referenceValue, int timeout)Constructor for a simple OOCSI variable to sync on a given channel and key, in case no value can be retrieved from the channel a reference value is provided which will be set automatically after the given timeout- Parameters:
client
-channelName
-key
-referenceValue
-timeout
-
-
OOCSIVariable
Constructor for a local OOCSI variable that does not sync on a given channel and key, a reference value is provided which will be set automatically after the given timeout- Parameters:
referenceValue
-timeout
-
-
-
Method Details
-
get
retrieve the current value of the variable (will check for expiration if a timeout is given; in this case the reference value is set)- Returns:
-
set
set the variable and, if successful, let the channel know- Parameters:
var
-
-
set
public void set()update the setting of the variable, but only if it is different from the reference value; and then let the channel know -
extractValue
safely extract the message value in the right type- Parameters:
event
-- Returns:
-
update
public void update()notifier for a variable update; override to get notified about this -
remoteUpdate
public void remoteUpdate()notifier for a remote variable update (from another client); override to get notified about this -
localUpdate
public void localUpdate()notifier for a local variable update; override to get notified about this -
filter
filter the newly entered variable setting (if variable type is numerical, this could be a min/max filter and additional filtering based on the standard deviation, or a different filter)- Parameters:
var
-- Returns:
-
adapt
adaptation of the variable based on the recent history (values) and the newly entered variable setting- Parameters:
var
-- Returns:
-
reference
retrieve the reference value- Returns:
-
fresh
public long fresh()retrieve the number of milliseconds that have passed since the last setting of the variable by another OOCSI client- Returns:
-
last
retrieve the last input value- Returns:
-
reference
set the reference value (also possible during operation); supports chained invocation- Parameters:
reference
-- Returns:
-
timeout
set the timeout in milliseconds (also possible during operation); supports chained invocation- Parameters:
timeoutMS
-- Returns:
-
limit
set the limiting of incoming events in terms of "rate" and "seconds" timeframe; supports chained invocation- Parameters:
rate
-seconds
-- Returns:
-
min
set the minimum value for (lower-)bounded variable (also possible during operation); supports chained invocation- Parameters:
min
-- Returns:
-
max
set the maximum value for (upper-)bounded variable (also possible during operation); supports chained invocation- Parameters:
max
-- Returns:
-
smooth
set the length of the smoothing window, i.e., the buffer of historical values of this variable (also possible during operation, however, this will reset the buffer); supports chained invocation- Parameters:
windowLength
-- Returns:
-
smooth
set the length of the smoothing window, i.e., the buffer of historical values of this variable (also possible during operation, however, this will reset the buffer); supports chained invocation. the parameter sigma sets the upper bound for the standard deviation protected variable- Parameters:
windowLength
-sigma
-- Returns:
-
generator
creates a periodic feedback loop that feed either the last input value or the reference value into the variable (locally). If there is no reference value set, the former applies. The period is given in milliseconds.- Parameters:
periodMS
-- Returns:
-
generator
public OOCSIVariable<T> generator(long periodMS, java.lang.String outputChannel, java.lang.String outputKey)creates a periodic feedback loop that feed either the last input value or the reference value into the variable (locally). If there is no reference value set, the former applies. The period is given in milliseconds. In addition, the new value of the variable is sent out to the channel "outputChannel" with the given key "outputKey"- Parameters:
periodMS
-outputChannel
-outputKey
-- Returns:
-
connect
connect the given variable to this variable, so whenever this variable is set, the connected given variable will be set as well- Parameters:
forward
-
-
disconnect
disconnect the given variable from this variable; no more events will be sent- Parameters:
forward
-
-