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 key
  `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)
  `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
  `OOCSIVariable​(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 setting
  `void` | `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 well
  `void` | `disconnect​(OOCSIVariable<T> forward)` | disconnect the given variable from this variable; no more events will be sent
  `protected T` | `extractValue​(OOCSIEvent event, java.lang.String key)` | safely extract the message value in the right type
  `protected 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 client
  `OOCSIVariable<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 value
  `OOCSIVariable<T>` | `limit​(int rate, int seconds)` | set the limiting of incoming events in terms of "rate" and "seconds" timeframe; supports chained invocation
  `void` | `localUpdate()` | notifier for a local variable update; override to get notified about this
  `OOCSIVariable<T>` | `max​(T max)` | set the maximum value for (upper-)bounded variable (also possible during operation); supports chained invocation
  `OOCSIVariable<T>` | `min​(T min)` | set the minimum value for (lower-)bounded variable (also possible during operation); supports chained invocation
  `T` | `reference()` | retrieve the reference value
  `OOCSIVariable<T>` | `reference​(T reference)` | set the reference value (also possible during operation); supports chained invocation
  `void` | `remoteUpdate()` | notifier for a remote variable update (from another client); override to get notified about this
  `void` | `set()` | update the setting of the variable, but only if it is different from the reference value; and then let the channel know
  `void` | `set​(T var)` | set the variable and, if successful, let the channel know
  `OOCSIVariable<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 invocation
  `OOCSIVariable<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 invocation
  `void` | `update()` | notifier for a variable update; override to get notified about this

  ### Methods 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

    protected T min

  - ### max

    protected T max

  - ### sigma

    protected T sigma

  - ### mean

    protected T mean

  - ### values

    protected java.util.concurrent.ArrayBlockingQueue<T> values

  - ### windowLength

    protected int windowLength

  - ### lastInput

    protected T lastInput

  - ### forwarders

    protected java.util.List<OOCSIVariable<T>> forwarders

- ## Constructor Details

  - ### OOCSIVariable

    public OOCSIVariable​(OOCSIClient client, java.lang.String channelName, java.lang.String key)
    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

    public OOCSIVariable​(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
    Parameters:
      `referenceValue` -
      `timeout` -

- ## Method Details

  - ### get

    public 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)
    Returns:

  - ### set

    public void set​(T var)
    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

    protected T extractValue​(OOCSIEvent event, java.lang.String key)
    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

    protected 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)
    Parameters:
      `var` -
    Returns:

  - ### adapt

    protected T adapt​(T var)
    adaptation of the variable based on the recent history (values) and the newly entered variable setting
    Parameters:
      `var` -
    Returns:

  - ### reference

    public T 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

    public T last()
    retrieve the last input value
    Returns:

  - ### reference

    public OOCSIVariable<T> reference​(T reference)
    set the reference value (also possible during operation); supports chained invocation
    Parameters:
      `reference` -
    Returns:

  - ### timeout

    public OOCSIVariable<T> timeout​(int timeoutMS)
    set the timeout in milliseconds (also possible during operation); supports chained invocation
    Parameters:
      `timeoutMS` -
    Returns:

  - ### limit

    public OOCSIVariable<T> limit​(int rate, int seconds)
    set the limiting of incoming events in terms of "rate" and "seconds" timeframe; supports chained invocation
    Parameters:
      `rate` -
      `seconds` -
    Returns:

  - ### min

    public OOCSIVariable<T> min​(T min)
    set the minimum value for (lower-)bounded variable (also possible during operation); supports chained invocation
    Parameters:
      `min` -
    Returns:

  - ### max

    public OOCSIVariable<T> max​(T max)
    set the maximum value for (upper-)bounded variable (also possible during operation); supports chained invocation
    Parameters:
      `max` -
    Returns:

  - ### smooth

    public OOCSIVariable<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 invocation
    Parameters:
      `windowLength` -
    Returns:

  - ### smooth

    public OOCSIVariable<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. the parameter sigma sets the upper bound for the standard deviation protected variable
    Parameters:
      `windowLength` -
      `sigma` -
    Returns:

  - ### generator

    public OOCSIVariable<T> generator​(long periodMS)
    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

    public void 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 well
    Parameters:
      `forward` -

  - ### disconnect

    public void disconnect​(OOCSIVariable<T> forward)
    disconnect the given variable from this variable; no more events will be sent
    Parameters:
      `forward` -