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 TypeMethodDescriptionbooleanstatic ReplicaStateReturns aReplicaStatefrom the provided JSON representation.Returns the CSN associated with the provided StreamId.Returns the StreamIds for each replica.inthashCode()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.toString()Methods inherited from class AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface Collection
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
-
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
-
streamIds
-
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
-
toJson
Returns the JSON representation of thisReplicaState.- Returns:
- the 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
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Csn>- Overrides:
hashCodein classObject
-
equals
-