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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The current version format used on export, respected on import to aid backwards compatibility.
    static final long
    The highest possible sequence number, (2^64)-1.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes with an empty partition state for 1024 partitions.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Deprecated.
    This method of recovering state does not account for whether an event received by the DCP client was actually processed by the user's application.
    void
     
    void
    Provides an iterator over all partitions, calling the callback for each one.
    get(int partition)
    Accessor into the partition state, only use this if really needed.
    boolean
    Check if the current sequence numbers for all partitions are >= the ones set as end.
    void
    rollbackToPosition(int partition, long seqno)
    Helper method to rollback the given partition to the given sequence number.
    void
    set(int partition, PartitionState partitionState)
    Accessor to set/override the current partition state, only use this if really needed.
    void
    setFromJson(byte[] persisted)
    Recovers the session state from persisted JSON.
    void
    setToBeginningWithNoEnd(int numPartitions)
    Initializes all partition states to start at the beginning (0) with no end.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      @Deprecated public byte[] export(StateFormat format)
      Deprecated.
      This method of recovering state does not account for whether an event received by the DCP client was actually processed by the user's application. This can cause the application to resume from the wrong point, silently skipping some events. Instead, an application should track its own state, and resume using Client.resumeStreaming(Map).
      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