Class SessionState

java.lang.Object
com.couchbase.client.dcp.state.SessionState

public class SessionState extends Object
Holds the state information for the current session (all partitions involved).
Since:
1.0.0
Author:
Michael Nitschinger
  • Field Details

    • NO_END_SEQNO

      public static final long NO_END_SEQNO
      The highest possible sequence number, (2^64)-1. Sequence numbers must be interpreted as unsigned values. When comparing two sequence numbers to see which is greater, use Long.compareUnsigned.
      See Also:
    • CURRENT_VERSION

      public static final int CURRENT_VERSION
      The current version format used on export, respected on import to aid backwards compatibility.
      See Also:
  • Constructor Details

    • SessionState

      public SessionState()
      Initializes with an empty partition state for 1024 partitions.
  • Method Details

    • setToBeginningWithNoEnd

      public void setToBeginningWithNoEnd(int numPartitions)
      Initializes all partition states to start at the beginning (0) with no end.
      Parameters:
      numPartitions - the actual number of partitions used.
    • setFromJson

      public void setFromJson(byte[] persisted)
      Recovers the session state from persisted JSON.
      Parameters:
      persisted - the persisted JSON format.
    • get

      public PartitionState get(int partition)
      Accessor into the partition state, only use this if really needed.

      If you want to avoid going out of bounds, use the simpler iterator way on foreachPartition(Consumer).

      Parameters:
      partition - the index of the partition.
      Returns:
      the partition state for the given partition id.
    • set

      public void set(int partition, PartitionState partitionState)
      Accessor to set/override the current partition state, only use this if really needed.
      Parameters:
      partition - the index of the partition.
      partitionState - the partition state to override.
    • isAtEnd

      public boolean isAtEnd()
      Check if the current sequence numbers for all partitions are >= the ones set as end.
      Returns:
      true if all are at the end, false otherwise.
    • rollbackToPosition

      public void rollbackToPosition(int partition, long seqno)
      Helper method to rollback the given partition to the given sequence number.

      This will set the seqno AND REMOVE ALL ENTRIES from the failover log that are higher than the given sequence number!

      Parameters:
      partition - the partition to rollback
      seqno - the sequence number where to roll it back to.
    • foreachPartition

      public void foreachPartition(Consumer<PartitionState> action)
      Provides an iterator over all partitions, calling the callback for each one.
      Parameters:
      action - the action to be called with the state for every partition.
    • foreachPartition

      public void foreachPartition(BiConsumer<Integer,PartitionState> consumer)
    • export

      public byte[] export(StateFormat format)
      Export the PartitionState into the desired format.
      Parameters:
      format - the format in which the state should be exposed, always uses the current version.
      Returns:
      the exported format, depending on the type can be converted into a string by the user.
    • toString

      public String toString()
      Overrides:
      toString in class Object