Interface MultiClusterGigaSpace

All Superinterfaces:
AutoCloseable, GigaSpace
All Known Implementing Classes:
DefaultMultiClusterGigaSpace

public interface MultiClusterGigaSpace extends GigaSpace, AutoCloseable
A GigaSpace that fronts several already-deployed remote spaces - one per cluster / site - and redirects each operation to one or more of them according to the configured MultiClusterGigaSpace.WriteMode, MultiClusterGigaSpace.ReadMode and MultiClusterGigaSpace.FailoverPolicy.

Because it extends GigaSpace, application code does not change: whatever calls write / readMultiple / change / execute today keeps compiling and running. Only the bean or factory that produces the GigaSpace is swapped.

DefaultMultiClusterGigaSpace is the implementation: construct one directly when the clusters arrive at runtime or a framework needs a plain constructor, or build one through MultiClusterGigaSpaceConfigurer when the topology is known up front and should be validated. The interface is the contract defined by PIC-6085; getStats() and close() are the two additions.

Semantics worth knowing before using it

  • Fan-out modes are not a distributed transaction. Inside an active transaction the proxy falls back to the active cluster only (or fails, depending on the configured transaction policy) - there is no cross-cluster two-phase commit.
  • READ_ROUND_ROBIN reads are eventually consistent by construction: a read may land on a cluster that has not yet received the latest write. Read-your-writes requires MultiClusterGigaSpace.ReadMode.READ_ACTIVE.
  • Either the proxy fans mutations out, or a WAN Gateway replicates them - doing both applies each mutation twice.
  • Two inherited GigaSpace methods throw UnsupportedOperationException here, because what they return would be a live handle onto one cluster and every call on it would bypass the routing above: GigaSpace.getClustered() - use this proxy, or getCluster(String) when one cluster is what you want - and executorBuilder(...), whose builder is bound to the space that created it; use GigaSpace.execute(Task) instead, which is routed and honours the fan-out setting. Narrower handles - getSpace(), getTypeManager(), getTxProvider(), newDataEventSession() - are answered by the active cluster.

Implementations are thread-safe: registration, configuration and failover may run concurrently with space operations.

  • Method Details

    • registerCluster

      void registerCluster(String clusterName, GigaSpace spaceProxy)
      Registers a GigaSpace cluster proxy target under a named identifier. The first cluster registered becomes the active one unless an active cluster was already chosen.
      Throws:
      IllegalArgumentException - if the name is blank, already registered, or the same proxy instance is already registered under a different name
    • unregisterCluster

      void unregisterCluster(String clusterName)
      Unregisters a target cluster by name. If it was the active cluster, the next cluster in the priority list is promoted.
      Throws:
      IllegalArgumentException - if no cluster is registered under that name
    • unregisterCluster

      void unregisterCluster(GigaSpace spaceProxy)
      Unregisters a target cluster by its proxy instance.
    • setActiveCluster

      void setActiveCluster(String clusterName)
      Sets the primary active cluster by name. It takes the mutations and, with any read pin dropped, the MultiClusterGigaSpace.ReadMode.READ_ACTIVE reads too - reads and writes are back on one cluster.
      See Also:
    • setActiveCluster

      void setActiveCluster(GigaSpace spaceProxy)
      Sets the primary active cluster by direct instance reference.
    • getActiveClusterName

      String getActiveClusterName()
      Returns the name of the currently designated primary active cluster - the one taking mutations - or null if none.
    • getActiveCluster

      GigaSpace getActiveCluster()
      Returns the currently designated primary active GigaSpace proxy, or null if none.
    • setWriteActiveCluster

      void setWriteActiveCluster(String clusterName)
      Makes clusterName the write-active cluster: mutations, transactions, task execution and metadata calls go there. Unlike setActiveCluster(String) it leaves a pinned read cluster alone; with no pin, READ_ACTIVE reads follow the write role as usual.
      Throws:
      IllegalArgumentException - if no cluster is registered under that name
    • setReadActiveCluster

      void setReadActiveCluster(String clusterName)
      Pins MultiClusterGigaSpace.ReadMode.READ_ACTIVE reads to clusterName, separately from the cluster taking mutations - a dedicated read cluster and a dedicated write cluster.

      Reads served there see a write only once the WAN Gateway or a WRITE_SYNC fan-out has carried it over, so this gives up read-your-writes. Reads inside a transaction still go to the write-active cluster, where the transaction is. If the pinned cluster becomes unreachable the read role fails over on its own, to the next cluster in priority order that is not taking the writes, and the write role is left alone. MultiClusterGigaSpace.ReadMode.READ_ROUND_ROBIN reads ignore the pin.

      Throws:
      IllegalArgumentException - if no cluster is registered under that name
    • clearReadActiveCluster

      void clearReadActiveCluster()
      Drops the read pin, so READ_ACTIVE reads follow the write-active cluster again.
    • getReadActiveClusterName

      String getReadActiveClusterName()
      The cluster MultiClusterGigaSpace.ReadMode.READ_ACTIVE reads go to: the pinned read cluster, or the active cluster when nothing is pinned. null if there is neither.
    • getReadActiveCluster

      GigaSpace getReadActiveCluster()
      The proxy of the cluster getReadActiveClusterName() names, or null.
    • getRegisteredClusters

      Map<String, GigaSpace> getRegisteredClusters()
      Returns the registered clusters, keyed by name, in registration order.
    • getCluster

      GigaSpace getCluster(String clusterName)
      Resolves a GigaSpace proxy by its registered cluster name.
      Throws:
      IllegalArgumentException - if the name is not registered
    • getClusterName

      String getClusterName(GigaSpace spaceProxy)
      Resolves the registered cluster name for a given GigaSpace proxy instance.
      Throws:
      IllegalArgumentException - if the proxy is not registered
    • setWriteMode

      void setWriteMode(MultiClusterGigaSpace.WriteMode mode)
    • getWriteMode

    • setReadMode

      void setReadMode(MultiClusterGigaSpace.ReadMode mode)
    • getReadMode

    • setFailoverPolicy

      void setFailoverPolicy(MultiClusterGigaSpace.FailoverPolicy policy)
    • getFailoverPolicy

    • setClusterPriorityList

      void setClusterPriorityList(List<String> priorityNames)
      Sets the ordered fallback list of cluster names for automated promotion. Registered clusters missing from the list keep their registration order behind the listed ones.
      Throws:
      IllegalArgumentException - if a name is unknown or listed twice
    • getClusterPriorityList

      List<String> getClusterPriorityList()
      The order clusters will actually be promoted in: the configured priorities first, then any registered cluster the configuration omits, minus anything removed by removeClusterFromPriorityList(String) or dropped after a failure.

      It reports what failover will do rather than what was once configured - a cluster removed on failure is gone from this list, and one registered afterwards appears in it.

    • addClusterToPriorityList

      boolean addClusterToPriorityList(String clusterName)
      Makes a cluster a promotion candidate again, appended to the configured order if it was not in it.
      Returns:
      true if this call changed the list
    • removeClusterFromPriorityList

      boolean removeClusterFromPriorityList(String clusterName)
      Removes a cluster from failover promotion without unregistering it.

      A cluster removed this way is not silently re-appended by the fallback ordering, unlike one that was simply never listed - otherwise a cluster dropped after a failure would be re-elected by the next promotion.

      Returns:
      true if this call changed the list
    • getReadRotation

      List<String> getReadRotation()
      The clusters currently eligible for MultiClusterGigaSpace.ReadMode.READ_ROUND_ROBIN reads, in registration order.

      Registering a cluster puts it in the rotation. A failure takes it out - and leaves it out until this application decides it is ready, which is what addClusterToReadRotation(String) is for.

    • addClusterToReadRotation

      boolean addClusterToReadRotation(String clusterName)
      Puts a cluster back into round-robin reads after it was removed.
      Returns:
      true if this call changed the rotation
    • removeClusterFromReadRotation

      boolean removeClusterFromReadRotation(String clusterName)
      Takes a cluster out of round-robin reads. It stays registered, and stays usable as the active cluster: the rotation governs balanced reads only, so removing the active cluster from it does not stop reads reaching that cluster through MultiClusterGigaSpace.ReadMode.READ_ACTIVE.
      Returns:
      true if this call changed the rotation
    • setFailureThreshold

      void setFailureThreshold(int consecutiveFailuresThreshold)
      Sets the consecutive failure threshold required before marking a cluster unhealthy.
    • getFailureThreshold

      int getFailureThreshold()
      Returns the consecutive failure threshold.
    • setFailureWindow

      void setFailureWindow(Duration failureWindow)
      Defines the rolling window duration for error threshold evaluation.
    • getFailureWindow

      Duration getFailureWindow()
      Returns the rolling failure window.
    • isClusterHealthy

      boolean isClusterHealthy(String clusterName)
      Returns true if the cluster identified by name is reachable.
    • isClusterHealthy

      boolean isClusterHealthy(GigaSpace spaceProxy)
      Returns true if the specified GigaSpace cluster instance is reachable.
    • failoverToNextCluster

      void failoverToNextCluster()
      Forcefully triggers failover to the next healthy cluster in the priority list.
      Throws:
      NoAvailableClusterException - if no other cluster is healthy
    • addClusterStateListener

      void addClusterStateListener(MultiClusterGigaSpace.ClusterStateListener listener)
    • removeClusterStateListener

      void removeClusterStateListener(MultiClusterGigaSpace.ClusterStateListener listener)
    • addClusterEventListener

      void addClusterEventListener(ClusterEventListener listener)
      Registers a listener that receives the same events with an explicit ClusterEventType rather than the convention below.
    • removeClusterEventListener

      void removeClusterEventListener(ClusterEventListener listener)
    • getStats

      MultiClusterStats getStats()
      Per-cluster operation counters, failures and observed latency.
    • close

      void close()
      Releases the resources this proxy owns: background schedulers and the async write queue.

      Cluster proxies are never among them. Whether a cluster arrived as a GigaSpace or as a SpaceConfigurer the configurer built one from, it belongs to the application - close it yourself, the same way you would close the SpaceConfigurer behind a plain GigaSpace.

      Specified by:
      close in interface AutoCloseable