Class ClusterState

java.lang.Object
com.loomcache.common.model.ClusterState

public final class ClusterState extends Object
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.

  • Constructor Details

    • ClusterState

      public ClusterState()
  • Method Details

    • operationalState

      public ClusterState.OperationalState operationalState()
      Return the current cluster operational state.
    • clusterVersion

      public LoomVersion clusterVersion()
      Return the cluster protocol/version gate used for rolling-upgrade ceremonies.
    • changeClusterVersion

      public LoomVersion changeClusterVersion(LoomVersion newVersion)
      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

      public void addMember(NodeInfo node)
      Add a member to the cluster state.
      Parameters:
      node - the node to add (must not be null)
      Throws:
      IllegalArgumentException - if node is null
    • removeMember

      public void removeMember(String nodeId)
      Remove a member from the cluster state.
      Parameters:
      nodeId - the node ID to remove (must not be null)
    • getMember

      public @Nullable NodeInfo getMember(String nodeId)
      Get a member by node ID.
      Parameters:
      nodeId - the node ID to look up (must not be null)
      Returns:
      the NodeInfo or null if not found
    • allMembers

      public Collection<NodeInfo> allMembers()
      Get all members (alive and dead).
      Returns:
      an unmodifiable collection of all members
    • aliveMembers

      public Collection<NodeInfo> 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

      public boolean containsMember(String nodeId)
      Check if a member exists.
      Parameters:
      nodeId - the node ID to check (must not be null)
      Returns:
      true if the member exists
    • markDead

      public void markDead(String nodeId)
      Mark a member as dead (atomic replacement via copy-on-write).
      Parameters:
      nodeId - the node ID to mark (must not be null)
    • markAlive

      public void markAlive(String nodeId)
      Mark a member as alive (atomic replacement via copy-on-write).
      Parameters:
      nodeId - the node ID to mark (must not be null)