Class ClusterRegistry
java.lang.Object
org.openspaces.core.multicluster.internal.ClusterRegistry
The proxy's topology: which clusters are registered, which one is active, and in what order they take
over.
Why copy-on-write
Every space operation reads this state, and it changes rarely - on registration and on failover. So the whole topology lives in one immutableClusterRegistry.Snapshot behind an AtomicReference: readers take a
snapshot with a single volatile read and never lock, and a reader can never observe a half-applied
change (for example an active cluster that has just been unregistered).
Mutations are compare-and-set retry loops over a pure transform, so concurrent registration and failover cannot lose an update.
Identity, not equality
Reverse lookup (proxy -> name) uses an IdentityHashMap: GigaSpace
implementations do not define equals, and two proxies to the same space are legitimately
different targets. Registering the same instance twice under different names is therefore rejected -
it would make nameOf(GigaSpace) ambiguous and silently skew fan-out counts.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne registered cluster.static final classAn immutable view of the topology. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddToPriorityList(String name) Makes a cluster a promotion candidate again, appended to the configured priority order.booleanaddToReadRotation(String name) Puts a cluster back into round-robin reads.Drops the read pin, soREAD_ACTIVEreads follow the active cluster again.booleancompareAndSetActive(String expectedActive, String newActive) Atomically promotesexpectedActivetonewActive, failing if another thread changed the active cluster first.booleancompareAndSetReadActive(String expectedPin, String newPin) Atomically moves the read pin fromexpectedPintonewPin(nulldrops it), failing if another thread moved it first.Resolves a proxy by cluster name.Resolves the cluster name of a proxy instance.Convenience for a proxy registered without topology metadata.register(ClusterRegistry.Cluster cluster) Registers a cluster.booleanremoveFromPriorityList(String name) Removes a cluster from failover promotion, without unregistering it.booleanremoveFromReadRotation(String name) Takes a cluster out of round-robin reads, leaving it registered and usable as the active cluster.Makesnamethe active cluster for both reads and writes, dropping any read pin.Makes the cluster behind this proxy instance active.voidsetPriorityList(List<String> names) Sets the failover priority order.setReadActive(String name) PinsREAD_ACTIVEreads toname, leaving the active cluster taking writes.setWriteActive(String name) Makesnamethe active cluster for writes only.snapshot()The current topology.toString()unregister(String name) Removes a cluster by name.unregister(GigaSpace proxy) Removes a cluster by proxy instance.
-
Constructor Details
-
ClusterRegistry
public ClusterRegistry()
-
-
Method Details
-
snapshot
The current topology. One volatile read; safe to hold for the duration of an operation. -
register
Registers a cluster. The first cluster registered becomes active, so a single-cluster proxy needs no further wiring.- Returns:
- the snapshot after registration
- Throws:
IllegalArgumentException- if the name is taken, or this proxy instance is already registered
-
register
Convenience for a proxy registered without topology metadata. -
unregister
Removes a cluster by name. If it was active, the next cluster inClusterRegistry.Snapshot.failoverOrder()is promoted; if it was the last one, the registry is left with no active cluster.- Returns:
- the removed cluster
- Throws:
IllegalArgumentException- if the name is not registered
-
unregister
Removes a cluster by proxy instance. -
setActive
Makesnamethe active cluster for both reads and writes, dropping any read pin.- Returns:
- the previously active cluster, or
nullif there was none - Throws:
IllegalArgumentException- if the name is not registered
-
setWriteActive
Makesnamethe active cluster for writes only. A pinned read cluster keeps servingREAD_ACTIVEreads; without a pin, reads follow the write role as usual.- Returns:
- the previously active cluster, or
nullif there was none - Throws:
IllegalArgumentException- if the name is not registered
-
setReadActive
PinsREAD_ACTIVEreads toname, leaving the active cluster taking writes. Pinning the active cluster itself is allowed and keeps reads there even after the write role moves.- Returns:
- the cluster that served
READ_ACTIVEreads before, ornullif there was none - Throws:
IllegalArgumentException- if the name is not registered
-
clearReadActive
Drops the read pin, soREAD_ACTIVEreads follow the active cluster again.- Returns:
- the cluster that served
READ_ACTIVEreads before, ornullif there was none
-
compareAndSetReadActive
Atomically moves the read pin fromexpectedPintonewPin(nulldrops it), failing if another thread moved it first. Single-flight for the read role, exactly ascompareAndSetActive(String, String)is for the write role.- Returns:
trueif this call moved the pin
-
setActive
Makes the cluster behind this proxy instance active. -
compareAndSetActive
Atomically promotesexpectedActivetonewActive, failing if another thread changed the active cluster first. This is how failover stays single-flight: concurrent failures produce one promotion, not one per failing operation.- Returns:
trueif this call performed the promotion
-
setPriorityList
-
addToReadRotation
Puts a cluster back into round-robin reads.Recovery notifies; it does not re-add. A cluster the application took out after a failure - or that
WRITE_SYNCunregistered - comes back when the application says so, not when it starts answering pings again.- Returns:
trueif this call changed the rotation
-
removeFromReadRotation
Takes a cluster out of round-robin reads, leaving it registered and usable as the active cluster. -
addToPriorityList
Makes a cluster a promotion candidate again, appended to the configured priority order. -
removeFromPriorityList
Removes a cluster from failover promotion, without unregistering it. -
get
-
nameOf
-
toString
-