Package nl.tue.id.oocsi.client.behavior

# Class OOCSIConsensus<T>

java.lang.Object
nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator<T>
nl.tue.id.oocsi.client.behavior.OOCSIConsensus<T>

    public class OOCSIConsensus<T>
    extends OOCSISystemCommunicator<T>

OOCSIConsensus is a system-level primitive that allows for easy consensus between different OOCSI clients on the same channel. The consensus will be about a single key or data item, for which different options are given to vote for. This realizes synchronization on data, not time for which we have OOCSISync.

Author:
  matsfunk

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator

  `OOCSISystemCommunicator.SystemFilter<K>`

- ## Field Summary

  ### Fields inherited from class nl.tue.id.oocsi.client.behavior.OOCSISystemCommunicator

  `channelName, client, HANDLE`

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `OOCSIConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` | create a new consensus process
  `OOCSIConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` | create a new consensus process with a callback that will be triggered when the consensus is reached

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `static OOCSIConsensus<java.lang.Boolean>` | `createBooleanConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` |
  `static OOCSIConsensus<java.lang.Boolean>` | `createBooleanConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` |
  `static OOCSIConsensus<java.lang.Float>` | `createFloatAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` |
  `static OOCSIConsensus<java.lang.Float>` | `createFloatAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` |
  `static OOCSIConsensus<java.lang.Integer>` | `createIntegerAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` |
  `static OOCSIConsensus<java.lang.Integer>` | `createIntegerAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` |
  `static OOCSIConsensus<java.lang.Integer>` | `createIntegerConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` | STATIC FACTORY METHODS
  `static OOCSIConsensus<java.lang.Integer>` | `createIntegerConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` |
  `static OOCSIConsensus<java.lang.String>` | `createStringConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)` |
  `static OOCSIConsensus<java.lang.String>` | `createStringConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)` |
  `T` | `get()` | returns the current consensus value or my last vote; attention: may return null in case no vote was given
  `T` | `get​(T defaultValue)` | returns the current consensus value or the default value if no consensus has been reached yet
  `protected T` | `getAggregate​(java.util.Map<java.lang.String,​T> votes)` | compute the aggregate of all votes (after all votes have been recorded, the aggregate function is used to compute a single result value; different implementations might be plugged into this depending on needs)
  `void` | `set​(T myVote)` | set my vote for the consensus process
  `void` | `stop()` |

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

- ## Constructor Details

  - ### OOCSIConsensus

    public OOCSIConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)
    create a new consensus process
    Parameters:
      `client` -
      `channelName` -
      `key` -
      `timeoutMS` -

  - ### OOCSIConsensus

    public OOCSIConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)
    create a new consensus process with a callback that will be triggered when the consensus is reached
    Parameters:
      `client` -
      `channelName` -
      `key` -
      `timeoutMS` -
      `handler` -

- ## Method Details

  - ### set

    public void set​(T myVote)
    set my vote for the consensus process
    Parameters:
      `myVote` -

  - ### get

    public T get()
    returns the current consensus value or my last vote; attention: may return null in case no vote was given
    Returns:

  - ### get

    public T get​(T defaultValue)
    returns the current consensus value or the default value if no consensus has been reached yet
    Parameters:
      `defaultValue` -
    Returns:

  - ### getAggregate

    protected T getAggregate​(java.util.Map<java.lang.String,​T> votes)
    compute the aggregate of all votes (after all votes have been recorded, the aggregate function is used to compute a single result value; different implementations might be plugged into this depending on needs)
    Parameters:
      `votes` -
    Returns:

  - ### stop

    public void stop()

  - ### createIntegerConsensus

    public static OOCSIConsensus<java.lang.Integer> createIntegerConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)
    STATIC FACTORY METHODS

  - ### createIntegerConsensus

    public static OOCSIConsensus<java.lang.Integer> createIntegerConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)

  - ### createIntegerAvgConsensus

    public static OOCSIConsensus<java.lang.Integer> createIntegerAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)

  - ### createIntegerAvgConsensus

    public static OOCSIConsensus<java.lang.Integer> createIntegerAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)

  - ### createFloatAvgConsensus

    public static OOCSIConsensus<java.lang.Float> createFloatAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)

  - ### createFloatAvgConsensus

    public static OOCSIConsensus<java.lang.Float> createFloatAvgConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)

  - ### createStringConsensus

    public static OOCSIConsensus<java.lang.String> createStringConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)

  - ### createStringConsensus

    public static OOCSIConsensus<java.lang.String> createStringConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)

  - ### createBooleanConsensus

    public static OOCSIConsensus<java.lang.Boolean> createBooleanConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS)

  - ### createBooleanConsensus

    public static OOCSIConsensus<java.lang.Boolean> createBooleanConsensus​(OOCSIClient client, java.lang.String channelName, java.lang.String key, int timeoutMS, Handler handler)