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.
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCluster(String clusterName, GigaSpace spaceProxy) Registers a cluster proxy bean; the container owns it, the multi-cluster proxy will not close it.voidaddCluster(String clusterName, SpaceConfigurer spaceConfigurer) Registers a cluster by itsSpaceConfigurer; the proxy for it is built withnew GigaSpaceConfigurer(spaceConfigurer).gigaSpace().voidaddCluster(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.voidvoiddestroy()Closes the proxy with the context: its write executors and deferred queue.Class<?> booleanprotected MultiClusterGigaSpaceConfigurerPicks 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.voidsetActiveCluster(String activeCluster) voidsetClusterPriority(List<String> clusterPriority) voidsetClusters(Map<String, GigaSpace> clusters) Registers several cluster proxy beans at once.voidsetConfigurer(MultiClusterGigaSpaceConfigurer configurer) Uses a configurer built elsewhere as the starting point.voidsetFailoverPolicy(MultiClusterGigaSpace.FailoverPolicy failoverPolicy) voidsetFailureThreshold(int failureThreshold) voidsetFailureWindow(Duration failureWindow) voidsetJmx(boolean jmx) Whether to expose this proxy over JMX.voidvoidsetProperties(Properties properties) Applies the modes and per-cluster topology metadata from properties; seeMultiClusterPropertiesfor the schema.voidsetProxyFactory(Function<MultiClusterSetup, ? extends MultiClusterGigaSpace> proxyFactory) Builds a custom proxy, typically a subclass ofDefaultMultiClusterGigaSpace, instead of the default one.voidsetQuiescePolicy(QuiescePolicy quiescePolicy) voidsetReadActiveCluster(String readActiveCluster) PinsREAD_ACTIVEreads to a cluster other than the active one.voidsetReadMode(MultiClusterGigaSpace.ReadMode readMode) voidsetRequiredSuccessCount(int requiredSuccessCount) voidsetSpaceConfigurers(Map<String, SpaceConfigurer> spaceConfigurers) Registers several clusters by theirSpaceConfigurerbeans at once.voidsetTransactionPolicy(TransactionPolicy transactionPolicy) voidsetWriteMode(MultiClusterGigaSpace.WriteMode writeMode)
-
Constructor Details
-
MultiClusterGigaSpaceFactoryBean
public MultiClusterGigaSpaceFactoryBean()
-
-
Method Details
-
addCluster
-
setClusters
-
addCluster
Registers a cluster by itsSpaceConfigurer; the proxy for it is built withnew GigaSpaceConfigurer(spaceConfigurer).gigaSpace(). The configurer bean stays the container's to close. -
setSpaceConfigurers
Registers several clusters by theirSpaceConfigurerbeans at once. -
addCluster
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
-
setReadActiveCluster
PinsREAD_ACTIVEreads to a cluster other than the active one. -
setClusterPriority
-
setProperties
Applies the modes and per-cluster topology metadata from properties; seeMultiClusterPropertiesfor the schema. The cluster proxies still come from the container - the file names the clusters, the context supplies them. -
setConfigurer
Uses a configurer built elsewhere as the starting point. -
setName
-
setWriteMode
-
setReadMode
-
setFailoverPolicy
-
setTransactionPolicy
-
setQuiescePolicy
-
setFailureThreshold
public void setFailureThreshold(int failureThreshold) -
setFailureWindow
-
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 ofDefaultMultiClusterGigaSpace, instead of the default one.- See Also:
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
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
- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<MultiClusterGigaSpace>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.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:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-