diff --git a/pom.xml b/pom.xml
index 1e7b251d..d1788b32 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
org.springframework.data
spring-data-geode
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.0.DATAGEODE-100-SNAPSHOT
Spring Data Geode
diff --git a/src/main/asciidoc/reference/bootstrap-annotations.adoc b/src/main/asciidoc/reference/bootstrap-annotations.adoc
index 8187beeb..af512b4c 100644
--- a/src/main/asciidoc/reference/bootstrap-annotations.adoc
+++ b/src/main/asciidoc/reference/bootstrap-annotations.adoc
@@ -350,17 +350,17 @@ Building on our examples above, the client's `application.properties` would defi
[source, java]
----
spring.data.gemfire.cache.log-level=info
-spring.data.gemfire.pool.venus.servers=venus[48484]
-spring.data.gemfire.pool.venus.max-connections=200
-spring.data.gemfire.pool.venus.min-connections=50
-spring.data.gemfire.pool.venus.ping-interval=15000
-spring.data.gemfire.pool.venus.pr-single-hop-enabled=true
-spring.data.gemfire.pool.venus.read-timeout=20000
-spring.data.gemfire.pool.venus.subscription-enabled=true
-spring.data.gemfire.pool.saturn.locators=skullbox[20668]
-spring.data.gemfire.pool.saturn.subscription-enabled=true
-spring.data.gemfire.pool.neptune.servers=saturn[41414],neptune[42424]
-spring.data.gemfire.pool.neptune.min-connections=25
+spring.data.gemfire.pool.Venus.servers=venus[48484]
+spring.data.gemfire.pool.Venus.max-connections=200
+spring.data.gemfire.pool.Venus.min-connections=50
+spring.data.gemfire.pool.Venus.ping-interval=15000
+spring.data.gemfire.pool.Venus.pr-single-hop-enabled=true
+spring.data.gemfire.pool.Venus.read-timeout=20000
+spring.data.gemfire.pool.Venus.subscription-enabled=true
+spring.data.gemfire.pool.Saturn.locators=skullbox[20668]
+spring.data.gemfire.pool.Saturn.subscription-enabled=true
+spring.data.gemfire.pool.Neptune.servers=saturn[41414],neptune[42424]
+spring.data.gemfire.pool.Neptune.min-connections=25
----
And, the server's application.properties would define...
@@ -383,9 +383,9 @@ Then, we can simplify the `@ClientCacheApplication` class to...
@SpringBootApplication
@ClientCacheApplication
@EnablePools(pools = {
- @EnablePool(name = "VenusPool"),
- @EnablePool(name = "SaturnPool"),
- @EnablePool(name = "NeptunePool")
+ @EnablePool(name = "Venus"),
+ @EnablePool(name = "Saturn"),
+ @EnablePool(name = "Neptune")
})
class ClientApplication { .. }
----
diff --git a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
index d9b6352f..1239bb80 100644
--- a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
@@ -29,8 +29,8 @@ import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newR
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -72,12 +72,13 @@ import org.springframework.util.StringUtils;
* Spring {@link FactoryBean} used to construct, configure and initialize a Pivotal GemFire/Apache Geode
* {@link Cache peer cache).
*
- * Allows either retrieval of an existing, opened {@link Cache} or creation of a new {@link Cache}.
+ * Allows either retrieval of an existing, open {@link Cache} or creation of a new {@link Cache}.
*
* This class implements the {@link PersistenceExceptionTranslator} interface and is auto-detected by Spring's
* {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor} for AOP-based translation
- * of native persistent store exceptions to Spring's {@link DataAccessException} hierarchy. Therefore, the presence
- * of this class automatically enables a {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}
+ * of native persistent data store exceptions to Spring's {@link DataAccessException} hierarchy. Therefore, the presence
+ * of this class automatically enables a
+ * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}
* to translate Pivotal GemFire/Apache Geode exceptions appropriately.
*
* @author Costin Leau
@@ -119,10 +120,10 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
private Boolean pdxReadSerialized;
private Boolean useClusterConfiguration;
- private GemFireCache cache;
-
private CacheFactoryInitializer> cacheFactoryInitializer;
+ private GemFireCache cache;
+
private DynamicRegionSupport dynamicRegionSupport;
private Float criticalHeapPercentage;
@@ -139,7 +140,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
private Integer messageSyncInterval;
private Integer searchTimeout;
- private List peerCacheConfigurers = Collections.emptyList();
+ private List peerCacheConfigurers = new ArrayList<>();
private List jndiDataSources;
@@ -165,13 +166,65 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
*
* @throws Exception if initialization fails.
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+ * @see #applyCacheConfigurers()
* @see #initBeanFactoryLocator()
- * @see #postProcessBeforeCacheInitialization(Properties)
*/
@Override
public void afterPropertiesSet() throws Exception {
+ applyCacheConfigurers();
initBeanFactoryLocator();
- postProcessBeforeCacheInitialization(resolveProperties());
+ }
+
+ /**
+ * Applies the composite {@link PeerCacheConfigurer PeerCacheConfigurers} to this {@link CacheFactoryBean}
+ * before creating the {@link Cache peer Cache}.
+ *
+ * @see #getCompositePeerCacheConfigurer()
+ * @see #applyPeerCacheConfigurers(PeerCacheConfigurer...)
+ */
+ protected void applyCacheConfigurers() {
+
+ PeerCacheConfigurer autoReconnectClusterConfigurationConfigurer = (beanName, cacheFactoryBean) -> {
+
+ Properties gemfireProperties = resolveProperties();
+
+ gemfireProperties.setProperty("disable-auto-reconnect",
+ String.valueOf(!Boolean.TRUE.equals(getEnableAutoReconnect())));
+
+ gemfireProperties.setProperty("use-cluster-configuration",
+ String.valueOf(Boolean.TRUE.equals(getUseClusterConfiguration())));
+ };
+
+ this.peerCacheConfigurers.add(autoReconnectClusterConfigurationConfigurer);
+
+ applyPeerCacheConfigurers(getCompositePeerCacheConfigurer());
+ }
+
+ /**
+ * Applies the given array of {@link PeerCacheConfigurer PeerCacheConfigurers} to this {@link CacheFactoryBean}.
+ *
+ * @param peerCacheConfigurers array of {@link PeerCacheConfigurer PeerCacheConfigurers} applied to
+ * this {@link CacheFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
+ * @see #applyPeerCacheConfigurers(Iterable)
+ */
+ protected void applyPeerCacheConfigurers(PeerCacheConfigurer... peerCacheConfigurers) {
+ applyPeerCacheConfigurers(Arrays.asList(nullSafeArray(peerCacheConfigurers, PeerCacheConfigurer.class)));
+ }
+
+ /**
+ * Applies the given {@link Iterable} of {@link PeerCacheConfigurer PeerCacheConfigurers}
+ * to this {@link CacheFactoryBean}.
+ *
+ * @param peerCacheConfigurers {@link Iterable} of {@link PeerCacheConfigurer PeerCacheConfigurers}
+ * applied to this {@link CacheFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
+ * @see java.lang.Iterable
+ * @see #applyPeerCacheConfigurers(PeerCacheConfigurer...)
+ */
+ protected void applyPeerCacheConfigurers(Iterable peerCacheConfigurers) {
+ stream(nullSafeIterable(peerCacheConfigurers).spliterator(), false)
+ .forEach(clientCacheConfigurer -> clientCacheConfigurer.configure(getBeanName(), this));
}
/**
@@ -184,64 +237,13 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @see #getBeanFactory()
* @see #getBeanName()
*/
- private void initBeanFactoryLocator() {
- if (isUseBeanFactoryLocator() && getBeanFactoryLocator() == null) {
+ void initBeanFactoryLocator() {
+
+ if (isUseBeanFactoryLocator() && this.beanFactoryLocator == null) {
this.beanFactoryLocator = newBeanFactoryLocator(getBeanFactory(), getBeanName());
}
}
- /**
- * Post processes this {@link CacheFactoryBean} before cache initialization.
- *
- * This is also the point at which any configured {@link PeerCacheConfigurer} beans are called.
- *
- * @param gemfireProperties {@link Properties} used to configure Pivotal GemFire/Apache Geode.
- * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
- * @see java.util.Properties
- */
- protected void postProcessBeforeCacheInitialization(Properties gemfireProperties) {
-
- gemfireProperties.setProperty("disable-auto-reconnect", String.valueOf(
- !Boolean.TRUE.equals(getEnableAutoReconnect())));
-
- gemfireProperties.setProperty("use-cluster-configuration", String.valueOf(
- Boolean.TRUE.equals(getUseClusterConfiguration())));
-
- applyPeerCacheConfigurers();
- }
-
- /* (non-Javadoc) */
- private void applyPeerCacheConfigurers() {
- applyPeerCacheConfigurers(getCompositePeerCacheConfigurer());
- }
-
- /**
- * Null-safe operation to apply the given array of {@link PeerCacheConfigurer PeerCacheConfigurers}
- * to this {@link CacheFactoryBean}.
- *
- * @param peerCacheConfigurers array of {@link PeerCacheConfigurer PeerCacheConfigurers} applied to
- * this {@link CacheFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
- * @see #applyPeerCacheConfigurers(Iterable)
- */
- protected void applyPeerCacheConfigurers(PeerCacheConfigurer... peerCacheConfigurers) {
- applyPeerCacheConfigurers(Arrays.asList(nullSafeArray(peerCacheConfigurers, PeerCacheConfigurer.class)));
- }
-
- /**
- * Null-safe operation to apply the given {@link Iterable} of {@link PeerCacheConfigurer PeerCacheConfigurers}
- * to this {@link CacheFactoryBean}.
- *
- * @param peerCacheConfigurers {@link Iterable} of {@link PeerCacheConfigurer PeerCacheConfigurers}
- * applied to this {@link CacheFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
- * @see java.lang.Iterable
- */
- protected void applyPeerCacheConfigurers(Iterable peerCacheConfigurers) {
- stream(nullSafeIterable(peerCacheConfigurers).spliterator(), false)
- .forEach(clientCacheConfigurer -> clientCacheConfigurer.configure(getBeanName(), this));
- }
-
/**
* Initializes the {@link Cache}.
*
@@ -257,14 +259,15 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
ClassLoader currentThreadContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
- // use bean ClassLoader to load Spring configured, Pivotal GemFire/Apache Geode classes
+ // Use Spring Bean ClassLoader to load Spring configured, Pivotal GemFire/Apache Geode classes
Thread.currentThread().setContextClassLoader(getBeanClassLoader());
setCache(postProcess(resolveCache()));
- Optional.ofNullable(this.getCache()).ifPresent(cache -> {
+ Optional.ofNullable(getCache()).ifPresent(cache -> {
- Optional.ofNullable(cache.getDistributedSystem()).map(DistributedSystem::getDistributedMember)
+ Optional.ofNullable(cache.getDistributedSystem())
+ .map(DistributedSystem::getDistributedMember)
.ifPresent(member ->
logInfo(() -> String.format("Connected to Distributed System [%1$s] as Member [%2$s]"
.concat(" in Group(s) [%3$s] with Role(s) [%4$s] on Host [%5$s] having PID [%6$d]"),
@@ -279,8 +282,8 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
return getCache();
}
- catch (Exception e) {
- throw newRuntimeException(e, "Error occurred when initializing peer cache");
+ catch (Exception cause) {
+ throw newRuntimeException(cause, "Error occurred when initializing peer cache");
}
finally {
Thread.currentThread().setContextClassLoader(currentThreadContextClassLoader);
@@ -298,19 +301,24 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @see #fetchCache()
* @see #resolveProperties()
* @see #createFactory(java.util.Properties)
- * @see #prepareFactory(Object)
+ * @see #configureFactory(Object)
* @see #createCache(Object)
*/
@SuppressWarnings("unchecked")
protected T resolveCache() {
+
try {
+
this.cacheResolutionMessagePrefix = "Found existing";
+
return (T) fetchCache();
}
- catch (CacheClosedException ex) {
+ catch (CacheClosedException cause) {
+
this.cacheResolutionMessagePrefix = "Created new";
initDynamicRegionFactory();
- return (T) createCache(prepareFactory(initializeFactory(createFactory(resolveProperties()))));
+
+ return (T) createCache(postProcess(configureFactory(initializeFactory(createFactory(resolveProperties())))));
}
}
@@ -353,7 +361,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
/**
* Constructs a new instance of {@link CacheFactory} initialized with the given Pivotal GemFire/Apache Geode
- * {@link Properties} used to create an instance of a {@link Cache}.
+ * {@link Properties} used to construct, configure and initialize an instance of a {@link Cache}.
*
* @param gemfireProperties {@link Properties} used by the {@link CacheFactory} to configure the {@link Cache}.
* @return a new instance of {@link CacheFactory} initialized with the given Pivotal GemFire/Apache Geode
@@ -366,11 +374,12 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
/**
- * Initializes the given cache factory with the configured {@link CacheFactoryInitializer}.
+ * Initializes the given {@link CacheFactory} with the configured {@link CacheFactoryInitializer}.
*
- * @param factory cache factory to initialize; may be {@literal null}.
- * @return the given cache factory.
+ * @param factory {@link CacheFactory} to initialize; may be {@literal null}.
+ * @return the initialized {@link CacheFactory}.
* @see org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer#initialize(Object)
+ * @see org.apache.geode.cache.CacheFactory
* @see #getCacheFactoryInitializer()
*/
@Nullable
@@ -383,16 +392,17 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
/**
- * Prepares and initializes the {@link CacheFactory} used to create the {@link Cache}.
+ * Configures the {@link CacheFactory} used to create the {@link Cache}.
*
* Sets PDX options specified by the user.
*
* @param factory {@link CacheFactory} used to create the {@link Cache}.
- * @return the prepared and initialized {@link CacheFactory}.
- * @see #initializePdx(CacheFactory)
+ * @return the configured {@link CacheFactory}.
+ * @see org.apache.geode.cache.CacheFactory
+ * @see #configurePdx(CacheFactory)
*/
- protected Object prepareFactory(Object factory) {
- return initializePdx((CacheFactory) factory);
+ protected Object configureFactory(Object factory) {
+ return configurePdx((CacheFactory) factory);
}
/**
@@ -402,7 +412,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @return the given {@link CacheFactory}.
* @see org.apache.geode.cache.CacheFactory
*/
- private CacheFactory initializePdx(CacheFactory cacheFactory) {
+ private CacheFactory configurePdx(CacheFactory cacheFactory) {
Optional.ofNullable(getPdxSerializer()).ifPresent(cacheFactory::setPdxSerializer);
@@ -419,17 +429,28 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
/**
- * Creates a new {@link Cache} instance using the provided factory.
+ * Post processes the {@link CacheFactory} used to create the {@link Cache}.
*
- * @param parameterized {@link Class} type extension of {@link GemFireCache}.
+ * @param factory {@link CacheFactory} used to create the {@link Cache}.
+ * @return the post processed {@link CacheFactory}.
+ * @see org.apache.geode.cache.CacheFactory
+ */
+ protected Object postProcess(Object factory) {
+ return factory;
+ }
+
+ /**
+ * Creates a new {@link Cache} instance using the provided {@link Object factory}.
+ *
+ * @param {@link Class sub-type} of {@link GemFireCache}.
* @param factory instance of {@link CacheFactory}.
- * @return a new instance of {@link Cache} created by the provided factory.
+ * @return a new instance of {@link Cache} created by the provided {@link Object factory}.
* @see org.apache.geode.cache.CacheFactory#create()
* @see org.apache.geode.cache.GemFireCache
*/
@SuppressWarnings("unchecked")
protected T createCache(Object factory) {
- return (T) Optional.ofNullable(getCache()).orElseGet(((CacheFactory) factory)::create);
+ return (T) ((CacheFactory) factory).create();
}
/**
@@ -450,16 +471,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
@SuppressWarnings("all")
protected T postProcess(T cache) {
- // load cache.xml Resource and initialize the cache
- Optional.ofNullable(getCacheXml()).ifPresent(cacheXml -> {
- try {
- logDebug("Initializing cache with [%s]", cacheXml);
- cache.loadCacheXml(cacheXml.getInputStream());
- }
- catch (IOException e) {
- throw newRuntimeException(e, "Failed to load cache.xml [%s]", cacheXml);
- }
- });
+ loadCacheXml(cache);
Optional.ofNullable(getCopyOnRead()).ifPresent(cache::setCopyOnRead);
@@ -473,20 +485,34 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
configureHeapPercentages(cache);
configureOffHeapPercentages(cache);
- registerJndiDataSources();
+ registerJndiDataSources(cache);
registerTransactionListeners(cache);
registerTransactionWriter(cache);
return cache;
}
- /* (non-Javadoc) */
- private boolean isHeapPercentageValid(Float heapPercentage) {
- return (heapPercentage >= 0.0f && heapPercentage <= 100.0f);
+ private T loadCacheXml(T cache) {
+
+ // Load cache.xml Resource and initialize the cache
+ Optional.ofNullable(getCacheXml()).ifPresent(cacheXml -> {
+ try {
+ logDebug("Initializing cache with [%s]", cacheXml);
+ cache.loadCacheXml(cacheXml.getInputStream());
+ }
+ catch (IOException cause) {
+ throw newRuntimeException(cause, "Failed to load cache.xml [%s]", cacheXml);
+ }
+ });
+
+ return cache;
}
- /* (non-Javadoc) */
- private void configureHeapPercentages(GemFireCache cache) {
+ private boolean isHeapPercentageValid(Float heapPercentage) {
+ return heapPercentage >= 0.0f && heapPercentage <= 100.0f;
+ }
+
+ private GemFireCache configureHeapPercentages(GemFireCache cache) {
Optional.ofNullable(getCriticalHeapPercentage()).ifPresent(criticalHeapPercentage -> {
@@ -503,10 +529,11 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
cache.getResourceManager().setEvictionHeapPercentage(evictionHeapPercentage);
});
+
+ return cache;
}
- /* (non-Javadoc) */
- private void configureOffHeapPercentages(GemFireCache cache) {
+ private GemFireCache configureOffHeapPercentages(GemFireCache cache) {
Optional.ofNullable(getCriticalOffHeapPercentage()).ifPresent(criticalOffHeapPercentage -> {
@@ -523,10 +550,11 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
cache.getResourceManager().setEvictionOffHeapPercentage(evictionOffHeapPercentage);
});
+
+ return cache;
}
- /* (non-Javadoc) */
- private void registerJndiDataSources() {
+ private GemFireCache registerJndiDataSources(GemFireCache cache) {
nullSafeCollection(getJndiDataSources()).forEach(jndiDataSource -> {
@@ -534,41 +562,30 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
JndiDataSourceType jndiDataSourceType = JndiDataSourceType.valueOfIgnoreCase(type);
- Assert.notNull(jndiDataSourceType, String.format(
- "'jndi-binding' 'type' [%1$s] is invalid; 'type' must be one of %2$s", type,
- Arrays.toString(JndiDataSourceType.values())));
+ Assert.notNull(jndiDataSourceType,
+ String.format("'jndi-binding' 'type' [%1$s] is invalid; 'type' must be one of %2$s",
+ type, Arrays.toString(JndiDataSourceType.values())));
jndiDataSource.getAttributes().put("type", jndiDataSourceType.getName());
JNDIInvoker.mapDatasource(jndiDataSource.getAttributes(), jndiDataSource.getProps());
});
+
+ return cache;
}
- /* (non-Javadoc) */
- private void registerTransactionListeners(GemFireCache cache) {
+ private GemFireCache registerTransactionListeners(GemFireCache cache) {
+
nullSafeCollection(getTransactionListeners())
.forEach(transactionListener -> cache.getCacheTransactionManager().addListener(transactionListener));
+
+ return cache;
}
- /* (non-Javadoc) */
- private void registerTransactionWriter(GemFireCache cache) {
+ private GemFireCache registerTransactionWriter(GemFireCache cache) {
+
Optional.ofNullable(getTransactionWriter()).ifPresent(it -> cache.getCacheTransactionManager().setWriter(it));
- }
- /**
- * Destroys the {@link Cache} bean on Spring container shutdown.
- *
- * @throws Exception if an error occurs while closing the cache.
- * @see org.springframework.beans.factory.DisposableBean#destroy()
- * @see #destroyBeanFactoryLocator()
- * @see #close(GemFireCache)
- * @see #isClose()
- */
- @Override
- public void destroy() throws Exception {
- if (isClose()) {
- close(fetchCache());
- destroyBeanFactoryLocator();
- }
+ return cache;
}
/**
@@ -585,7 +602,25 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
.filter(it -> !it.isClosed())
.ifPresent(RegionService::close);
- this.cache = null;
+ setCache(null);
+ }
+
+ /**
+ * Destroys the {@link Cache} bean on Spring container shutdown.
+ *
+ * @throws Exception if an error occurs while closing the cache.
+ * @see org.springframework.beans.factory.DisposableBean#destroy()
+ * @see #destroyBeanFactoryLocator()
+ * @see #close(GemFireCache)
+ * @see #isClose()
+ */
+ @Override
+ public void destroy() throws Exception {
+
+ if (isClose()) {
+ close(fetchCache());
+ destroyBeanFactoryLocator();
+ }
}
/**
@@ -613,7 +648,9 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
public DataAccessException translateExceptionIfPossible(RuntimeException exception) {
if (exception instanceof IllegalArgumentException) {
+
DataAccessException wrapped = GemfireCacheUtils.convertQueryExceptions(exception);
+
// ignore conversion if generic exception is returned
if (!(wrapped instanceof GemfireSystemException)) {
return wrapped;
@@ -702,11 +739,12 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @see #getCacheXml()
*/
private File getCacheXmlFile() {
+
try {
return getCacheXml().getFile();
}
- catch (Throwable e) {
- throw newIllegalStateException(e, "Resource [%s] is not resolvable as a file", getCacheXml());
+ catch (Throwable cause) {
+ throw newIllegalStateException(cause, "Resource [%s] is not resolvable as a file", getCacheXml());
}
}
@@ -716,9 +754,11 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @return boolean value indicating whether a {@link Resource cache.xml} {@link File} is present.
* @see #getCacheXmlFile()
*/
+ @SuppressWarnings("all")
private boolean isCacheXmlAvailable() {
+
try {
- return (getCacheXmlFile() != null);
+ return getCacheXmlFile() != null;
}
catch (Throwable ignore) {
return false;
@@ -736,7 +776,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
@Override
@SuppressWarnings("all")
public GemFireCache getObject() throws Exception {
- return Optional.ofNullable(this.getCache()).orElseGet(this::init);
+ return Optional.ofNullable(getCache()).orElseGet(this::init);
}
/**
@@ -752,26 +792,25 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
/**
- * Set the phase for the {@link Cache} bean in the lifecycle managed by the Spring container.
+ * Set the {@link CacheFactoryInitializer} that will be called to initialize the cache factory used to create
+ * the cache constructed by this {@link CacheFactoryBean}.
*
- * @param phase {@link Integer#TYPE int} value indicating the phase of this {@link Cache} bean
- * in the lifecycle managed by the Spring container.
- * @see org.springframework.context.Phased#getPhase()
+ * @param cacheFactoryInitializer {@link CacheFactoryInitializer} configured to initialize the cache factory.
+ * @see org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer
*/
- protected void setPhase(int phase) {
- this.phase = phase;
+ public void setCacheFactoryInitializer(CacheFactoryInitializer cacheFactoryInitializer) {
+ this.cacheFactoryInitializer = cacheFactoryInitializer;
}
/**
- * Returns the configured phase of the {@link Cache} bean in the lifecycle managed by the Spring container.
+ * Return the {@link CacheFactoryInitializer} that will be called to initialize the cache factory used to create
+ * the cache constructed by this {@link CacheFactoryBean}.
*
- * @return an {@link Integer#TYPE int} value indicating the phase of this {@link Cache} bean in the lifecycle
- * managed by the Spring container.
- * @see org.springframework.context.Phased#getPhase()
+ * @return the {@link CacheFactoryInitializer} configured to initialize the cache factory.
+ * @see org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer
*/
- @Override
- public int getPhase() {
- return this.phase;
+ public CacheFactoryInitializer getCacheFactoryInitializer() {
+ return this.cacheFactoryInitializer;
}
/**
@@ -808,28 +847,6 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
return this.properties;
}
- /**
- * Set the {@link CacheFactoryInitializer} that will be called to initialize the cache factory used to create
- * the cache constructed by this {@link CacheFactoryBean}.
- *
- * @param cacheFactoryInitializer {@link CacheFactoryInitializer} configured to initialize the cache factory.
- * @see org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer
- */
- public void setCacheFactoryInitializer(CacheFactoryInitializer cacheFactoryInitializer) {
- this.cacheFactoryInitializer = cacheFactoryInitializer;
- }
-
- /**
- * Return the {@link CacheFactoryInitializer} that will be called to initialize the cache factory used to create
- * the cache constructed by this {@link CacheFactoryBean}.
- *
- * @return the {@link CacheFactoryInitializer} configured to initialize the cache factory.
- * @see org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer
- */
- public CacheFactoryInitializer getCacheFactoryInitializer() {
- return this.cacheFactoryInitializer;
- }
-
/**
* Sets a value to indicate whether the cache will be closed on shutdown of the Spring container.
*
@@ -940,7 +957,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* or not.
*/
public Boolean getEnableAutoReconnect() {
- return enableAutoReconnect;
+ return this.enableAutoReconnect;
}
/**
@@ -1057,6 +1074,29 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
return messageSyncInterval;
}
+ /**
+ * Set the phase for the {@link Cache} bean in the lifecycle managed by the Spring container.
+ *
+ * @param phase {@link Integer#TYPE int} value indicating the phase of this {@link Cache} bean
+ * in the lifecycle managed by the Spring container.
+ * @see org.springframework.context.Phased#getPhase()
+ */
+ protected void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ /**
+ * Returns the configured phase of the {@link Cache} bean in the lifecycle managed by the Spring container.
+ *
+ * @return an {@link Integer#TYPE int} value indicating the phase of this {@link Cache} bean in the lifecycle
+ * managed by the Spring container.
+ * @see org.springframework.context.Phased#getPhase()
+ */
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
/**
* Set the disk store that is used for PDX meta data. Applicable on GemFire
* 6.6 or higher.
@@ -1164,7 +1204,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
*/
public void setPeerCacheConfigurers(List peerCacheConfigurers) {
- this.peerCacheConfigurers = Optional.ofNullable(peerCacheConfigurers).orElseGet(Collections::emptyList);
+ Optional.ofNullable(peerCacheConfigurers).ifPresent(this.peerCacheConfigurers::addAll);
}
/**
@@ -1279,9 +1319,9 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
* @see org.apache.geode.cache.client.ClientCacheFactory
*/
T initialize(T cacheFactory);
+
}
- /* (non-Javadoc) */
public static class DynamicRegionSupport {
private Boolean persistent = Boolean.TRUE;
@@ -1323,23 +1363,25 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
public void initializeDynamicRegionFactory() {
- File localDiskDirectory = (this.diskDirectory != null ? new File(this.diskDirectory) : null);
- DynamicRegionFactory.Config config = new DynamicRegionFactory.Config(localDiskDirectory, poolName,
- persistent, registerInterest);
+ File localDiskDirectory = this.diskDirectory != null ? new File(this.diskDirectory) : null;
+
+ DynamicRegionFactory.Config config =
+ new DynamicRegionFactory.Config(localDiskDirectory, this.poolName, this.persistent,
+ this.registerInterest);
DynamicRegionFactory.get().open(config);
}
}
- /* (non-Javadoc) */
public static class JndiDataSource {
- private List props;
+ private List configProperties;
+
private Map attributes;
public Map getAttributes() {
- return attributes;
+ return this.attributes;
}
public void setAttributes(Map attributes) {
@@ -1347,11 +1389,11 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport
}
public List getProps() {
- return props;
+ return this.configProperties;
}
public void setProps(List props) {
- this.props = props;
+ this.configProperties = props;
}
}
}
diff --git a/src/main/java/org/springframework/data/gemfire/ConfigurableRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/ConfigurableRegionFactoryBean.java
new file mode 100644
index 00000000..526a33b9
--- /dev/null
+++ b/src/main/java/org/springframework/data/gemfire/ConfigurableRegionFactoryBean.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.gemfire;
+
+import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
+import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeCollection;
+import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.StreamSupport;
+
+import org.apache.geode.cache.Region;
+import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
+import org.springframework.data.gemfire.config.annotation.RegionConfigurer;
+
+/**
+ * The ConfigurableRegionFactoryBean class...
+ *
+ * @author John Blum
+ * @see org.springframework.data.gemfire.RegionLookupFactoryBean
+ * @since 2.1.0
+ */
+@SuppressWarnings("unused")
+public abstract class ConfigurableRegionFactoryBean extends RegionLookupFactoryBean {
+
+ private List regionConfigurers = Collections.emptyList();
+
+ private RegionConfigurer compositeRegionConfigurer = new RegionConfigurer() {
+
+ @Override
+ public void configure(String beanName, ClientRegionFactoryBean, ?> bean) {
+ nullSafeCollection(regionConfigurers)
+ .forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean));
+ }
+ };
+
+ /**
+ * Returns a reference to the Composite {@link RegionConfigurer} used to apply additional configuration
+ * to this {@link ClientRegionFactoryBean} on Spring container initialization.
+ *
+ * @return the Composite {@link RegionConfigurer}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ */
+ protected RegionConfigurer getCompositeRegionConfigurer() {
+ return this.compositeRegionConfigurer;
+ }
+
+ /**
+ * Null-safe operation to set an array of {@link RegionConfigurer RegionConfigurers} used to apply
+ * additional configuration to this {@link ClientRegionFactoryBean} when using Annotation-based configuration.
+ *
+ * @param regionConfigurers array of {@link RegionConfigurer RegionConfigurers} used to apply
+ * additional configuration to this {@link ClientRegionFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ * @see #setRegionConfigurers(List)
+ */
+ public void setRegionConfigurers(RegionConfigurer... regionConfigurers) {
+ setRegionConfigurers(Arrays.asList(nullSafeArray(regionConfigurers, RegionConfigurer.class)));
+ }
+
+ /**
+ * Null-safe operation to set an {@link Iterable} of {@link RegionConfigurer RegionConfigurers} used to apply
+ * additional configuration to this {@link ClientRegionFactoryBean} when using Annotation-based configuration.
+ *
+ * @param regionConfigurers {@link Iterable} of {@link RegionConfigurer RegionConfigurers} used to apply
+ * additional configuration to this {@link ClientRegionFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ */
+ public void setRegionConfigurers(List regionConfigurers) {
+ this.regionConfigurers = Optional.ofNullable(regionConfigurers).orElseGet(Collections::emptyList);
+ }
+
+ /**
+ * Null-safe operation to apply the composite {@link RegionConfigurer RegionConfigurers}
+ * to this {@link ConfigurableRegionFactoryBean}.
+ *
+ * @param regionName {@link String} containing the name of the {@link Region}.
+ * to this {@link ConfigurableRegionFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ * @see #applyRegionConfigurers(String, Iterable)
+ * @see #getCompositeRegionConfigurer()
+ */
+ protected void applyRegionConfigurers(String regionName) {
+ applyRegionConfigurers(regionName, getCompositeRegionConfigurer());
+ }
+
+ /**
+ * Null-safe operation to apply the given array of {@link RegionConfigurer RegionConfigurers}
+ * to this {@link ConfigurableRegionFactoryBean}.
+ *
+ * @param regionName {@link String} containing the name of the {@link Region}.
+ * @param regionConfigurers array of {@link RegionConfigurer RegionConfigurers} applied
+ * to this {@link ConfigurableRegionFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ * @see #applyRegionConfigurers(String, Iterable)
+ */
+ protected void applyRegionConfigurers(String regionName, RegionConfigurer... regionConfigurers) {
+ applyRegionConfigurers(regionName, Arrays.asList(nullSafeArray(regionConfigurers, RegionConfigurer.class)));
+ }
+
+ /**
+ * Null-safe operation to apply the given {@link Iterable} of {@link RegionConfigurer RegionConfigurers}
+ * to this {@link ConfigurableRegionFactoryBean}.
+ *
+ * @param regionName {@link String} containing the name of the {@link Region}.
+ * @param regionConfigurers {@link Iterable} of {@link RegionConfigurer RegionConfigurers} applied
+ * to this {@link ConfigurableRegionFactoryBean}.
+ * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
+ * @see #applyRegionConfigurers(String, RegionConfigurer...)
+ */
+ protected void applyRegionConfigurers(String regionName, Iterable regionConfigurers) {
+
+ if (this instanceof RegionFactoryBean) {
+ StreamSupport.stream(nullSafeIterable(regionConfigurers).spliterator(), false)
+ .forEach(regionConfigurer -> regionConfigurer.configure(regionName, (RegionFactoryBean) this));
+ }
+ else if (this instanceof ClientRegionFactoryBean) {
+ StreamSupport.stream(nullSafeIterable(regionConfigurers).spliterator(), false)
+ .forEach(regionConfigurer -> regionConfigurer.configure(regionName, (ClientRegionFactoryBean) this));
+ }
+ }
+}
diff --git a/src/main/java/org/springframework/data/gemfire/LookupRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/LookupRegionFactoryBean.java
index 3984e1ef..adc0d032 100644
--- a/src/main/java/org/springframework/data/gemfire/LookupRegionFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/LookupRegionFactoryBean.java
@@ -16,36 +16,38 @@
package org.springframework.data.gemfire;
-import org.apache.geode.cache.AttributesMutator;
+import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
+
+import java.util.Arrays;
+import java.util.Optional;
+
import org.apache.geode.cache.CacheListener;
import org.apache.geode.cache.CacheLoader;
import org.apache.geode.cache.CacheWriter;
import org.apache.geode.cache.CustomExpiry;
-import org.apache.geode.cache.EvictionAttributesMutator;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.wan.GatewaySender;
import org.springframework.util.Assert;
-import org.springframework.util.ObjectUtils;
/**
* The LookupRegionFactoryBean class is a concrete implementation of RegionLookupFactoryBean for handling
* >gfe:lookup-region/< SDG XML namespace (XSD) elements.
*
* @author John Blum
- * @see org.springframework.data.gemfire.RegionLookupFactoryBean
+ * @see RegionLookupFactoryBean
* @see org.apache.geode.cache.AttributesMutator
* @since 1.6.0
*/
@SuppressWarnings("unused")
public class LookupRegionFactoryBean extends RegionLookupFactoryBean {
+ private AsyncEventQueue[] asyncEventQueues;
+
private Boolean cloningEnabled;
private Boolean enableStatistics;
- private AsyncEventQueue[] asyncEventQueues;
-
private CacheListener[] cacheListeners;
private CacheLoader cacheLoader;
@@ -66,166 +68,123 @@ public class LookupRegionFactoryBean extends RegionLookupFactoryBean
@Override
public void afterPropertiesSet() throws Exception {
+
super.afterPropertiesSet();
- AttributesMutator attributesMutator = getRegion().getAttributesMutator();
+ Optional.ofNullable(getRegion().getAttributesMutator()).ifPresent(attributesMutator -> {
- if (!ObjectUtils.isEmpty(asyncEventQueues)) {
- for (AsyncEventQueue asyncEventQueue : asyncEventQueues) {
- attributesMutator.addAsyncEventQueueId(asyncEventQueue.getId());
- }
- }
+ Arrays.stream(nullSafeArray(this.asyncEventQueues, AsyncEventQueue.class))
+ .map(AsyncEventQueue::getId)
+ .forEach(attributesMutator::addAsyncEventQueueId);
- if (!ObjectUtils.isEmpty(cacheListeners)) {
- for (CacheListener cacheListener : cacheListeners) {
- attributesMutator.addCacheListener(cacheListener);
- }
- }
+ Arrays.stream(nullSafeArray(this.cacheListeners, CacheListener.class))
+ .forEach(attributesMutator::addCacheListener);
- if (cacheLoader != null) {
- attributesMutator.setCacheLoader(cacheLoader);
- }
+ Optional.ofNullable(this.cacheLoader).ifPresent(attributesMutator::setCacheLoader);
+ Optional.ofNullable(this.cacheWriter).ifPresent(attributesMutator::setCacheWriter);
+ Optional.ofNullable(this.cloningEnabled).ifPresent(attributesMutator::setCloningEnabled);
- if (cacheWriter != null) {
- attributesMutator.setCacheWriter(cacheWriter);
- }
+ // Eviction
+ Optional.ofNullable(attributesMutator.getEvictionAttributesMutator())
+ .ifPresent(evictionAttributesMutator -> Optional.ofNullable(this.evictionMaximum)
+ .ifPresent(evictionAttributesMutator::setMaximum));
- if (cloningEnabled != null) {
- attributesMutator.setCloningEnabled(cloningEnabled);
- }
+ // Expiration
+ if (isStatisticsEnabled()) {
- if (isStatisticsEnabled()) {
- assertStatisticsEnabled();
+ assertStatisticsEnabled();
- if (customEntryIdleTimeout != null) {
- attributesMutator.setCustomEntryIdleTimeout(customEntryIdleTimeout);
+ Optional.ofNullable(this.customEntryIdleTimeout).ifPresent(attributesMutator::setCustomEntryIdleTimeout);
+ Optional.ofNullable(this.customEntryTimeToLive).ifPresent(attributesMutator::setCustomEntryTimeToLive);
+ Optional.ofNullable(this.entryIdleTimeout).ifPresent(attributesMutator::setEntryIdleTimeout);
+ Optional.ofNullable(this.entryTimeToLive).ifPresent(attributesMutator::setEntryTimeToLive);
+ Optional.ofNullable(this.regionIdleTimeout).ifPresent(attributesMutator::setRegionIdleTimeout);
+ Optional.ofNullable(this.regionTimeToLive).ifPresent(attributesMutator::setRegionTimeToLive);
}
- if (customEntryTimeToLive != null) {
- attributesMutator.setCustomEntryTimeToLive(customEntryTimeToLive);
- }
-
- if (entryIdleTimeout != null) {
- attributesMutator.setEntryIdleTimeout(entryIdleTimeout);
- }
-
- if (entryTimeToLive != null) {
- attributesMutator.setEntryTimeToLive(entryTimeToLive);
- }
-
- if (regionIdleTimeout != null) {
- attributesMutator.setRegionIdleTimeout(regionIdleTimeout);
- }
-
- if (regionTimeToLive != null) {
- attributesMutator.setRegionTimeToLive(regionTimeToLive);
- }
- }
-
- if (evictionMaximum != null) {
- EvictionAttributesMutator evictionAttributesMutator = attributesMutator.getEvictionAttributesMutator();
- evictionAttributesMutator.setMaximum(evictionMaximum);
- }
-
- if (!ObjectUtils.isEmpty(gatewaySenders)) {
- for (GatewaySender gatewaySender : gatewaySenders) {
- attributesMutator.addGatewaySenderId(gatewaySender.getId());
- }
- }
+ Arrays.stream(nullSafeArray(this.gatewaySenders, GatewaySender.class))
+ .map(GatewaySender::getId)
+ .forEach(attributesMutator::addGatewaySenderId);
+ });
}
@Override
- final boolean isLookupEnabled() {
+ public final boolean isLookupEnabled() {
return true;
}
- /* (non-Javadoc) */
public void setAsyncEventQueues(AsyncEventQueue[] asyncEventQueues) {
this.asyncEventQueues = asyncEventQueues;
}
- /* (non-Javadoc) */
public void setCacheListeners(CacheListener[] cacheListeners) {
this.cacheListeners = cacheListeners;
}
- /* (non-Javadoc) */
public void setCacheLoader(CacheLoader cacheLoader) {
this.cacheLoader = cacheLoader;
}
- /* (non-Javadoc) */
public void setCacheWriter(CacheWriter cacheWriter) {
this.cacheWriter = cacheWriter;
}
- /* (non-Javadoc) */
public void setCloningEnabled(Boolean cloningEnabled) {
this.cloningEnabled = cloningEnabled;
}
- /* (non-Javadoc) */
public void setCustomEntryIdleTimeout(CustomExpiry customEntryIdleTimeout) {
setStatisticsEnabled(customEntryIdleTimeout != null);
this.customEntryIdleTimeout = customEntryIdleTimeout;
}
- /* (non-Javadoc) */
public void setCustomEntryTimeToLive(CustomExpiry customEntryTimeToLive) {
setStatisticsEnabled(customEntryTimeToLive != null);
this.customEntryTimeToLive = customEntryTimeToLive;
}
- /* (non-Javadoc) */
public void setEntryIdleTimeout(ExpirationAttributes entryIdleTimeout) {
setStatisticsEnabled(entryIdleTimeout != null);
this.entryIdleTimeout = entryIdleTimeout;
}
- /* (non-Javadoc) */
public void setEntryTimeToLive(ExpirationAttributes entryTimeToLive) {
setStatisticsEnabled(entryTimeToLive != null);
this.entryTimeToLive = entryTimeToLive;
}
- /* (non-Javadoc) */
public void setEvictionMaximum(final Integer evictionMaximum) {
this.evictionMaximum = evictionMaximum;
}
- /* (non-Javadoc) */
public void setGatewaySenders(GatewaySender[] gatewaySenders) {
this.gatewaySenders = gatewaySenders;
}
- /* (non-Javadoc) */
public void setRegionIdleTimeout(ExpirationAttributes regionIdleTimeout) {
setStatisticsEnabled(regionIdleTimeout != null);
this.regionIdleTimeout = regionIdleTimeout;
}
- /* (non-Javadoc) */
public void setRegionTimeToLive(ExpirationAttributes regionTimeToLive) {
setStatisticsEnabled(regionTimeToLive != null);
this.regionTimeToLive = regionTimeToLive;
}
- /* (non-Javadoc) */
public void setStatisticsEnabled(Boolean enableStatistics) {
this.enableStatistics = enableStatistics;
}
- /* (non-Javadoc) */
protected boolean isStatisticsEnabled() {
return Boolean.TRUE.equals(this.enableStatistics);
}
- /* (non-Javadoc) */
private void assertStatisticsEnabled() {
+
Region localRegion = getRegion();
- Assert.state(localRegion.getAttributes().getStatisticsEnabled(), String.format(
- "Statistics for Region '%1$s' must be enabled to change Entry & Region TTL/TTI Expiration settings",
+
+ Assert.state(localRegion.getAttributes().getStatisticsEnabled(),
+ String.format("Statistics for Region [%s] must be enabled to change Entry & Region TTL/TTI Expiration settings",
localRegion.getFullPath()));
}
-
}
diff --git a/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java
index 02bcdd29..858fc1a9 100644
--- a/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java
@@ -17,6 +17,7 @@ package org.springframework.data.gemfire;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
+import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.util.Assert;
/**
@@ -39,7 +40,7 @@ public class PartitionedRegionFactoryBean extends RegionFactoryBean
}
// Validate the data-policy and persistent attributes are compatible when specified!
- assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy);
+ RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent);
regionFactory.setDataPolicy(dataPolicy);
setDataPolicy(dataPolicy);
diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java
index a7e1700f..72962e45 100644
--- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java
@@ -18,19 +18,11 @@ package org.springframework.data.gemfire;
import static java.util.Arrays.stream;
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
-import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeCollection;
-import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
import java.util.Optional;
-import java.util.stream.StreamSupport;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheListener;
@@ -56,7 +48,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.io.Resource;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
-import org.springframework.data.gemfire.config.annotation.RegionConfigurer;
+import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -88,16 +80,15 @@ import org.springframework.util.StringUtils;
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
* @see org.springframework.beans.factory.DisposableBean
* @see org.springframework.context.SmartLifecycle
- * @see org.springframework.data.gemfire.RegionLookupFactoryBean
+ * @see RegionLookupFactoryBean
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
*/
@SuppressWarnings("unused")
-public abstract class RegionFactoryBean extends RegionLookupFactoryBean
+// TODO: Rename to PeerRegionFatoryBean in SD Lovelace
+public abstract class RegionFactoryBean extends ConfigurableRegionFactoryBean
implements DisposableBean, SmartLifecycle {
- protected final Log log = LogFactory.getLog(getClass());
-
private boolean close = true;
private boolean destroy = false;
private boolean running;
@@ -124,19 +115,8 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean regionConfigurers = Collections.emptyList();
-
private RegionAttributes attributes;
- private RegionConfigurer compositeRegionConfigurer = new RegionConfigurer() {
-
- @Override
- public void configure(String beanName, RegionFactoryBean, ?> bean) {
- nullSafeCollection(regionConfigurers)
- .forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean));
- }
- };
-
private RegionShortcut shortcut;
private Resource snapshot;
@@ -170,40 +150,6 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean regionConfigurers) {
- StreamSupport.stream(nullSafeIterable(regionConfigurers).spliterator(), false)
- .forEach(regionConfigurer -> regionConfigurer.configure(regionName, this));
- }
-
- /* (non-Javadoc) */
private Region enableAsLockGrantor(Region region) {
Optional.ofNullable(region)
@@ -213,7 +159,6 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean newRegion(RegionFactory regionFactory, Region, ?> parentRegion, String regionName) {
return Optional.ofNullable(parentRegion)
@@ -230,7 +175,6 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean newIllegalArgumentException("Peer Cache is required"));
}
- /* (non-Javadoc) */
private RegionAttributes verifyLockGrantorEligibility(RegionAttributes regionAttributes, Scope scope) {
Optional.ofNullable(regionAttributes).ifPresent(attributes ->
@@ -249,9 +192,8 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean regionFactory.addGatewaySenderId(((GatewaySender) gatewaySender).getId()));
+ .forEach(gatewaySender -> regionFactory.addGatewaySenderId(gatewaySender.getId()));
Optional.ofNullable(this.keyConstraint).ifPresent(regionFactory::setKeyConstraint);
@@ -343,23 +285,12 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean RegionShortcutToDataPolicyConverter.INSTANCE.convert(regionShortcut));
}
- /* (non-Javadoc) */
@SuppressWarnings("unchecked")
private Optional getFieldValue(Object source, String fieldName, Class targetType) {
@@ -470,27 +400,30 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean regionFactory, Boolean persistent, DataPolicy dataPolicy) {
if (dataPolicy != null) {
- assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy);
+ RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, this.persistent);
regionFactory.setDataPolicy(dataPolicy);
setDataPolicy(dataPolicy);
}
@@ -635,8 +532,9 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean regionConfigurers) {
- this.regionConfigurers = Optional.ofNullable(regionConfigurers).orElseGet(Collections::emptyList);
- }
-
public Scope getScope() {
return this.scope;
}
@@ -941,9 +814,9 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean extends RegionLookupFactoryBean extends AbstractFactoryBeanSupport>
implements InitializingBean {
@@ -74,15 +75,12 @@ public abstract class RegionLookupFactoryBean extends AbstractFactoryBeanS
@SuppressWarnings("all")
public void afterPropertiesSet() throws Exception {
- GemFireCache cache = getCache();
+ GemFireCache cache = requireCache();
- Assert.notNull(cache, "Cache is required");
-
- String regionName = resolveRegionName();
-
- Assert.hasText(regionName, "regionName, name or beanName property must be set");
+ String regionName = requireRegionName();
synchronized (cache) {
+
setRegion(isLookupEnabled()
? Optional.ofNullable(getParent())
.map(parentRegion -> parentRegion.getSubregion(regionName))
@@ -101,6 +99,35 @@ public abstract class RegionLookupFactoryBean extends AbstractFactoryBeanS
}
}
+ private GemFireCache requireCache() {
+
+ GemFireCache cache = getCache();
+
+ Assert.notNull(cache, "Cache is required");
+
+ return cache;
+ }
+
+ private String requireRegionName() {
+
+ String regionName = resolveRegionName();
+
+ Assert.hasText(regionName, "regionName, name or the beanName property must be set");
+
+ return regionName;
+ }
+
+ /**
+ * Resolves the {@link String name} of the {@link Region}.
+ *
+ * @return a {@link String} containing the name of the {@link Region}.
+ * @see org.apache.geode.cache.Region#getName()
+ */
+ public String resolveRegionName() {
+ return StringUtils.hasText(this.regionName) ? this.regionName
+ : (StringUtils.hasText(this.name) ? this.name : getBeanName());
+ }
+
/**
* Creates a new {@link Region} with the given {@link String name}.
*
@@ -134,8 +161,8 @@ public abstract class RegionLookupFactoryBean extends AbstractFactoryBeanS
try {
region.loadSnapshot(snapshot.getInputStream());
}
- catch (Exception e) {
- throw newRuntimeException(e, "Failed to load snapshot [%s]", snapshot);
+ catch (Exception cause) {
+ throw newRuntimeException(cause, "Failed to load snapshot [%s]", snapshot);
}
});
@@ -177,17 +204,6 @@ public abstract class RegionLookupFactoryBean extends AbstractFactoryBeanS
return Optional.ofNullable(getRegion()).map(Region::getClass).orElse((Class) Region.class);
}
- /**
- * Resolves the {@link String name} of the {@link Region}.
- *
- * @return a {@link String} containing the name of the {@link Region}.
- * @see org.apache.geode.cache.Region#getName()
- */
- public String resolveRegionName() {
- return (StringUtils.hasText(this.regionName) ? this.regionName
- : (StringUtils.hasText(this.name) ? this.name : getBeanName()));
- }
-
/**
* Returns a reference to the {@link GemFireCache} used to create the {@link Region}.
*
@@ -208,17 +224,14 @@ public abstract class RegionLookupFactoryBean extends AbstractFactoryBeanS
this.cache = cache;
}
- /* (non-Javadoc) */
- boolean isLookupEnabled() {
+ public boolean isLookupEnabled() {
return Boolean.TRUE.equals(getLookupEnabled());
}
- /* (non-Javadoc) */
public void setLookupEnabled(Boolean lookupEnabled) {
this.lookupEnabled = lookupEnabled;
}
- /* (non-Javadoc) */
public Boolean getLookupEnabled() {
return this.lookupEnabled;
}
diff --git a/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java
index 79331d4e..6fb56c3d 100644
--- a/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/ReplicatedRegionFactoryBean.java
@@ -17,6 +17,7 @@ package org.springframework.data.gemfire;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.RegionFactory;
+import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.util.Assert;
/**
@@ -27,6 +28,7 @@ public class ReplicatedRegionFactoryBean extends RegionFactoryBean {
@Override
protected void resolveDataPolicy(RegionFactory regionFactory, Boolean persistent, DataPolicy dataPolicy) {
+
if (dataPolicy == null) {
dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE);
}
@@ -41,7 +43,7 @@ public class ReplicatedRegionFactoryBean extends RegionFactoryBean {
}
// Validate that the data-policy and persistent attributes are compatible when both are specified!
- assertDataPolicyAndPersistentAttributesAreCompatible(dataPolicy);
+ RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent);
regionFactory.setDataPolicy(dataPolicy);
setDataPolicy(dataPolicy);
@@ -49,6 +51,7 @@ public class ReplicatedRegionFactoryBean extends RegionFactoryBean {
@Override
protected void resolveDataPolicy(RegionFactory regionFactory, Boolean persistent, String dataPolicy) {
+
DataPolicy resolvedDataPolicy = null;
if (dataPolicy != null) {
@@ -58,5 +61,4 @@ public class ReplicatedRegionFactoryBean extends RegionFactoryBean {
resolveDataPolicy(regionFactory, persistent, resolvedDataPolicy);
}
-
}
diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java
index ce96c984..6d3e5bcd 100644
--- a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java
@@ -25,7 +25,6 @@ import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -37,9 +36,6 @@ import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.distributed.DistributedSystem;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
@@ -122,21 +118,14 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
clientCacheConfigurer.configure(beanName, bean));
/**
- * Post processes this {@link ClientCacheFactoryBean} before cache initialization.
+ * Applies the composite {@link ClientCacheConfigurer ClientCacheConfigurers}
+ * to this {@link ClientCacheFactoryBean}.
*
- * This is also the point at which any configured {@link ClientCacheConfigurer} beans are called.
- *
- * @param gemfireProperties {@link Properties} used to configure Pivotal GemFire/Apache Geode.
- * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
- * @see java.util.Properties
+ * @see #getCompositeClientCacheConfigurer()
+ * @see #applyClientCacheConfigurers(ClientCacheConfigurer...)
*/
@Override
- protected void postProcessBeforeCacheInitialization(Properties gemfireProperties) {
- applyClientCacheConfigurers();
- }
-
- /* (non-Javadoc) */
- private void applyClientCacheConfigurers() {
+ protected void applyCacheConfigurers() {
applyClientCacheConfigurers(getCompositeClientCacheConfigurer());
}
@@ -221,12 +210,12 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
/**
* Constructs a new instance of {@link ClientCacheFactory} initialized with the given Pivotal GemFire/Apache Geode
- * {@link Properties} used to create an instance of a {@link ClientCache}.
+ * {@link Properties} used to construct, configure and initialize an instance of a {@link ClientCache}.
*
* @param gemfireProperties {@link Properties} used by the {@link ClientCacheFactory}
* to configure the {@link ClientCache}.
- * @return a new instance of {@link ClientCacheFactory} initialized with the given Pivotal GemFire/Apache Geode
- * {@link Properties}.
+ * @return a new instance of {@link ClientCacheFactory} initialized with
+ * the given Pivotal GemFire/Apache Geode {@link Properties}.
* @see org.apache.geode.cache.client.ClientCacheFactory
* @see java.util.Properties
*/
@@ -236,17 +225,19 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
/**
- * Prepares and initializes the {@link ClientCacheFactory} used to create the {@link ClientCache}.
+ * Configures the {@link ClientCacheFactory} used to create the {@link ClientCache}.
*
* Sets PDX options specified by the user.
*
+ * Sets Pool options specified by the user.
+ *
* @param factory {@link ClientCacheFactory} used to create the {@link ClientCache}.
- * @return the prepared and initialized {@link ClientCacheFactory}.
- * @see #initializePdx(ClientCacheFactory)
+ * @return the configured {@link ClientCacheFactory}.
+ * @see #configurePdx(ClientCacheFactory)
*/
@Override
- protected Object prepareFactory(Object factory) {
- return initializePool(initializePdx((ClientCacheFactory) factory));
+ protected Object configureFactory(Object factory) {
+ return configurePool(configurePdx((ClientCacheFactory) factory));
}
/**
@@ -256,7 +247,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @return the given {@link ClientCacheFactory}
* @see org.apache.geode.cache.client.ClientCacheFactory
*/
- ClientCacheFactory initializePdx(ClientCacheFactory clientCacheFactory) {
+ ClientCacheFactory configurePdx(ClientCacheFactory clientCacheFactory) {
Optional.ofNullable(getPdxSerializer()).ifPresent(clientCacheFactory::setPdxSerializer);
@@ -280,10 +271,10 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @see org.apache.geode.cache.client.ClientCacheFactory
* @see org.apache.geode.cache.client.Pool
*/
- ClientCacheFactory initializePool(ClientCacheFactory clientCacheFactory) {
+ ClientCacheFactory configurePool(ClientCacheFactory clientCacheFactory) {
- DefaultableDelegatingPoolAdapter pool = DefaultableDelegatingPoolAdapter.from(
- DelegatingPoolAdapter.from(resolvePool())).preferDefault();
+ DefaultableDelegatingPoolAdapter pool =
+ DefaultableDelegatingPoolAdapter.from(DelegatingPoolAdapter.from(resolvePool())).preferDefault();
clientCacheFactory.setPoolFreeConnectionTimeout(pool.getFreeConnectionTimeout(getFreeConnectionTimeout()));
clientCacheFactory.setPoolIdleTimeout(pool.getIdleTimeout(getIdleTimeout()));
@@ -291,8 +282,8 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
clientCacheFactory.setPoolMaxConnections(pool.getMaxConnections(getMaxConnections()));
clientCacheFactory.setPoolMinConnections(pool.getMinConnections(getMinConnections()));
clientCacheFactory.setPoolMultiuserAuthentication(pool.getMultiuserAuthentication(getMultiUserAuthentication()));
- clientCacheFactory.setPoolPRSingleHopEnabled(pool.getPRSingleHopEnabled(getPrSingleHopEnabled()));
clientCacheFactory.setPoolPingInterval(pool.getPingInterval(getPingInterval()));
+ clientCacheFactory.setPoolPRSingleHopEnabled(pool.getPRSingleHopEnabled(getPrSingleHopEnabled()));
clientCacheFactory.setPoolReadTimeout(pool.getReadTimeout(getReadTimeout()));
clientCacheFactory.setPoolRetryAttempts(pool.getRetryAttempts(getRetryAttempts()));
clientCacheFactory.setPoolServerGroup(pool.getServerGroup(getServerGroup()));
@@ -305,13 +296,14 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
clientCacheFactory.setPoolSubscriptionRedundancy(pool.getSubscriptionRedundancy(getSubscriptionRedundancy()));
clientCacheFactory.setPoolThreadLocalConnections(pool.getThreadLocalConnections(getThreadLocalConnections()));
- final AtomicBoolean noServers = new AtomicBoolean(getServers().isEmpty());
+ AtomicBoolean noServers = new AtomicBoolean(getServers().isEmpty());
- boolean hasServers = !noServers.get();
boolean noLocators = getLocators().isEmpty();
boolean hasLocators = !noLocators;
+ boolean hasServers = !noServers.get();
if (hasServers || noLocators) {
+
Iterable servers = pool.getServers(getServers().toInetSocketAddresses());
stream(servers.spliterator(), false).forEach(server -> {
@@ -321,6 +313,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
if (hasLocators || noServers.get()) {
+
Iterable locators = pool.getLocators(getLocators().toInetSocketAddresses());
stream(locators.spliterator(), false).forEach(locator ->
@@ -331,63 +324,58 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
/**
- * Resolves an appropriate {@link Pool} from the Spring container that will be used to configure
- * the {@link ClientCache}.
+ * Resolves the {@link Pool} used to configure the {@link ClientCache}, {@literal DEFAULT} {@link Pool}.
*
- * @return the resolved {@link Pool}.
+ * @return the resolved {@link Pool} used to configure the {@link ClientCache}, {@literal DEFAULT} {@link Pool}.
+ * @see org.apache.geode.cache.client.PoolManager#find(String)
* @see org.apache.geode.cache.client.Pool
+ * @see #getPoolName()
+ * @see #getPool()
* @see #findPool(String)
+ * @see #isPoolNameResolvable(String)
*/
Pool resolvePool() {
- Pool localPool = getPool();
+ Pool pool = getPool();
- if (localPool == null) {
+ if (pool == null) {
- String poolName = Optional.ofNullable(getPoolName()).filter(StringUtils::hasText)
- .orElse(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
+ String poolName = resolvePoolName();
- localPool = findPool(poolName);
+ pool = findPool(poolName);
- if (localPool == null) {
+ if (pool == null && isPoolNameResolvable(poolName)) {
- BeanFactory beanFactory = getBeanFactory();
+ String dereferencedPoolName = SpringUtils.dereferenceBean(poolName);
- if (beanFactory instanceof ListableBeanFactory) {
- try {
- Map poolFactoryBeanMap =
- ((ListableBeanFactory) beanFactory).getBeansOfType(PoolFactoryBean.class, false, false);
+ PoolFactoryBean poolFactoryBean =
+ getBeanFactory().getBean(dereferencedPoolName, PoolFactoryBean.class);
- String dereferencedPoolName = SpringUtils.dereferenceBean(poolName);
-
- if (poolFactoryBeanMap.containsKey(dereferencedPoolName)) {
- return poolFactoryBeanMap.get(dereferencedPoolName).getPool();
- }
- }
- catch (BeansException e) {
- logInfo("Unable to resolve bean of type [%1$s] with name [%2$s]",
- PoolFactoryBean.class.getName(), poolName);
- }
- }
+ return poolFactoryBean.getPool();
}
}
- return localPool;
+ return pool;
+ }
+
+ String resolvePoolName() {
+
+ return Optional.ofNullable(getPoolName())
+ .filter(StringUtils::hasText)
+ .orElse(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
}
- /**
- * Attempts to find a {@link Pool} with the given {@link String name}.
- *
- * @param name {@link String} containing the name of the {@link Pool} to find.
- * @return a {@link Pool} instance with the given {@link String name} registered in GemFire/Geode
- * or {@literal null} if no {@link Pool} with the given {@link String name} exists.
- * @see org.apache.geode.cache.client.PoolManager#find(String)
- * @see org.apache.geode.cache.client.Pool
- */
Pool findPool(String name) {
return PoolManager.find(name);
}
+ private boolean isPoolNameResolvable(String poolName) {
+
+ return Optional.ofNullable(poolName)
+ .filter(getBeanFactory()::containsBean)
+ .isPresent();
+ }
+
/**
* Creates a new {@link ClientCache} instance using the provided factory.
*
@@ -420,7 +408,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
this.fetchCache().readyForEvents();
}
catch (IllegalStateException | CacheClosedException ignore) {
- // thrown if clientCache.readyForEvents() is called on a non-durable client
+ // Thrown when clientCache.readyForEvents() is called on a non-durable client
}
}
}
@@ -449,22 +437,18 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
return Optional.ofNullable(getCache()).map(Object::getClass).orElse((Class) ClientCache.class);
}
- /* (non-Javadoc) */
public void addLocators(ConnectionEndpoint... locators) {
this.locators.add(locators);
}
- /* (non-Javadoc) */
public void addLocators(Iterable locators) {
this.locators.add(locators);
}
- /* (non-Javadoc) */
public void addServers(ConnectionEndpoint... servers) {
this.servers.add(servers);
}
- /* (non-Javadoc) */
public void addServers(Iterable servers) {
this.servers.add(servers);
}
@@ -546,36 +530,30 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
return this.durableClientTimeout;
}
- /* (non-Javadoc) */
@Override
public final void setEnableAutoReconnect(Boolean enableAutoReconnect) {
throw new UnsupportedOperationException("Auto-reconnect does not apply to clients");
}
- /* (non-Javadoc) */
@Override
public final Boolean getEnableAutoReconnect() {
return Boolean.FALSE;
}
- /* (non-Javadoc) */
public void setFreeConnectionTimeout(Integer freeConnectionTimeout) {
this.freeConnectionTimeout = freeConnectionTimeout;
}
- /* (non-Javadoc) */
public Integer getFreeConnectionTimeout() {
- return freeConnectionTimeout;
+ return this.freeConnectionTimeout;
}
- /* (non-Javadoc) */
public void setIdleTimeout(Long idleTimeout) {
this.idleTimeout = idleTimeout;
}
- /* (non-Javadoc) */
public Long getIdleTimeout() {
- return idleTimeout;
+ return this.idleTimeout;
}
/**
@@ -595,7 +573,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @return a boolean value indicating whether the server should keep the durable client's queues alive.
*/
public Boolean getKeepAlive() {
- return keepAlive;
+ return this.keepAlive;
}
/**
@@ -608,60 +586,49 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
return Boolean.TRUE.equals(getKeepAlive());
}
- /* (non-Javadoc) */
public void setLoadConditioningInterval(Integer loadConditioningInterval) {
this.loadConditioningInterval = loadConditioningInterval;
}
- /* (non-Javadoc) */
public Integer getLoadConditioningInterval() {
- return loadConditioningInterval;
+ return this.loadConditioningInterval;
}
- /* (non-Javadoc) */
public void setLocators(ConnectionEndpoint[] locators) {
setLocators(ConnectionEndpointList.from(locators));
}
- /* (non-Javadoc) */
public void setLocators(Iterable locators) {
getLocators().clear();
addLocators(locators);
}
- /* (non-Javadoc) */
protected ConnectionEndpointList getLocators() {
- return locators;
+ return this.locators;
}
- /* (non-Javadoc) */
public void setMaxConnections(Integer maxConnections) {
this.maxConnections = maxConnections;
}
- /* (non-Javadoc) */
public Integer getMaxConnections() {
- return maxConnections;
+ return this.maxConnections;
}
- /* (non-Javadoc) */
public void setMinConnections(Integer minConnections) {
this.minConnections = minConnections;
}
- /* (non-Javadoc) */
public Integer getMinConnections() {
- return minConnections;
+ return this.minConnections;
}
- /* (non-Javadoc) */
public void setMultiUserAuthentication(Boolean multiUserAuthentication) {
this.multiUserAuthentication = multiUserAuthentication;
}
- /* (non-Javadoc) */
public Boolean getMultiUserAuthentication() {
- return multiUserAuthentication;
+ return this.multiUserAuthentication;
}
/**
@@ -701,37 +668,31 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @return the name of the GemFire {@link Pool} used by this GemFire cache client.
*/
public String getPoolName() {
- return poolName;
+ return this.poolName;
}
- /* (non-Javadoc) */
public void setPingInterval(Long pingInterval) {
this.pingInterval = pingInterval;
}
- /* (non-Javadoc) */
public Long getPingInterval() {
- return pingInterval;
+ return this.pingInterval;
}
- /* (non-Javadoc) */
public void setPrSingleHopEnabled(Boolean prSingleHopEnabled) {
this.prSingleHopEnabled = prSingleHopEnabled;
}
- /* (non-Javadoc) */
public Boolean getPrSingleHopEnabled() {
- return prSingleHopEnabled;
+ return this.prSingleHopEnabled;
}
- /* (non-Javadoc) */
public void setReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
}
- /* (non-Javadoc) */
public Integer getReadTimeout() {
- return readTimeout;
+ return this.readTimeout;
}
/**
@@ -752,7 +713,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
* @return a boolean value indicating the state of the 'readyForEvents' property.
*/
public Boolean getReadyForEvents(){
- return readyForEvents;
+ return this.readyForEvents;
}
/**
@@ -780,129 +741,104 @@ public class ClientCacheFactoryBean extends CacheFactoryBean implements Applicat
}
}
- /* (non-Javadoc) */
public void setRetryAttempts(Integer retryAttempts) {
this.retryAttempts = retryAttempts;
}
- /* (non-Javadoc) */
public Integer getRetryAttempts() {
- return retryAttempts;
+ return this.retryAttempts;
}
- /* (non-Javadoc) */
public void setServerGroup(String serverGroup) {
this.serverGroup = serverGroup;
}
- /* (non-Javadoc) */
public String getServerGroup() {
- return serverGroup;
+ return this.serverGroup;
}
- /* (non-Javadoc) */
public void setServers(ConnectionEndpoint[] servers) {
setServers(ConnectionEndpointList.from(servers));
}
- /* (non-Javadoc) */
public void setServers(Iterable servers) {
getServers().clear();
addServers(servers);
}
- /* (non-Javadoc) */
protected ConnectionEndpointList getServers() {
- return servers;
+ return this.servers;
}
- /* (non-Javadoc) */
public void setSocketBufferSize(Integer socketBufferSize) {
this.socketBufferSize = socketBufferSize;
}
- /* (non-Javadoc) */
public Integer getSocketBufferSize() {
- return socketBufferSize;
+ return this.socketBufferSize;
}
- /* (non-Javadoc) */
public void setSocketConnectTimeout(Integer socketConnectTimeout) {
this.socketConnectTimeout = socketConnectTimeout;
}
- /* (non-Javadoc) */
public Integer getSocketConnectTimeout() {
return this.socketConnectTimeout;
}
- /* (non-Javadoc) */
public void setStatisticsInterval(Integer statisticsInterval) {
this.statisticsInterval = statisticsInterval;
}
- /* (non-Javadoc) */
public Integer getStatisticsInterval() {
- return statisticsInterval;
+ return this.statisticsInterval;
}
- /* (non-Javadoc) */
public void setSubscriptionAckInterval(Integer subscriptionAckInterval) {
this.subscriptionAckInterval = subscriptionAckInterval;
}
- /* (non-Javadoc) */
public Integer getSubscriptionAckInterval() {
- return subscriptionAckInterval;
+ return this.subscriptionAckInterval;
}
- /* (non-Javadoc) */
public void setSubscriptionEnabled(Boolean subscriptionEnabled) {
this.subscriptionEnabled = subscriptionEnabled;
}
- /* (non-Javadoc) */
public Boolean getSubscriptionEnabled() {
- return subscriptionEnabled;
+ return this.subscriptionEnabled;
}
- /* (non-Javadoc) */
public void setSubscriptionMessageTrackingTimeout(Integer subscriptionMessageTrackingTimeout) {
this.subscriptionMessageTrackingTimeout = subscriptionMessageTrackingTimeout;
}
- /* (non-Javadoc) */
public Integer getSubscriptionMessageTrackingTimeout() {
- return subscriptionMessageTrackingTimeout;
+ return this.subscriptionMessageTrackingTimeout;
}
- /* (non-Javadoc) */
public void setSubscriptionRedundancy(Integer subscriptionRedundancy) {
this.subscriptionRedundancy = subscriptionRedundancy;
}
- /* (non-Javadoc) */
public Integer getSubscriptionRedundancy() {
- return subscriptionRedundancy;
+ return this.subscriptionRedundancy;
}
- /* (non-Javadoc) */
public void setThreadLocalConnections(Boolean threadLocalConnections) {
this.threadLocalConnections = threadLocalConnections;
}
- /* (non-Javadoc) */
public Boolean getThreadLocalConnections() {
- return threadLocalConnections;
+ return this.threadLocalConnections;
}
- /* (non-Javadoc) */
@Override
public final void setUseClusterConfiguration(Boolean useClusterConfiguration) {
throw new UnsupportedOperationException("Cluster-based Configuration is not applicable for clients");
}
- /* (non-Javadoc) */
@Override
public final Boolean getUseClusterConfiguration() {
return Boolean.FALSE;
diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java
index 361e98f0..27e7d5a6 100644
--- a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java
@@ -19,20 +19,20 @@ package org.springframework.data.gemfire.client;
import static java.util.Arrays.stream;
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeCollection;
-import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.stream.StreamSupport;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.geode.cache.CacheListener;
import org.apache.geode.cache.CacheLoader;
import org.apache.geode.cache.CacheWriter;
+import org.apache.geode.cache.CustomExpiry;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
@@ -42,14 +42,16 @@ import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.compression.Compressor;
-import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
+import org.springframework.data.gemfire.ConfigurableRegionFactoryBean;
import org.springframework.data.gemfire.DataPolicyConverter;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.RegionLookupFactoryBean;
import org.springframework.data.gemfire.config.annotation.RegionConfigurer;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
+import org.springframework.data.gemfire.util.RegionUtils;
+import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -71,11 +73,11 @@ import org.springframework.util.StringUtils;
* @see org.springframework.beans.factory.DisposableBean
* @see org.springframework.beans.factory.FactoryBean
* @see org.springframework.data.gemfire.DataPolicyConverter
- * @see org.springframework.data.gemfire.RegionLookupFactoryBean
+ * @see RegionLookupFactoryBean
* @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
*/
@SuppressWarnings("unused")
-public class ClientRegionFactoryBean extends RegionLookupFactoryBean implements DisposableBean {
+public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean implements DisposableBean {
public static final String DEFAULT_POOL_NAME = "DEFAULT";
public static final String GEMFIRE_POOL_NAME = GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME;
@@ -83,7 +85,11 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
private boolean close = false;
private boolean destroy = false;
+ private Boolean cloningEnabled;
+ private Boolean concurrencyChecksEnabled;
+ private Boolean diskSynchronous;
private Boolean persistent;
+ private Boolean statisticsEnabled;
private CacheListener[] cacheListeners;
@@ -98,12 +104,25 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
private Compressor compressor;
+ private CustomExpiry customEntryIdleTimeout;
+ private CustomExpiry customEntryTimeToLive;
+
private DataPolicy dataPolicy;
private EvictionAttributes evictionAttributes;
+ private ExpirationAttributes entryIdleTimeout;
+ private ExpirationAttributes entryTimeToLive;
+ private ExpirationAttributes regionIdleTimeout;
+ private ExpirationAttributes regionTimeToLive;
+
+ private Integer concurrencyLevel;
+ private Integer initialCapacity;
+
private Interest[] interests;
+ private Float loadFactor;
+
private List regionConfigurers = Collections.emptyList();
private RegionAttributes attributes;
@@ -126,6 +145,8 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
* @param gemfireCache reference to the {@link GemFireCache}.
* @param regionName {@link String name} of the new {@link Region}.
* @return a new {@link Region} with the given {@link String name}.
+ * @see #createClientRegionFactory(ClientCache, ClientRegionShortcut)
+ * @see #newRegion(ClientRegionFactory, Region, String)
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
*/
@@ -139,109 +160,37 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
ClientRegionFactory clientRegionFactory =
postProcess(configure(createClientRegionFactory(clientCache, resolveClientRegionShortcut())));
- @SuppressWarnings("all")
- Region region = newRegion(clientRegionFactory, getParent(), regionName);
-
- return region;
- }
-
- /* (non-Javadoc) */
- private void applyRegionConfigurers(String regionName) {
- applyRegionConfigurers(regionName, getCompositeRegionConfigurer());
+ return newRegion(clientRegionFactory, getParent(), regionName);
}
/**
- * Null-safe operation to apply the given array of {@link RegionConfigurer RegionConfigurers}
- * to this {@link ClientRegionFactoryBean}.
+ * Constructs a new {@link Region} using the provided {@link ClientRegionFactory} as either
+ * a {@link Region root Region} or a {@link Region sub-Region} if {@link Region parent}
+ * is not {@literal null}.
*
- * @param regionName {@link String} containing the name of the {@link Region}.
- * @param regionConfigurers array of {@link RegionConfigurer RegionConfigurers} applied
- * to this {@link ClientRegionFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
- * @see #applyRegionConfigurers(String, Iterable)
+ * @param clientRegionFactory {@link ClientRegionFactory} containing the configuration
+ * for the new {@link Region}.
+ * @param parent {@link Region} designated as the parent of the new {@link Region}
+ * if the new {@link Region} is a {@link Region sub-Region}.
+ * @param regionName {@link String name} of the new {@link Region}.
+ * @return the new {@link Region} initialized with the given {@link String name}.
*/
- protected void applyRegionConfigurers(String regionName, RegionConfigurer... regionConfigurers) {
- applyRegionConfigurers(regionName, Arrays.asList(nullSafeArray(regionConfigurers, RegionConfigurer.class)));
- }
-
- /**
- * Null-safe operation to apply the given {@link Iterable} of {@link RegionConfigurer RegionConfigurers}
- * to this {@link ClientRegionFactoryBean}.
- *
- * @param regionName {@link String} containing the name of the {@link Region}.
- * @param regionConfigurers {@link Iterable} of {@link RegionConfigurer RegionConfigurers} applied
- * to this {@link ClientRegionFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
- */
- protected void applyRegionConfigurers(String regionName, Iterable regionConfigurers) {
- StreamSupport.stream(nullSafeIterable(regionConfigurers).spliterator(), false)
- .forEach(regionConfigurer -> regionConfigurer.configure(regionName, this));
- }
-
- /**
- * Assert the settings for {@link ClientRegionShortcut} and the {@literal persistent} attribute
- * in <gfe:*-region> elements are compatible.
- *
- * @param resolvedShortcut {@link ClientRegionShortcut} resolved from the SDG XML namespace.
- * @see org.springframework.data.gemfire.client.ClientRegionShortcutWrapper
- * @see org.apache.geode.cache.client.ClientRegionShortcut
- * @see #isNotPersistent()
- * @see #isPersistent()
- */
- private void assertClientRegionShortcutAndPersistentAttributeAreCompatible(ClientRegionShortcut resolvedShortcut) {
-
- final boolean persistentNotSpecified = (this.persistent == null);
-
- if (ClientRegionShortcutWrapper.valueOf(resolvedShortcut).isPersistent()) {
- Assert.isTrue(persistentNotSpecified || isPersistent(),
- String.format("Client Region Shortcut [%s] is not valid when persistent is false", resolvedShortcut));
- }
- else {
- Assert.isTrue(persistentNotSpecified || isNotPersistent(),
- String.format("Client Region Shortcut [%s] is not valid when persistent is true", resolvedShortcut));
- }
- }
-
- /**
- * Assert the settings for {@link DataPolicy} and the persistent attribute
- * in <gfe:*-region> elements are compatible.
- *
- * @param resolvedDataPolicy {@link DataPolicy} resolved from the SDG XML namespace.
- * @see org.apache.geode.cache.DataPolicy
- * @see #isNotPersistent()
- * @see #isPersistent()
- */
- private void assertDataPolicyAndPersistentAttributeAreCompatible(DataPolicy resolvedDataPolicy) {
-
- if (resolvedDataPolicy.withPersistence()) {
- Assert.isTrue(isPersistentUnspecified() || isPersistent(),
- String.format("Data Policy [%s] is not valid when persistent is false", resolvedDataPolicy));
- }
- else {
- Assert.isTrue(isPersistentUnspecified() || isNotPersistent(),
- String.format("Data Policy [%s] is not valid when persistent is true", resolvedDataPolicy));
- }
- }
-
- /* (non-Javadoc) */
private Region newRegion(ClientRegionFactory clientRegionFactory,
- Region, ?> parentRegion, String regionName) {
+ Region, ?> parent, String regionName) {
- return Optional.ofNullable(parentRegion)
- .map(parent -> {
- logInfo("Creating client Subregion [%1$s] with parent Region [%2$s]",
- regionName, parent.getName());
+ if (parent != null) {
- return clientRegionFactory.createSubregion(parent, regionName);
- })
- .orElseGet(() -> {
- logInfo("Created client Region [%s]", regionName);
+ logInfo("Creating client sub-Region [%1$s] with parent Region [%2$s]",
+ regionName, parent.getName());
- return clientRegionFactory.create(regionName);
- });
+ return clientRegionFactory.createSubregion(parent, regionName);
+ }
+ else {
+ logInfo("Creating client Region [%s]", regionName);
+ return clientRegionFactory.create(regionName);
+ }
}
- /* (non-Javadoc) */
private ClientCache resolveCache(GemFireCache gemfireCache) {
return Optional.ofNullable(gemfireCache)
@@ -251,9 +200,11 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
}
/**
- * Resolves the {@link ClientRegionShortcut} used to configure the {@link DataPolicy} of the client {@link Region}.
+ * Resolves the {@link ClientRegionShortcut} used to configure the {@link DataPolicy}
+ * for the {@link Region client Region}.
*
- * @return a {@link ClientRegionShortcut} used to configure the {@link DataPolicy} of the client {@link Region}.
+ * @return a {@link ClientRegionShortcut} used to configure the {@link DataPolicy}
+ * for the {@link Region client Region}.
* @see org.apache.geode.cache.client.ClientRegionShortcut
* @see org.apache.geode.cache.DataPolicy
*/
@@ -267,7 +218,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
if (dataPolicy != null) {
- assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy);
+ RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, this.persistent);
if (DataPolicy.EMPTY.equals(dataPolicy)) {
resolvedShortcut = ClientRegionShortcut.PROXY;
@@ -279,57 +230,48 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
resolvedShortcut = ClientRegionShortcut.LOCAL_PERSISTENT;
}
else {
- // NOTE the DataPolicy validation is based on the ClientRegionShortcut initialization logic
- // in org.apache.geode.internal.cache.GemFireCacheImpl.initializeClientRegionShortcuts
+ // NOTE: DataPolicy validation is based on the ClientRegionShortcut initialization logic
+ // in org.apache.geode.internal.cache.GemFireCacheImpl.initializeClientRegionShortcuts.
throw newIllegalArgumentException("Data Policy [%s] is not valid for a client Region", dataPolicy);
}
}
else {
- resolvedShortcut = (isPersistent() ? ClientRegionShortcut.LOCAL_PERSISTENT : ClientRegionShortcut.LOCAL);
+ resolvedShortcut = isPersistent() ? ClientRegionShortcut.LOCAL_PERSISTENT : ClientRegionShortcut.LOCAL;
}
}
- // NOTE the ClientRegionShortcut and Persistent attribute will be compatible
- // if the shortcut was derived from the Data Policy.
- assertClientRegionShortcutAndPersistentAttributeAreCompatible(resolvedShortcut);
+ // NOTE: The ClientRegionShortcut and Persistent attribute will be compatible
+ // if the shortcut was derived from the DataPolicy.
+ RegionUtils.assertClientRegionShortcutAndPersistentAttributeAreCompatible(resolvedShortcut, this.persistent);
return resolvedShortcut;
}
- /* (non-Javadoc) */
- private String resolvePoolName() {
+ private String resolvePoolName(String factoryPoolName, String attributesPoolName) {
- return getPoolName()
+ String resolvedPoolName = StringUtils.hasText(factoryPoolName) ? factoryPoolName : attributesPoolName;
+
+ return Optional.ofNullable(resolvedPoolName)
.filter(StringUtils::hasText)
- .filter(this::isNotDefaultPool)
- .filter(this::isPoolResolvable)
+ .filter(GemfireUtils::isNotDefaultPool)
+ .map(it -> {
+
+ Assert.isTrue(eagerlyInitializePool(it),
+ String.format("[%s] is not resolvable as a Pool in the application context", it));
+
+ return it;
+ })
.orElse(null);
}
- /* (non-Javadoc) */
- boolean isPoolResolvable(String poolName) {
- return getBeanFactory().containsBean(poolName) || (PoolManager.find(poolName) != null);
- }
+ @SuppressWarnings("all")
+ private boolean eagerlyInitializePool(String poolName) {
- /* (non-Javadoc) */
- boolean isNotDefaultPool(String poolName) {
- return !DEFAULT_POOL_NAME.equals(poolName);
- }
-
- /* (non-Javadoc) */
- private String eagerlyInitializePool(String poolName) {
-
- try {
- if (getBeanFactory().isTypeMatch(poolName, Pool.class)) {
- logDebug("Found bean definition for Pool [%s]; Eagerly initializing...", poolName);
- getBeanFactory().getBean(poolName, Pool.class);
- }
- }
- catch (BeansException ignore) {
- getLog().warn(ignore.getMessage(), ignore.getCause());
- }
-
- return poolName;
+ return Optional.ofNullable(PoolManager.find(poolName))
+ .map(it -> true)
+ .orElseGet(() ->
+ SpringUtils.safeGetValue(() ->
+ getBeanFactory().getBean(poolName, Pool.class) != null, false));
}
/**
@@ -337,81 +279,93 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
* and {@link ClientRegionShortcut}.
*
* @param clientCache reference to the {@link ClientCache}.
- * @param shortcut {@link ClientRegionShortcut} used to specify the client {@link Region} {@link DataPolicy}.
+ * @param clientRegionShortcut {@link ClientRegionShortcut} used to configure
+ * the {@link Region client Region} {@link DataPolicy}.
* @return a new instance of {@link ClientRegionFactory}.
* @see org.apache.geode.cache.client.ClientCache#createClientRegionFactory(ClientRegionShortcut)
* @see org.apache.geode.cache.client.ClientRegionShortcut
* @see org.apache.geode.cache.client.ClientRegionFactory
*/
protected ClientRegionFactory createClientRegionFactory(ClientCache clientCache,
- ClientRegionShortcut shortcut) {
+ ClientRegionShortcut clientRegionShortcut) {
- return clientCache.createClientRegionFactory(shortcut);
+ return clientCache.createClientRegionFactory(clientRegionShortcut);
}
/**
* Configures the given {@link ClientRegionFactoryBean} from the configuration settings
- * of this {@link ClientRegionFactoryBean}.
+ * of this {@link ClientRegionFactoryBean} and any {@link RegionAttributes}.
*
* @param clientRegionFactory {@link ClientRegionFactory} to configure.
- * @return the given {@link ClientRegionFactory}.
+ * @return the configured {@link ClientRegionFactory}.
* @see org.apache.geode.cache.client.ClientRegionFactory
*/
protected ClientRegionFactory configure(ClientRegionFactory clientRegionFactory) {
- Optional.ofNullable(this.attributes).ifPresent(attributes -> {
-
- stream(nullSafeArray(attributes.getCacheListeners(), CacheListener.class))
- .forEach(clientRegionFactory::addCacheListener);
-
- clientRegionFactory.setCloningEnabled(attributes.getCloningEnabled());
- clientRegionFactory.setCompressor(attributes.getCompressor());
- clientRegionFactory.setConcurrencyChecksEnabled(attributes.getConcurrencyChecksEnabled());
- clientRegionFactory.setConcurrencyLevel(attributes.getConcurrencyLevel());
- clientRegionFactory.setCustomEntryIdleTimeout(attributes.getCustomEntryIdleTimeout());
- clientRegionFactory.setCustomEntryTimeToLive(attributes.getCustomEntryTimeToLive());
- clientRegionFactory.setDiskStoreName(attributes.getDiskStoreName());
- clientRegionFactory.setDiskSynchronous(attributes.isDiskSynchronous());
- clientRegionFactory.setEntryIdleTimeout(attributes.getEntryIdleTimeout());
- clientRegionFactory.setEntryTimeToLive(attributes.getEntryTimeToLive());
- clientRegionFactory.setEvictionAttributes(attributes.getEvictionAttributes());
- clientRegionFactory.setInitialCapacity(attributes.getInitialCapacity());
- clientRegionFactory.setKeyConstraint(attributes.getKeyConstraint());
- clientRegionFactory.setLoadFactor(attributes.getLoadFactor());
- clientRegionFactory.setRegionIdleTimeout(attributes.getRegionIdleTimeout());
- clientRegionFactory.setRegionTimeToLive(attributes.getRegionTimeToLive());
- clientRegionFactory.setStatisticsEnabled(attributes.getStatisticsEnabled());
- clientRegionFactory.setValueConstraint(attributes.getValueConstraint());
-
- Optional.ofNullable(attributes.getPoolName())
- .filter(StringUtils::hasText)
- .filter(this::isNotDefaultPool)
- .filter(this::isPoolResolvable)
- .map(this::eagerlyInitializePool)
- .ifPresent(clientRegionFactory::setPoolName);
-
- });
+ Optional regionAttributesPoolName = configureWithRegionAttributes(clientRegionFactory);
stream(nullSafeArray(this.cacheListeners, CacheListener.class)).forEach(clientRegionFactory::addCacheListener);
+ Optional.ofNullable(this.cloningEnabled).ifPresent(clientRegionFactory::setCloningEnabled);
Optional.ofNullable(this.compressor).ifPresent(clientRegionFactory::setCompressor);
-
- Optional.ofNullable(this.diskStoreName).filter(StringUtils::hasText)
- .ifPresent(clientRegionFactory::setDiskStoreName);
-
+ Optional.ofNullable(this.concurrencyChecksEnabled).ifPresent(clientRegionFactory::setConcurrencyChecksEnabled);
+ Optional.ofNullable(this.concurrencyLevel).ifPresent(clientRegionFactory::setConcurrencyLevel);
+ Optional.ofNullable(this.customEntryIdleTimeout).ifPresent(clientRegionFactory::setCustomEntryIdleTimeout);
+ Optional.ofNullable(this.customEntryTimeToLive).ifPresent(clientRegionFactory::setCustomEntryTimeToLive);
+ Optional.ofNullable(this.diskStoreName).filter(StringUtils::hasText).ifPresent(clientRegionFactory::setDiskStoreName);
+ Optional.ofNullable(this.diskSynchronous).ifPresent(clientRegionFactory::setDiskSynchronous);
+ Optional.ofNullable(this.entryIdleTimeout).ifPresent(clientRegionFactory::setEntryIdleTimeout);
+ Optional.ofNullable(this.entryTimeToLive).ifPresent(clientRegionFactory::setEntryTimeToLive);
Optional.ofNullable(this.evictionAttributes).ifPresent(clientRegionFactory::setEvictionAttributes);
-
+ Optional.ofNullable(this.initialCapacity).ifPresent(clientRegionFactory::setInitialCapacity);
Optional.ofNullable(this.keyConstraint).ifPresent(clientRegionFactory::setKeyConstraint);
+ Optional.ofNullable(this.loadFactor).ifPresent(clientRegionFactory::setLoadFactor);
- Optional.ofNullable(resolvePoolName())
- .map(this::eagerlyInitializePool)
+ Optional.ofNullable(resolvePoolName(getPoolName().orElse(null), regionAttributesPoolName.orElse(null)))
.ifPresent(clientRegionFactory::setPoolName);
+ Optional.ofNullable(this.regionIdleTimeout).ifPresent(clientRegionFactory::setRegionIdleTimeout);
+ Optional.ofNullable(this.regionTimeToLive).ifPresent(clientRegionFactory::setRegionTimeToLive);
+ Optional.ofNullable(this.statisticsEnabled).ifPresent(clientRegionFactory::setStatisticsEnabled);
Optional.ofNullable(this.valueConstraint).ifPresent(clientRegionFactory::setValueConstraint);
return clientRegionFactory;
}
+ private Optional configureWithRegionAttributes(ClientRegionFactory clientRegionFactory) {
+
+ AtomicReference regionAttributesPoolName = new AtomicReference<>(null);
+
+ Optional.ofNullable(getAttributes()).ifPresent(regionAttributes -> {
+
+ regionAttributesPoolName.set(regionAttributes.getPoolName());
+
+ stream(nullSafeArray(regionAttributes.getCacheListeners(), CacheListener.class))
+ .forEach(clientRegionFactory::addCacheListener);
+
+ clientRegionFactory.setCloningEnabled(regionAttributes.getCloningEnabled());
+ clientRegionFactory.setCompressor(regionAttributes.getCompressor());
+ clientRegionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled());
+ clientRegionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel());
+ clientRegionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout());
+ clientRegionFactory.setCustomEntryTimeToLive(regionAttributes.getCustomEntryTimeToLive());
+ clientRegionFactory.setDiskStoreName(regionAttributes.getDiskStoreName());
+ clientRegionFactory.setDiskSynchronous(regionAttributes.isDiskSynchronous());
+ clientRegionFactory.setEntryIdleTimeout(regionAttributes.getEntryIdleTimeout());
+ clientRegionFactory.setEntryTimeToLive(regionAttributes.getEntryTimeToLive());
+ clientRegionFactory.setEvictionAttributes(regionAttributes.getEvictionAttributes());
+ clientRegionFactory.setInitialCapacity(regionAttributes.getInitialCapacity());
+ clientRegionFactory.setKeyConstraint(regionAttributes.getKeyConstraint());
+ clientRegionFactory.setLoadFactor(regionAttributes.getLoadFactor());
+ clientRegionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout());
+ clientRegionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive());
+ clientRegionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled());
+ clientRegionFactory.setValueConstraint(regionAttributes.getValueConstraint());
+ });
+
+ return Optional.ofNullable(regionAttributesPoolName.get()).filter(StringUtils::hasText);
+ }
+
/**
* Post-process the given {@link ClientRegionFactory} setup by this {@link ClientRegionFactoryBean}.
*
@@ -445,7 +399,6 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
return region;
}
- /* (non-Javadoc) */
@SuppressWarnings("unchecked")
private Region registerInterests(Region region) {
@@ -459,6 +412,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
region.registerInterest(((Interest) interest).getKey(), interest.getPolicy(),
interest.isDurable(), interest.isReceiveValues());
}
+
});
return region;
@@ -488,18 +442,8 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
if (isDestroy()) {
region.destroyRegion();
}
- });
- }
- /**
- * Returns a reference to the Composite {@link RegionConfigurer} used to apply additional configuration
- * to this {@link ClientRegionFactoryBean} on Spring container initialization.
- *
- * @return the Composite {@link RegionConfigurer}.
- * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
- */
- protected RegionConfigurer getCompositeRegionConfigurer() {
- return this.compositeRegionConfigurer;
+ });
}
/**
@@ -516,6 +460,17 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
this.attributes = attributes;
}
+ /**
+ * Gets the {@link RegionAttributes} used to configure the {@link Region client Region}
+ * created by this {@link ClientRegionFactoryBean}.
+ *
+ * @return the {@link RegionAttributes} used to configure the {@link Region client Region}.
+ * @see org.apache.geode.cache.RegionAttributes
+ */
+ protected RegionAttributes getAttributes() {
+ return this.attributes;
+ }
+
/**
* Sets the cache listeners used for the region used by this factory. Used
* only when a new region is created.Overrides the settings specified
@@ -547,7 +502,10 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
this.cacheWriter = cacheWriter;
}
- /* (non-Javadoc) */
+ public void setCloningEnabled(Boolean cloningEnabled) {
+ this.cloningEnabled = cloningEnabled;
+ }
+
final boolean isClose() {
return this.close;
}
@@ -575,6 +533,22 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
this.compressor = compressor;
}
+ public void setConcurrencyChecksEnabled(Boolean concurrencyChecksEnabled) {
+ this.concurrencyChecksEnabled = concurrencyChecksEnabled;
+ }
+
+ public void setConcurrencyLevel(Integer concurrencyLevel) {
+ this.concurrencyLevel = concurrencyLevel;
+ }
+
+ public void setCustomEntryIdleTimeout(CustomExpiry customEntryIdleTimeout) {
+ this.customEntryIdleTimeout = customEntryIdleTimeout;
+ }
+
+ public void setCustomEntryTimeToLive(CustomExpiry customEntryTimeToLive) {
+ this.customEntryTimeToLive = customEntryTimeToLive;
+ }
+
/**
* Sets the Data Policy. Used only when a new Region is created.
*
@@ -600,7 +574,6 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
setDataPolicy(resolvedDataPolicy);
}
- /* (non-Javadoc) */
final boolean isDestroy() {
return this.destroy;
}
@@ -615,7 +588,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
*/
public void setDestroy(boolean destroy) {
this.destroy = destroy;
- this.close = (this.close && !destroy); // retain previous value iff destroy is false;
+ this.close = this.close && !destroy; // retain previous value iff destroy is false;
}
/**
@@ -627,10 +600,26 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
this.diskStoreName = diskStoreName;
}
+ public void setDiskSynchronous(Boolean diskSynchronous) {
+ this.diskSynchronous = diskSynchronous;
+ }
+
+ public void setEntryIdleTimeout(ExpirationAttributes entryIdleTimeout) {
+ this.entryIdleTimeout = entryIdleTimeout;
+ }
+
+ public void setEntryTimeToLive(ExpirationAttributes entryTimeToLive) {
+ this.entryTimeToLive = entryTimeToLive;
+ }
+
public void setEvictionAttributes(EvictionAttributes evictionAttributes) {
this.evictionAttributes = evictionAttributes;
}
+ public void setInitialCapacity(Integer initialCapacity) {
+ this.initialCapacity = initialCapacity;
+ }
+
/**
* Set the interests for this client region. Both key and regex interest are
* supported.
@@ -641,17 +630,22 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
this.interests = interests;
}
- /* (non-Javadoc) */
Interest[] getInterests() {
return this.interests;
}
+ /**
+ * Sets a {@link Class type} constraint on this {@link Region client Region's} keys.
+ *
+ * @param keyConstraint {@link Class type} of this {@link Region client Region's} keys.
+ * @see java.lang.Class
+ */
public void setKeyConstraint(Class keyConstraint) {
this.keyConstraint = keyConstraint;
}
- protected boolean isPersistentUnspecified() {
- return (persistent == null);
+ public void setLoadFactor(Float loadFactor) {
+ this.loadFactor = loadFactor;
}
protected boolean isPersistent() {
@@ -662,14 +656,20 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
return Boolean.FALSE.equals(persistent);
}
- public void setPersistent(final boolean persistent) {
+ /**
+ * Configures whether this {@link Region client Region} is persistent, i.e. stores data to disk.
+ *
+ * @param persistent boolean value used to enable disk persistence.
+ */
+ public void setPersistent(boolean persistent) {
this.persistent = persistent;
}
/**
- * Sets the {@link Pool} used by this client {@link Region}.
+ * Configures the {@link Pool} used by this {@link Region client Region}.
*
- * @param pool client {@link Pool} to be used by this client {@link Region}.
+ * @param pool {@link Pool} used by this {@link Region client Region}
+ * to send/receive data to/from the server.
* @see org.apache.geode.cache.client.Pool
* @see #setPoolName(String)
*/
@@ -678,9 +678,10 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
}
/**
- * Sets the {@link String name} of the {@link Pool} used by this client {@link Region}.
+ * Configures the {@link String name} of the {@link Pool} used by this {@link Region client Region}.
*
- * @param poolName {@link String} containing the name of the client {@link Pool} used by this client {@link Region}.
+ * @param poolName {@link String} containing the name of the client {@link Pool}
+ * used by this {@link Region client Region}.
* @see #getPoolName()
* @see #setPool(Pool)
*/
@@ -689,55 +690,44 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean
}
/**
- * Returns the {@link String name} of the configured {@link Pool} to use with this client {@link Region}.
+ * Returns the {@link String name} of the configured {@link Pool} to use with this {@link Region client Region}.
*
* @return the {@link Optional} {@link String name} of the configured {@link Pool} to use
- * with this client {@link Region}.
+ * with this {@link Region client Region}.
* @see #setPoolName(String)
*/
public Optional getPoolName() {
return Optional.ofNullable(this.poolName);
}
- /**
- * Null-safe operation to set an array of {@link RegionConfigurer RegionConfigurers} used to apply
- * additional configuration to this {@link ClientRegionFactoryBean} when using Annotation-based configuration.
- *
- * @param regionConfigurers array of {@link RegionConfigurer RegionConfigurers} used to apply
- * additional configuration to this {@link ClientRegionFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
- * @see #setRegionConfigurers(List)
- */
- public void setRegionConfigurers(RegionConfigurer... regionConfigurers) {
- setRegionConfigurers(Arrays.asList(nullSafeArray(regionConfigurers, RegionConfigurer.class)));
+ public void setRegionIdleTimeout(ExpirationAttributes regionIdleTimeout) {
+ this.regionIdleTimeout = regionIdleTimeout;
+ }
+
+ public void setRegionTimeToLive(ExpirationAttributes regionTimeToLive) {
+ this.regionTimeToLive = regionTimeToLive;
}
/**
- * Null-safe operation to set an {@link Iterable} of {@link RegionConfigurer RegionConfigurers} used to apply
- * additional configuration to this {@link ClientRegionFactoryBean} when using Annotation-based configuration.
+ * Initializes the {@link DataPolicy} of the {@link Region client Region}
+ * using the given {@link ClientRegionShortcut}.
*
- * @param regionConfigurers {@link Iterable} of {@link RegionConfigurer RegionConfigurers} used to apply
- * additional configuration to this {@link ClientRegionFactoryBean}.
- * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
- */
- public void setRegionConfigurers(List regionConfigurers) {
- this.regionConfigurers = Optional.ofNullable(regionConfigurers).orElseGet(Collections::emptyList);
- }
-
- /**
- * Initializes the client {@link Region} using the given {@link ClientRegionShortcut}.
- *
- * @param shortcut {@link ClientRegionShortcut} used to initialize this client {@link Region}.
+ * @param shortcut {@link ClientRegionShortcut} used to initialize the {@link DataPolicy}
+ * of this {@link Region client Region}.
* @see org.apache.geode.cache.client.ClientRegionShortcut
*/
public void setShortcut(ClientRegionShortcut shortcut) {
this.shortcut = shortcut;
}
+ public void setStatisticsEnabled(Boolean statisticsEnabled) {
+ this.statisticsEnabled = statisticsEnabled;
+ }
+
/**
- * Sets a {@link Class type} constraint on this {@link Region Region's} values.
+ * Sets a {@link Class type} constraint on this {@link Region client Region's} values.
*
- * @param valueConstraint {@link Class type} of this client {@link Region Region's} values.
+ * @param valueConstraint {@link Class type} of this {@link Region client Region's} values.
* @see java.lang.Class
*/
public void setValueConstraint(Class valueConstraint) {
diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java
index 38015b1c..4b05eb7f 100644
--- a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java
+++ b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java
@@ -16,15 +16,14 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.management.internal.cli.domain.RegionInformation;
import org.apache.geode.management.internal.cli.functions.GetRegionsFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -52,7 +51,7 @@ import org.springframework.util.ObjectUtils;
*/
public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor {
- protected final Log logger = LogFactory.getLog(getClass());
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
private final ClientCache clientCache;
@@ -64,7 +63,10 @@ public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor
* @param clientCache the GemFire ClientCache instance.
* @see org.apache.geode.cache.client.ClientCache
*/
- public GemfireDataSourcePostProcessor(final ClientCache clientCache) {
+ public GemfireDataSourcePostProcessor(ClientCache clientCache) {
+
+ Assert.notNull(clientCache, "ClientCache must not be null");
+
this.clientCache = clientCache;
}
@@ -77,21 +79,24 @@ public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor
createClientRegionProxies(beanFactory, regionNames());
}
- /* (non-Javadoc) */
- // TODO remove this logic and delegate to o.s.d.g.config.remote.GemfireAdminOperations
+ // TODO: remove this logic and delegate to o.s.d.g.config.remote.GemfireAdminOperations
Iterable regionNames() {
+
try {
return execute(new ListRegionsOnServerFunction());
}
catch (Exception ignore) {
try {
+
Object results = execute(new GetRegionsFunction());
+
List regionNames = Collections.emptyList();
if (containsRegionInformation(results)) {
+
Object[] resultsArray = (Object[]) results;
- regionNames = new ArrayList(resultsArray.length);
+ regionNames = new ArrayList<>(resultsArray.length);
for (Object result : resultsArray) {
regionNames.add(((RegionInformation) result).getName());
@@ -100,39 +105,42 @@ public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor
return regionNames;
}
- catch (Exception e) {
- log("Failed to determine the Regions available on the Server: %n%1$s", e);
+ catch (Exception cause) {
+ log("Failed to determine the Regions available on the Server: %n%1$s", cause);
return Collections.emptyList();
}
}
}
- /* (non-Javadoc) */
@SuppressWarnings("unchecked")
T execute(Function gemfireFunction, Object... arguments) {
- return new GemfireOnServersFunctionTemplate(clientCache).executeAndExtract(gemfireFunction, arguments);
+ return new GemfireOnServersFunctionTemplate(this.clientCache).executeAndExtract(gemfireFunction, arguments);
}
- /* (non-Javadoc) */
boolean containsRegionInformation(Object results) {
- return (results instanceof Object[] && ((Object[]) results).length > 0
- && ((Object[]) results)[0] instanceof RegionInformation);
+ return results instanceof Object[] && ((Object[]) results).length > 0
+ && ((Object[]) results)[0] instanceof RegionInformation;
}
- /* (non-Javadoc) */
void createClientRegionProxies(ConfigurableListableBeanFactory beanFactory, Iterable regionNames) {
+
if (regionNames.iterator().hasNext()) {
- ClientRegionFactory, ?> clientRegionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
+
+ ClientRegionFactory, ?> clientRegionFactory =
+ this.clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
for (String regionName : regionNames) {
+
boolean createRegion = true;
if (beanFactory.containsBean(regionName)) {
+
Object existingBean = beanFactory.getBean(regionName);
- Assert.isTrue(existingBean instanceof Region, String.format(
- "Cannot create a client PROXY Region bean named '%1$s'. A bean with this name of type '%2$s' already exists.",
- regionName, ObjectUtils.nullSafeClassName(existingBean)));
+ if (logger.isWarnEnabled()) {
+ logger.warn("Cannot create a client PROXY Region bean named {}; A bean with name {} having type {} already exists",
+ regionName, regionName, ObjectUtils.nullSafeClassName(existingBean));
+ }
createRegion = false;
}
@@ -142,17 +150,15 @@ public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor
beanFactory.registerSingleton(regionName, clientRegionFactory.create(regionName));
}
else {
- log("A Region with name '%s' is already defined.", regionName);
+ log("A Region with name '%s' is already defined", regionName);
}
}
}
}
- /* (non-Javadoc) */
void log(String message, Object... arguments) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(message, arguments));
}
}
-
}
diff --git a/src/main/java/org/springframework/data/gemfire/client/PoolAdapter.java b/src/main/java/org/springframework/data/gemfire/client/PoolAdapter.java
index b57285ab..ca34dd10 100644
--- a/src/main/java/org/springframework/data/gemfire/client/PoolAdapter.java
+++ b/src/main/java/org/springframework/data/gemfire/client/PoolAdapter.java
@@ -24,13 +24,13 @@ import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.query.QueryService;
/**
- * The PoolAdapter class is an abstract, default no-op implementation of the GemFire {@link Pool} interface
- * that conveniently enables implementing classes to extend this adapter to adapt their interfaces and serve
- * as a {@link Pool}.
+ * The {@link PoolAdapter} class is an abstract base class and default, no-op implementation of
+ * the {@link Pool} interface that conveniently enables implementing classes to extend this adapter
+ * and choose which {@link Pool} methods/operations are supported by this implementation.
*
* For instance, one possible implementation is Spring Data GemFire's {@link PoolFactoryBean}, which can act as
* a {@link Pool} in a context where only the {@link Pool}'s "configuration" and meta-data are required,
- * but not actual connections or operating state information (e.g. pendingEventCount).
+ * but no actual connections or operating state information (e.g. pendingEventCount) is needed.
*
* @author John Blum
* @see org.springframework.data.gemfire.client.PoolFactoryBean
@@ -42,148 +42,119 @@ public abstract class PoolAdapter implements Pool {
public static final String NOT_IMPLEMENTED = "Not Implemented";
- /* (non-Javadoc) */
public boolean isDestroyed() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getFreeConnectionTimeout() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public long getIdleTimeout() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getLoadConditioningInterval() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public List getLocators() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getMaxConnections() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getMinConnections() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public boolean getMultiuserAuthentication() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public String getName() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
@Override
public List getOnlineLocators() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getPendingEventCount() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public long getPingInterval() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public boolean getPRSingleHopEnabled() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public QueryService getQueryService() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getReadTimeout() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getRetryAttempts() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public String getServerGroup() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public List getServers() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getSocketBufferSize() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getSocketConnectTimeout() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getStatisticInterval() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getSubscriptionAckInterval() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public boolean getSubscriptionEnabled() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getSubscriptionMessageTrackingTimeout() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public int getSubscriptionRedundancy() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public boolean getThreadLocalConnections() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public void destroy() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
- public void destroy(final boolean keepAlive) {
+ public void destroy(boolean keepAlive) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
- /* (non-Javadoc) */
public void releaseThreadLocalConnection() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
diff --git a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java
index 6b6d1cf3..a23ccc09 100644
--- a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java
@@ -21,6 +21,7 @@ import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeCollection;
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
+import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
import java.net.InetSocketAddress;
import java.util.Arrays;
@@ -75,8 +76,8 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
protected static final int DEFAULT_LOCATOR_PORT = DistributedSystemUtils.DEFAULT_LOCATOR_PORT;
protected static final int DEFAULT_SERVER_PORT = DistributedSystemUtils.DEFAULT_CACHE_SERVER_PORT;
- // indicates whether the Pool has been created internally (by this FactoryBean) or not
- volatile boolean springBasedPool = true;
+ // Indicates whether the Pool has been created by this FactoryBean, or not
+ volatile boolean springManagedPool = true;
// GemFire Pool Configuration Settings
private boolean keepAlive = false;
@@ -109,7 +110,7 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
private volatile Pool pool;
private PoolConfigurer compositePoolConfigurer = (beanName, bean) ->
- nullSafeCollection(poolConfigurers).forEach(poolConfigurer -> poolConfigurer.configure(beanName, bean));
+ nullSafeCollection(poolConfigurers).forEach(poolConfigurer -> poolConfigurer.configure(beanName, bean));
private PoolFactoryInitializer poolFactoryInitializer;
@@ -123,33 +124,44 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
* @see org.apache.geode.cache.client.PoolManager
* @see org.apache.geode.cache.client.PoolFactory
* @see org.apache.geode.cache.client.Pool
+ * @see #resolvePoolName()
*/
@Override
public void afterPropertiesSet() throws Exception {
- init(Optional.ofNullable(PoolManager.find(validatePoolName())));
- }
- /* (non-Javadoc) */
- @SuppressWarnings("all")
- private void init(Optional existingPool) {
+ Pool existingPool = find(resolvePoolName());
- if (existingPool.isPresent()) {
- this.pool = existingPool.get();
- this.springBasedPool = false;
+ if (existingPool != null) {
- logDebug(() -> String.format(
- "Pool with name [%s] already exists; Using existing Pool; Pool Configurers [%d] will not be applied",
- existingPool.get().getName(), this.poolConfigurers.size()));
+ this.pool = existingPool;
+ this.springManagedPool = false;
+
+ logDebug(() -> String.format("A Pool with name [%s] already exists; Using existing Pool",
+ this.pool.getName()));
+
+ logDebug("PoolConfigurers will not be applied");
}
else {
- this.springBasedPool = true;
+ logDebug("Pool [%s] not found; Lazily creating new Pool...", getName());
applyPoolConfigurers();
-
- logDebug("No Pool with name [%s] was found; Creating new Pool", getName());
}
}
- /* (non-Javadoc) */
+ private String resolvePoolName() {
+
+ if (!StringUtils.hasText(getName())) {
+ setName(Optional.ofNullable(getBeanName())
+ .filter(StringUtils::hasText)
+ .orElseThrow(() -> newIllegalArgumentException("Pool name is required")));
+ }
+
+ return getName();
+ }
+
+ private Pool find(String name) {
+ return PoolManager.find(name);
+ }
+
private void applyPoolConfigurers() {
applyPoolConfigurers(getCompositePoolConfigurer());
}
@@ -179,17 +191,6 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
.forEach(poolConfigurer -> poolConfigurer.configure(getName(), this));
}
- /* (non-Javadoc) */
- private String validatePoolName() {
-
- if (!StringUtils.hasText(getName())) {
- setName(Optional.ofNullable(getBeanName()).filter(StringUtils::hasText)
- .orElseThrow(() -> newIllegalArgumentException("Pool name is required")));
- }
-
- return getName();
- }
-
/**
* Releases all system resources and destroys the {@link Pool} when created by this {@link PoolFactoryBean}.
*
@@ -200,7 +201,7 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
public void destroy() throws Exception {
Optional.ofNullable(this.pool)
- .filter(pool -> this.springBasedPool)
+ .filter(pool -> this.springManagedPool)
.filter(pool -> !pool.isDestroyed())
.ifPresent(pool -> {
pool.releaseThreadLocalConnection();
@@ -210,17 +211,6 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
});
}
- /**
- * Returns a reference to the Composite {@link PoolConfigurer} used to apply additional configuration
- * to this {@link PoolFactoryBean} on Spring container initialization.
- *
- * @return the Composite {@link PoolConfigurer}.
- * @see org.springframework.data.gemfire.config.annotation.PoolConfigurer
- */
- protected PoolConfigurer getCompositePoolConfigurer() {
- return this.compositePoolConfigurer;
- }
-
/**
* Returns an object reference to the {@link Pool} created by this {@link PoolFactoryBean}.
*
@@ -233,28 +223,17 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
return Optional.ofNullable(this.pool).orElseGet(() -> {
- eagerlyInitializeClientCacheIfNotPresent();
+ eagerlyInitializeClientCache();
- PoolFactory poolFactory = configure(initialize(createPoolFactory()));
+ Pool namedPool = find(getName());
- this.pool = create(poolFactory, getName());
+ this.pool = namedPool != null ? namedPool
+ : postProcess(create(postProcess(configure(initialize(createPoolFactory()))), getName()));
return this.pool;
});
}
- /**
- * Determines whether the {@link DistributedSystem} exists yet or not.
- *
- * @return a boolean value indicating whether the single, {@link DistributedSystem} has already been created.
- * @see org.springframework.data.gemfire.GemfireUtils#getDistributedSystem()
- * @see org.springframework.data.gemfire.GemfireUtils#isConnected(DistributedSystem)
- * @see org.apache.geode.distributed.DistributedSystem
- */
- boolean isDistributedSystemPresent() {
- return GemfireUtils.isConnected(GemfireUtils.getDistributedSystem());
- }
-
/**
* Attempts to eagerly initialize the {@link ClientCache} if not already present so that a single
* {@link DistributedSystem} will exist, which is required to create a {@link Pool} instance.
@@ -262,14 +241,33 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
* @see org.springframework.beans.factory.BeanFactory#getBean(Class)
* @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.distributed.DistributedSystem
- * @see #isDistributedSystemPresent()
+ * @see #isClientCachePresent()
*/
- private void eagerlyInitializeClientCacheIfNotPresent() {
- if (!isDistributedSystemPresent()) {
+ private void eagerlyInitializeClientCache() {
+
+ if (!isClientCachePresent()) {
getBeanFactory().getBean(ClientCache.class);
}
}
+ /**
+ * Determines whether the {@link ClientCache} exists yet or not.
+ *
+ * @return a boolean value indicating whether the single {@link ClientCache} instance
+ * has been created yet.
+ * @see org.springframework.data.gemfire.GemfireUtils#getClientCache()
+ * @see org.apache.geode.distributed.DistributedSystem
+ * @see org.apache.geode.cache.client.ClientCache
+ */
+ boolean isClientCachePresent() {
+
+ return Optional.ofNullable(GemfireUtils.getClientCache())
+ .filter(clientCache -> !clientCache.isClosed())
+ .map(ClientCache::getDistributedSystem)
+ .filter(GemfireUtils::isConnected)
+ .isPresent();
+ }
+
/**
* Creates an instance of the {@link PoolFactory} interface to construct, configure and initialize a {@link Pool}.
*
@@ -336,6 +334,17 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
.orElse(poolFactory);
}
+ /**
+ * Post processes the fully configured {@link PoolFactory}.
+ *
+ * @param poolFactory {@link PoolFactory} to post process.
+ * @return the post processed {@link PoolFactory}.
+ * @see org.apache.geode.cache.client.PoolFactory
+ */
+ protected PoolFactory postProcess(PoolFactory poolFactory) {
+ return poolFactory;
+ }
+
/**
* Creates a {@link Pool} with the given {@link String name} using the provided {@link PoolFactory}.
*
@@ -350,61 +359,77 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
}
/**
- * Returns the {@link Class} type of the {@link Pool} produced by this {@link PoolFactoryBean}.
+ * Post processes the {@link Pool} created by this {@link PoolFactoryBean}.
*
- * @return the {@link Class} type of the {@link Pool} produced by this {@link PoolFactoryBean}.
+ * @param pool {@link Pool} to post process.
+ * @return the post processed {@link Pool}.
+ * @see org.apache.geode.cache.client.Pool
+ */
+ protected Pool postProcess(Pool pool) {
+ return pool;
+ }
+
+ /**
+ * Returns the {@link Class type} of {@link Pool} produced by this {@link PoolFactoryBean}.
+ *
+ * @return the {@link Class type} of {@link Pool} produced by this {@link PoolFactoryBean}.
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
@SuppressWarnings("unchecked")
public Class> getObjectType() {
- return Optional.ofNullable(this.pool).map(Pool::getClass).orElse((Class) Pool.class);
+ return this.pool != null ? this.pool.getClass() : Pool.class;
}
- /* (non-Javadoc) */
public void addLocators(ConnectionEndpoint... locators) {
this.locators.add(locators);
}
- /* (non-Javadoc) */
public void addLocators(Iterable locators) {
this.locators.add(locators);
}
- /* (non-Javadoc) */
public void addServers(ConnectionEndpoint... servers) {
this.servers.add(servers);
}
- /* (non-Javadoc) */
public void addServers(Iterable servers) {
this.servers.add(servers);
}
- /* (non-Javadoc) */
+ /**
+ * Returns a reference to the Composite {@link PoolConfigurer} used to apply additional configuration
+ * to this {@link PoolFactoryBean} on Spring container initialization.
+ *
+ * @return the Composite {@link PoolConfigurer}.
+ * @see org.springframework.data.gemfire.config.annotation.PoolConfigurer
+ */
+ protected PoolConfigurer getCompositePoolConfigurer() {
+ return this.compositePoolConfigurer;
+ }
+
public void setName(String name) {
this.name = name;
}
- /* (non-Javadoc) */
protected String getName() {
return this.name;
}
- /* (non-Javadoc) */
public void setPool(Pool pool) {
this.pool = pool;
}
- /* (non-Javadoc) */
public Pool getPool() {
return Optional.ofNullable(this.pool).orElseGet(() -> new PoolAdapter() {
@Override
public boolean isDestroyed() {
+
Pool pool = PoolFactoryBean.this.pool;
- return (pool != null && pool.isDestroyed());
+
+ return pool != null && pool.isDestroyed();
}
@Override
@@ -429,8 +454,10 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
@Override
public List getOnlineLocators() {
- return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getOnlineLocators)
- .orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
+
+ return Optional.ofNullable(PoolFactoryBean.this.pool)
+ .map(Pool::getOnlineLocators)
+ .orElseThrow(() -> newIllegalStateException("Pool [%s] has not been initialized", getName()));
}
@Override
@@ -450,14 +477,18 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
@Override
public String getName() {
- return Optional.ofNullable(PoolFactoryBean.this.getName()).filter(StringUtils::hasText)
+
+ return Optional.ofNullable(PoolFactoryBean.this.getName())
+ .filter(StringUtils::hasText)
.orElseGet(PoolFactoryBean.this::getBeanName);
}
@Override
public int getPendingEventCount() {
- return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getPendingEventCount)
- .orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
+
+ return Optional.ofNullable(PoolFactoryBean.this.pool)
+ .map(Pool::getPendingEventCount)
+ .orElseThrow(() -> newIllegalStateException("Pool [%s] has not been initialized", getName()));
}
@Override
@@ -472,8 +503,10 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
@Override
public QueryService getQueryService() {
- return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getQueryService)
- .orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
+
+ return Optional.ofNullable(PoolFactoryBean.this.pool)
+ .map(Pool::getQueryService)
+ .orElseThrow(() -> newIllegalStateException("Pool [%s] has not been initialized", getName()));
}
@Override
@@ -543,6 +576,7 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
@Override
public void destroy(boolean keepAlive) {
+
try {
PoolFactoryBean.this.destroy();
}
@@ -553,70 +587,58 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
@Override
public void releaseThreadLocalConnection() {
- Pool pool = PoolFactoryBean.this.pool;
- if (pool != null) {
- pool.releaseThreadLocalConnection();
- }
- else {
- throw new IllegalStateException("The Pool has not been initialized");
- }
+ Optional.ofNullable(PoolFactoryBean.this.pool)
+ .map(it -> {
+ it.releaseThreadLocalConnection();
+ return it;
+ })
+ .orElseThrow(() -> newIllegalStateException("Pool [%s] has not been initialized", getName()));
}
});
}
- /* (non-Javadoc) */
public void setFreeConnectionTimeout(int freeConnectionTimeout) {
this.freeConnectionTimeout = freeConnectionTimeout;
}
- /* (non-Javadoc) */
public void setIdleTimeout(long idleTimeout) {
this.idleTimeout = idleTimeout;
}
- /* (non-Javadoc) */
public void setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
}
- /* (non-Javadoc) */
public void setLoadConditioningInterval(int loadConditioningInterval) {
this.loadConditioningInterval = loadConditioningInterval;
}
- /* (non-Javadoc) */
public void setLocators(ConnectionEndpoint[] connectionEndpoints) {
setLocators(ConnectionEndpointList.from(connectionEndpoints));
}
- /* (non-Javadoc) */
public void setLocators(Iterable connectionEndpoints) {
getLocators().clear();
getLocators().add(connectionEndpoints);
}
- /* (non-Javadoc) */
ConnectionEndpointList getLocators() {
return locators;
}
- /* (non-Javadoc) */
public void setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections;
}
- /* (non-Javadoc) */
public void setMinConnections(int minConnections) {
this.minConnections = minConnections;
}
- /* (non-Javadoc) */
public void setMultiUserAuthentication(boolean multiUserAuthentication) {
this.multiUserAuthentication = multiUserAuthentication;
}
- /* (non-Javadoc) */
public void setPingInterval(long pingInterval) {
this.pingInterval = pingInterval;
}
@@ -658,78 +680,63 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport implements
this.poolFactoryInitializer = poolFactoryInitializer;
}
- /* (non-Javadoc) */
public void setPrSingleHopEnabled(boolean prSingleHopEnabled) {
this.prSingleHopEnabled = prSingleHopEnabled;
}
- /* (non-Javadoc) */
public void setReadTimeout(int readTimeout) {
this.readTimeout = readTimeout;
}
- /* (non-Javadoc) */
public void setRetryAttempts(int retryAttempts) {
this.retryAttempts = retryAttempts;
}
- /* (non-Javadoc) */
public void setServerGroup(String serverGroup) {
this.serverGroup = serverGroup;
}
- /* (non-Javadoc) */
public void setServers(ConnectionEndpoint[] connectionEndpoints) {
setServers(ConnectionEndpointList.from(connectionEndpoints));
}
- /* (non-Javadoc) */
public void setServers(Iterable connectionEndpoints) {
getServers().clear();
getServers().add(connectionEndpoints);
}
- /* (non-Javadoc) */
ConnectionEndpointList getServers() {
return servers;
}
- /* (non-Javadoc) */
public void setSocketBufferSize(int socketBufferSize) {
this.socketBufferSize = socketBufferSize;
}
- /* (non-Javadoc) */
public void setSocketConnectTimeout(int socketConnectTimeout) {
this.socketConnectTimeout = socketConnectTimeout;
}
- /* (non-Javadoc) */
public void setStatisticInterval(int statisticInterval) {
this.statisticInterval = statisticInterval;
}
- /* (non-Javadoc) */
public void setSubscriptionAckInterval(int subscriptionAckInterval) {
this.subscriptionAckInterval = subscriptionAckInterval;
}
- /* (non-Javadoc) */
public void setSubscriptionEnabled(boolean subscriptionEnabled) {
this.subscriptionEnabled = subscriptionEnabled;
}
- /* (non-Javadoc) */
public void setSubscriptionMessageTrackingTimeout(int subscriptionMessageTrackingTimeout) {
this.subscriptionMessageTrackingTimeout = subscriptionMessageTrackingTimeout;
}
- /* (non-Javadoc) */
public void setSubscriptionRedundancy(int subscriptionRedundancy) {
this.subscriptionRedundancy = subscriptionRedundancy;
}
- /* (non-Javadoc) */
public void setThreadLocalConnections(boolean threadLocalConnections) {
this.threadLocalConnections = threadLocalConnections;
}
diff --git a/src/main/java/org/springframework/data/gemfire/client/support/DefaultableDelegatingPoolAdapter.java b/src/main/java/org/springframework/data/gemfire/client/support/DefaultableDelegatingPoolAdapter.java
index 8322136e..4ac4253b 100644
--- a/src/main/java/org/springframework/data/gemfire/client/support/DefaultableDelegatingPoolAdapter.java
+++ b/src/main/java/org/springframework/data/gemfire/client/support/DefaultableDelegatingPoolAdapter.java
@@ -20,15 +20,18 @@ package org.springframework.data.gemfire.client.support;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.List;
+import java.util.function.Supplier;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.query.QueryService;
+import org.apache.shiro.util.CollectionUtils;
import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.util.Assert;
/**
- * The DefaultableDelegatingPoolAdapter class is a wrapper class around Pool allowing default configuration property
- * values to be providing in the case that the Pool's setting were null.
+ * The {@link DefaultableDelegatingPoolAdapter} class is a wrapper class around {@link Pool}
+ * allowing default configuration property values to be provided in the case that the {@link Pool Pool's}
+ * settings were {@literal null}.
*
* @author John Blum
* @see org.apache.geode.cache.client.Pool
@@ -41,221 +44,178 @@ public abstract class DefaultableDelegatingPoolAdapter {
private Preference preference = Preference.PREFER_POOL;
- /* (non-Javadoc) */
public static DefaultableDelegatingPoolAdapter from(Pool delegate) {
- return new DefaultableDelegatingPoolAdapter(delegate) { };
+ return new DefaultableDelegatingPoolAdapter(delegate) {};
}
- /* (non-Javadoc) */
protected DefaultableDelegatingPoolAdapter(Pool delegate) {
- Assert.notNull(delegate, "'delegate' must not be null");
+ Assert.notNull(delegate, "Pool delegate must not be null");
this.delegate = delegate;
}
- /* (non-Javadoc) */
protected Pool getDelegate() {
return this.delegate;
}
- /* (non-Javadoc) */
protected DefaultableDelegatingPoolAdapter setPreference(Preference preference) {
this.preference = preference;
return this;
}
- /* (non-Javadoc) */
protected Preference getPreference() {
return this.preference;
}
- /* (non-Javadoc) */
- protected T defaultIfNull(T defaultValue, ValueProvider valueProvider) {
- return (prefersPool() ? SpringUtils.defaultIfNull(valueProvider.getValue(), defaultValue) :
- (defaultValue != null ? defaultValue : valueProvider.getValue()));
+ protected T defaultIfNull(T defaultValue, Supplier valueProvider) {
+
+ return prefersPool() ? SpringUtils.defaultIfNull(valueProvider.get(), defaultValue) :
+ (defaultValue != null ? defaultValue : valueProvider.get());
}
- /* (non-Javadoc) */
- protected > T defaultIfEmpty(T defaultValue, ValueProvider valueProvider) {
+ protected