Package com.couchbase.client.dcp.state
Class SessionState
java.lang.Object
com.couchbase.client.dcp.state.SessionState
Holds the state information for the current session (all partitions involved).
- Since:
- 1.0.0
- Author:
- Michael Nitschinger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe current version format used on export, respected on import to aid backwards compatibility.static final longThe highest possible sequence number,(2^64)-1. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes with an empty partition state for 1024 partitions. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]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.voidforeachPartition(BiConsumer<Integer, PartitionState> consumer) voidforeachPartition(Consumer<PartitionState> action) 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.booleanisAtEnd()Check if the current sequence numbers for all partitions are >= the ones set as end.voidrollbackToPosition(int partition, long seqno) Helper method to rollback the given partition to the given sequence number.voidset(int partition, PartitionState partitionState) Accessor to set/override the current partition state, only use this if really needed.voidsetFromJson(byte[] persisted) Recovers the session state from persisted JSON.voidsetToBeginningWithNoEnd(int numPartitions) Initializes all partition states to start at the beginning (0) with no end.toString()
-
Field Details
-
NO_END_SEQNO
public static final long NO_END_SEQNOThe 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, useLong.compareUnsigned.- See Also:
-
CURRENT_VERSION
public static final int CURRENT_VERSIONThe 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
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
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 rollbackseqno- the sequence number where to roll it back to.
-
foreachPartition
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
-
export
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 usingClient.resumeStreaming(Map).Export thePartitionStateinto 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
-