Class MultiClusterGigaSpaceFactoryBean

java.lang.Object
org.openspaces.core.multicluster.MultiClusterGigaSpaceFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>, org.springframework.beans.factory.InitializingBean

public class MultiClusterGigaSpaceFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Spring wiring for the proxy: a FactoryBean that produces a MultiClusterGigaSpace and closes it with the context.

The lifecycle matters more than the convenience. A proxy owns its write executors and a deferred-mutation queue; leaving those to garbage collection leaks threads for the life of the JVM. Implementing DisposableBean means the container closes it exactly when it closes everything else. Cluster proxies are not the proxy's to close - the container owns those beans.

Three ways to configure it

// 1. cluster beans you already have (the PIC-6085 example, in Spring form)
@Bean(destroyMethod = "")
MultiClusterGigaSpaceFactoryBean multiCluster(GigaSpace clusterEast, GigaSpace clusterWest) {
    MultiClusterGigaSpaceFactoryBean factory = new MultiClusterGigaSpaceFactoryBean();
    factory.addCluster("us-east", clusterEast);
    factory.addCluster("us-west", clusterWest);
    factory.setActiveCluster("us-east");
    factory.setClusterPriority(List.of("us-east", "us-west"));
    factory.setWriteMode(WriteMode.WRITE_SYNC);
    factory.setReadMode(ReadMode.READ_ROUND_ROBIN);
    factory.setFailoverPolicy(FailoverPolicy.AUTO_FAILOVER_NEXT_AVAILABLE);
    return factory;
}

// 2. cluster beans plus the modes from properties, so they change without a rebuild
@Bean
MultiClusterGigaSpaceFactoryBean multiCluster(GigaSpace east, GigaSpace west,
                                              @Value("${...}") Properties config) {
    MultiClusterGigaSpaceFactoryBean factory = new MultiClusterGigaSpaceFactoryBean();
    factory.setClusters(Map.of("us-east", east, "us-west", west));
    factory.setProperties(config);
    return factory;
}

// 3. hand it a configurer you built yourself
factory.setConfigurer(new MultiClusterGigaSpaceConfigurer()...);

Properties and explicit setters compose: the properties are applied first, then anything set explicitly overrides them - which is what a deployment usually wants, a file for the modes and code for the exceptions.

  • Constructor Details

    • MultiClusterGigaSpaceFactoryBean

      public MultiClusterGigaSpaceFactoryBean()
  • Method Details

    • addCluster

      public void addCluster(String clusterName, GigaSpace spaceProxy)
      Registers a cluster proxy bean; the container owns it, the multi-cluster proxy will not close it.
    • setClusters

      public void setClusters(Map<String, GigaSpace> clusters)
      Registers several cluster proxy beans at once.
    • addCluster

      public void addCluster(String clusterName, SpaceConfigurer spaceConfigurer)
      Registers a cluster by its SpaceConfigurer; the proxy for it is built with new GigaSpaceConfigurer(spaceConfigurer).gigaSpace(). The configurer bean stays the container's to close.
    • setSpaceConfigurers

      public void setSpaceConfigurers(Map<String, SpaceConfigurer> spaceConfigurers)
      Registers several clusters by their SpaceConfigurer beans at once.
    • addCluster

      public void addCluster(ClusterDescriptor descriptor, GigaSpace spaceProxy)
      Registers a cluster proxy bean together with the descriptor that says where it is, so the topology and weighted balancing have something to work with.
    • setActiveCluster

      public void setActiveCluster(String activeCluster)
    • setReadActiveCluster

      public void setReadActiveCluster(String readActiveCluster)
      Pins READ_ACTIVE reads to a cluster other than the active one.
    • setClusterPriority

      public void setClusterPriority(List<String> clusterPriority)
    • setProperties

      public void setProperties(Properties properties)
      Applies the modes and per-cluster topology metadata from properties; see MultiClusterProperties for the schema. The cluster proxies still come from the container - the file names the clusters, the context supplies them.
    • setConfigurer

      public void setConfigurer(MultiClusterGigaSpaceConfigurer configurer)
      Uses a configurer built elsewhere as the starting point.
    • setName

      public void setName(String name)
    • setWriteMode

      public void setWriteMode(MultiClusterGigaSpace.WriteMode writeMode)
    • setReadMode

      public void setReadMode(MultiClusterGigaSpace.ReadMode readMode)
    • setFailoverPolicy

      public void setFailoverPolicy(MultiClusterGigaSpace.FailoverPolicy failoverPolicy)
    • setTransactionPolicy

      public void setTransactionPolicy(TransactionPolicy transactionPolicy)
    • setQuiescePolicy

      public void setQuiescePolicy(QuiescePolicy quiescePolicy)
    • setFailureThreshold

      public void setFailureThreshold(int failureThreshold)
    • setFailureWindow

      public void setFailureWindow(Duration failureWindow)
    • setRequiredSuccessCount

      public void setRequiredSuccessCount(int requiredSuccessCount)
    • setJmx

      public void setJmx(boolean jmx)
      Whether to expose this proxy over JMX.
    • setProxyFactory

      public void setProxyFactory(Function<MultiClusterSetup, ? extends MultiClusterGigaSpace> proxyFactory)
      Builds a custom proxy, typically a subclass of DefaultMultiClusterGigaSpace, instead of the default one.
      See Also:
      • MultiClusterGigaSpaceConfigurer.proxyFactory
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • resolveConfigurer

      protected MultiClusterGigaSpaceConfigurer resolveConfigurer()
      Picks the starting configurer: one supplied explicitly, one built from properties around the container's cluster proxies, or an empty one the cluster beans are registered on. Override it to start from a configurer of your own; the explicit bean settings are still applied on top.
    • getObject

      public MultiClusterGigaSpace getObject()
      Specified by:
      getObject in interface org.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>
    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>
    • isSingleton

      public boolean isSingleton()
      Specified by:
      isSingleton in interface org.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>
    • destroy

      public void destroy()
      Closes the proxy with the context: its write executors and deferred queue. Cluster proxies are container beans and are left alone.
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean