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 newReplicaState
with the provided state. -
Method Summary
Modifier and TypeMethodDescriptionstatic ReplicaState
Returns aReplicaState
from the provided JSON representation.Returns the CSN associated with the provided StreamId.Returns the StreamIds for each replica.boolean
isEmpty()
Returns if the streamId is empty.iterator()
Returns a pretty-printed string representation of thisReplicaState
.void
Purge the state by deleting streams (excepting the newest for each replica) which have an older CSN than the provided CSN.void
Adds a StreamId starting with the provided CSN to the state.void
putIfMoreRecent
(ReplicaState another) Updates the current state with all the StreamIds from the provided state.boolean
putIfMoreRecent
(CSN csn) Updates the current state with the provided CSN, creating the StreamId if necessary.void
retainOldestCsns
(ReplicaState other) Update this ServerState with the oldest CSN for each replica versus the provided ServerState.int
size()
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, toArray
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 newReplicaState
with 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:
isEmpty
in interfaceCollection<CSN>
- Overrides:
isEmpty
in classAbstractCollection<CSN>
- Returns:
- if the streamId is empty
-
iterator
- Specified by:
iterator
in interfaceCollection<CSN>
- Specified by:
iterator
in interfaceIterable<CSN>
- Specified by:
iterator
in classAbstractCollection<CSN>
-
streamIds
Returns the StreamIds in the state.- Returns:
- the StreamIds in the state
-
size
public int size()- Specified by:
size
in interfaceCollection<CSN>
- Specified by:
size
in 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 aReplicaState
from the provided JSON representation.- Parameters:
value
- the JSON string representation of theReplicaState
- Returns:
- a
ReplicaState
from the provided JSON representation
-
toString
- Overrides:
toString
in 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
-