Class MultiClusterRouter

java.lang.Object
org.openspaces.core.multicluster.internal.MultiClusterRouter
All Implemented Interfaces:
AutoCloseable

public final class MultiClusterRouter extends Object implements 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:

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 declare Throwable, 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 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 configuration
      availability - where availability answers come from when monitorHealth is false
      monitorHealth - whether to run the health-tracking and failover machinery
  • Method Details

    • describe

      public String describe()
      How the proxy describes itself: the topology, the modes, and whether it is still open.
    • diagnostic

      public List<Object> diagnostic(String operation, Function<GigaSpace, ?> call)
      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

      public <R> R read(String operation, Function<GigaSpace, R> call)
      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 a take that matched nothing.
      Parameters:
      kind - what the operation does - decides result merging and take-miss handling
      async - whether the operation returns a future rather than a value
    • execute

      public <R> R execute(String operation, boolean durable, Function<GigaSpace, R> call)
      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. Plain execute follows fanOutTasks, which is off by default because a task is arbitrary code that may not be idempotent.
    • local

      public <R> R local(String operation, Function<GigaSpace, R> call)
      Routes a space-local operation to the active cluster, so metadata stays consistent with the cluster mutations are applied to.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • exposeOverJmx

      public void exposeOverJmx(MultiClusterGigaSpace proxy)
      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

      public String name()
      The proxy's name, used in JMX and log lines.
    • control

      public MultiClusterControlSupport control()
      The control surface: the multi-cluster API's own methods.
    • stats

      public MultiClusterStatsRecorder stats()
      Per-cluster counters, failures and observed latency.
    • healthMonitor

      public HealthMonitor healthMonitor()
      The health monitor, or null when availability was supplied from outside.
    • deferredMutations

      public DeferredMutations deferredMutations()
      Mutations still owed to clusters that could not take them yet.