Class ReplicaState
- All Implemented Interfaces:
Iterable<CSN>,Collection<CSN>
The replication state of a replica.
The state is defined as a list of StreamIds.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new emptyReplicaState.ReplicaState(ReplicaState state) Creates a newReplicaStatewith the provided state. -
Method Summary
Modifier and TypeMethodDescriptionstatic ReplicaStateReturns aReplicaStatefrom the provided JSON representation.Returns the CSN associated with the provided StreamId.Returns the StreamIds for each replica.booleanisEmpty()Returns if the streamId is empty.iterator()Returns a pretty-printed string representation of thisReplicaState.voidPurge the state by deleting streams (excepting the newest for each replica) which have an older CSN than the provided CSN.voidAdds a StreamId starting with the provided CSN to the state.voidputIfMoreRecent(ReplicaState another) Updates the current state with all the StreamIds from the provided state.booleanputIfMoreRecent(CSN csn) Updates the current state with the provided CSN, creating the StreamId if necessary.voidretainOldestCsns(ReplicaState other) Update this ServerState with the oldest CSN for each replica versus the provided ServerState.intsize()Returns the StreamIds in the state.toJson()Returns the JSON representation of thisReplicaState.toJsonSimplified(Topology.DomainState domainState) Returns the simplified JSON representation of thisReplicaState.toString()Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
ReplicaState
public ReplicaState()Creates a new emptyReplicaState. -
ReplicaState
Creates a newReplicaStatewith the provided state.- Parameters:
state- the state
-
-
Method Details
-
get
Returns the CSN associated with the provided StreamId.- Parameters:
streamId- the streamId- Returns:
- the CSN associated with the provided StreamId
-
isEmpty
public boolean isEmpty()Returns if the streamId is empty.- Specified by:
isEmptyin interfaceCollection<CSN>- Overrides:
isEmptyin classAbstractCollection<CSN>- Returns:
- if the streamId is empty
-
iterator
- Specified by:
iteratorin interfaceCollection<CSN>- Specified by:
iteratorin interfaceIterable<CSN>- Specified by:
iteratorin classAbstractCollection<CSN>
-
streamIds
Returns the StreamIds in the state.- Returns:
- the StreamIds in the state
-
size
public int size()- Specified by:
sizein interfaceCollection<CSN>- Specified by:
sizein classAbstractCollection<CSN>
-
put
Adds a StreamId starting with the provided CSN to the state.- Parameters:
csn- the CSN starting the Stream
-
putIfMoreRecent
Updates the current state with all the StreamIds from the provided state.- Parameters:
another- the state to update from
-
putIfMoreRecent
Updates the current state with the provided CSN, creating the StreamId if necessary.- Parameters:
csn- the update CSN- Returns:
- if the StreamId was updated
-
getStreamsByReplicaId
Returns the StreamIds for each replica.- Returns:
- the StreamIds for each replica
-
toJson
Returns the JSON representation of thisReplicaState.- Returns:
- the JSON representation of this
ReplicaState
-
toJsonSimplified
Returns the simplified JSON representation of thisReplicaState.- Parameters:
domainState- the domain state- Returns:
- the simplified JSON representation of this
ReplicaState
-
fromJson
Returns aReplicaStatefrom the provided JSON representation.- Parameters:
value- the JSON string representation of theReplicaState- Returns:
- a
ReplicaStatefrom the provided JSON representation
-
toString
- Overrides:
toStringin classAbstractCollection<CSN>
-
prettyPrint
Returns a pretty-printed string representation of thisReplicaState.- Returns:
- a pretty-printed string representation of this
ReplicaState
-
retainOldestCsns
Update this ServerState with the oldest CSN for each replica versus the provided ServerState. If a replica is not present in the other ServerState, it will be removed from this ServerState.- Parameters:
other- The other ServerState
-
purge
Purge the state by deleting streams (excepting the newest for each replica) which have an older CSN than the provided CSN.- Parameters:
purgeCsn- the CSN to purge fromcallingReplicaId- the replica calling the purge
-