Class MultiClusterRouter
java.lang.Object
org.openspaces.core.multicluster.internal.MultiClusterRouter
- All Implemented Interfaces:
AutoCloseable
The router. Every space operation performed on a
DefaultMultiClusterGigaSpace arrives here as a
Function that applies it to one cluster, together with the OperationKind that says what
the operation does, and is dispatched accordingly.
Dispatch by entry point:
diagnostic(String, Function)- fanned out to every cluster and concatenated;read(String, Function)- sent to the cluster the configuredReadSelectorpicks from the clusters that are currently available; aREAD_ACTIVEread goes to the read-active cluster - the pinned read cluster, or the active one when nothing is pinned - and if that cluster is unreachable the read role moves first, since the read has nowhere else to go;mutate(OperationKind, String, boolean, Function)- placed by the configuredWriteExecutor: the active cluster only, every cluster synchronously, or the active cluster now and the rest in the background;execute(String, boolean, Function)- a mutation that carries arbitrary code, fanned out only whenfanOutTasksallows it and the task is not durable;local(String, Function)- the active cluster, so metadata stays consistent with the cluster mutations are applied to.
Transactions pin everything to one cluster
A transaction belongs to one space, and there is no cross-cluster transaction manager. A balanced read or a fanned-out mutation issued inside a transaction would escape it - atomic on one cluster, unprotected on the others. So while a transaction is open, both reads and mutations go to the active cluster;TransactionPolicy.STRICT makes the proxy refuse the operation instead, for callers who
would rather fail than get a partly-protected write.
No reflection
The caller supplies the call as a lambda already bound to the exact overload it wants, so the space's own exception reaches the caller unwrapped and every operation is resolved by javac rather than by name at runtime. The write executors still declareThrowable, so anything that is neither a
RuntimeException nor an Error - which no GigaSpace method declares - is wrapped
in a MultiClusterAccessException rather than thrown undeclared.
Thread-safe: registration, configuration and failover may run concurrently with space operations.
-
Constructor Summary
ConstructorsConstructorDescriptionMultiClusterRouter(MultiClusterSetup setup, ClusterAvailability availability, boolean monitorHealth) Builds the router and, unless availability is supplied from outside, starts monitoring cluster health. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()control()The control surface: the multi-cluster API's own methods.Mutations still owed to clusters that could not take them yet.describe()How the proxy describes itself: the topology, the modes, and whether it is still open.diagnostic(String operation, Function<GigaSpace, ?> call) Diagnostics describe the whole proxy, so they are collected from every cluster and concatenated.<R> RRoutes code execution.voidRegisters the JMX bean once the proxy instance exists - the bean's operations act on the proxy, so it cannot be built before the proxy it manages.The health monitor, ornullwhen availability was supplied from outside.<R> RRoutes a space-local operation to the active cluster, so metadata stays consistent with the cluster mutations are applied to.<R> Rmutate(OperationKind kind, String operation, boolean async, Function<GigaSpace, R> call) Places a mutation according to the write mode, with three overrides that take precedence over it: an open transaction, an asynchronous operation, and atakethat matched nothing.name()The proxy's name, used in JMX and log lines.<R> RRoutes a read to the cluster the configured selector picks.stats()Per-cluster counters, failures and observed latency.
-
Constructor Details
-
MultiClusterRouter
public MultiClusterRouter(MultiClusterSetup setup, ClusterAvailability availability, boolean monitorHealth) Builds the router and, unless availability is supplied from outside, starts monitoring cluster health.- Parameters:
setup- the validated topology and configurationavailability- where availability answers come from whenmonitorHealthis falsemonitorHealth- whether to run the health-tracking and failover machinery
-
-
Method Details
-
describe
How the proxy describes itself: the topology, the modes, and whether it is still open. -
diagnostic
Diagnostics describe the whole proxy, so they are collected from every cluster and concatenated. A cluster that cannot answer contributes nothing rather than failing the call - a diagnostic query should survive a partial outage, which is exactly when it is asked. -
read
Routes a read to the cluster the configured selector picks. Unavailable clusters are filtered out first, so no selector has to reason about health.One rule comes before the read mode: a read inside a transaction goes to the active cluster. A transaction is started on the active cluster and its uncommitted writes exist only there, so a read served by any other cluster would not see them - the caller would write an entry and then fail to read it back in the same transaction.
-
mutate
public <R> R mutate(OperationKind kind, String operation, boolean async, Function<GigaSpace, R> call) Places a mutation according to the write mode, with three overrides that take precedence over it: an open transaction, an asynchronous operation, and atakethat matched nothing.- Parameters:
kind- what the operation does - decides result merging and take-miss handlingasync- whether the operation returns a future rather than a value
-
execute
Routes code execution. Durable-task methods are never fanned out: their ids are issued by one cluster, so a task registered on one and executed on another is a different task. PlainexecutefollowsfanOutTasks, which is off by default because a task is arbitrary code that may not be idempotent. -
local
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
exposeOverJmx
Registers the JMX bean once the proxy instance exists - the bean's operations act on the proxy, so it cannot be built before the proxy it manages. -
name
The proxy's name, used in JMX and log lines. -
control
The control surface: the multi-cluster API's own methods. -
stats
Per-cluster counters, failures and observed latency. -
healthMonitor
The health monitor, ornullwhen availability was supplied from outside. -
deferredMutations
Mutations still owed to clusters that could not take them yet.
-