Class ClusterState
java.lang.Object
com.loomcache.common.model.ClusterState
Snapshot of the cluster state: all known members + their liveness.
Exchanged between nodes during discovery and membership updates.
Thread safety: uses ConcurrentHashMap for member storage.
Individual operations (add, remove, get, markDead) are atomic.
Compound operations like aliveMembers() return a point-in-time
snapshot — member status may change during stream evaluation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumCluster-wide operational state. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true when client write operations may be accepted.voidAdd a member to the cluster state.intGet the number of alive members.Get all alive members.Get all members (alive and dead).booleanReturns true when partition ownership may be rebalanced through migration.changeClusterVersion(LoomVersion newVersion) Change the cluster version and return the previous version.Return the cluster protocol/version gate used for rolling-upgrade ceremonies.booleancontainsMember(String nodeId) Check if a member exists.@Nullable NodeInfoGet a member by node ID.booleanisEmpty()Returns true if the cluster state has no members.booleanReturns true when the cluster is in NO_MIGRATION mode.booleanReturns true when the cluster is in PASSIVE read-only mode.voidMark a member as alive (atomic replacement via copy-on-write).voidMark a member as dead (atomic replacement via copy-on-write).Return the current cluster operational state.voidremoveMember(String nodeId) Remove a member from the cluster state.intsize()Get the total number of members.transitionTo(ClusterState.OperationalState newState) Transition the cluster operational state and return the previous state.
-
Constructor Details
-
ClusterState
public ClusterState()
-
-
Method Details
-
operationalState
Return the current cluster operational state. -
clusterVersion
Return the cluster protocol/version gate used for rolling-upgrade ceremonies. -
changeClusterVersion
Change the cluster version and return the previous version. -
transitionTo
Transition the cluster operational state and return the previous state. -
isPassive
public boolean isPassive()Returns true when the cluster is in PASSIVE read-only mode. -
isNoMigration
public boolean isNoMigration()Returns true when the cluster is in NO_MIGRATION mode. -
acceptsWrites
public boolean acceptsWrites()Returns true when client write operations may be accepted. -
allowsMigrations
public boolean allowsMigrations()Returns true when partition ownership may be rebalanced through migration. -
addMember
Add a member to the cluster state.- Parameters:
node- the node to add (must not be null)- Throws:
IllegalArgumentException- if node is null
-
removeMember
Remove a member from the cluster state.- Parameters:
nodeId- the node ID to remove (must not be null)
-
getMember
-
allMembers
Get all members (alive and dead).- Returns:
- an unmodifiable collection of all members
-
aliveMembers
Get all alive members.- Returns:
- a list of alive members (snapshot at call time)
-
isEmpty
public boolean isEmpty()Returns true if the cluster state has no members.- Returns:
- true if empty
-
size
public int size()Get the total number of members.- Returns:
- total member count
-
aliveCount
public int aliveCount()Get the number of alive members.- Returns:
- count of alive members
-
containsMember
Check if a member exists.- Parameters:
nodeId- the node ID to check (must not be null)- Returns:
- true if the member exists
-
markDead
Mark a member as dead (atomic replacement via copy-on-write).- Parameters:
nodeId- the node ID to mark (must not be null)
-
markAlive
Mark a member as alive (atomic replacement via copy-on-write).- Parameters:
nodeId- the node ID to mark (must not be null)
-