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
  • 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)