Skip to content

Commit

Permalink
Enable the close() operation on GemFireCache to be configurable via S…
Browse files Browse the repository at this point in the history
…pringProperties and Java System properties.

Add default constant value declarations for cache close and the bean phase to the AbstractBasicCacheFactoryBean class.

Resolves spring-projectsgh-537.
  • Loading branch information
jxblum committed Oct 27, 2021
1 parent 713272c commit 1d303af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@
public abstract class AbstractBasicCacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
implements DisposableBean, InitializingBean, PersistenceExceptionTranslator, Phased {

private boolean close = true;
protected static final boolean DEFAULT_CACHE_CLOSE = true;

private int phase = -1;
protected static final int DEFAULT_PHASE = -1;

private boolean close = DEFAULT_CACHE_CLOSE;

private int phase = DEFAULT_PHASE;

private Boolean copyOnRead;
private Boolean pdxIgnoreUnreadFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import org.apache.geode.cache.client.ClientCache;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.SpringProperties;
import org.springframework.core.io.Resource;
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

/**
* Abstract base class encapsulating functionality for (externally) configuring an Apache Geode {@link ClientCache}
Expand All @@ -45,6 +47,7 @@
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.core.SpringProperties
* @see org.springframework.core.io.Resource
* @see org.springframework.data.gemfire.AbstractBasicCacheFactoryBean
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
Expand All @@ -53,6 +56,8 @@
@SuppressWarnings("unused")
public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasicCacheFactoryBean {

protected static final String SPRING_DATA_GEMFIRE_CACHE_CLOSE_PROPERTY = "spring.data.gemfire.cache.close";

private boolean useBeanFactoryLocator = false;

private GemfireBeanFactoryLocator beanFactoryLocator;
Expand Down Expand Up @@ -154,6 +159,29 @@ protected boolean isCacheXmlResolvableAsAFile() {
return getOptionalCacheXml().filter(Resource::isFile).isPresent();
}

/**
* Returns a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.
*
* Defaults to {@literal true}.
*
* Can be configured via {@literal spring.data.gemfire.cache.close} property in {@literal spring.properties}
* or as a {@link System#getProperty(String, String) System property}.
*
* @return a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.
*/
@Override
public boolean isClose() {

String springDataGemfireCacheCloseProperty =
SpringProperties.getProperty(SPRING_DATA_GEMFIRE_CACHE_CLOSE_PROPERTY);
//System.getProperty(SPRING_DATA_GEMFIRE_CACHE_CLOSE_PROPERTY, String.valueOf(DEFAULT_CACHE_CLOSE));

boolean closeProperty = !StringUtils.hasText(springDataGemfireCacheCloseProperty)
|| Boolean.parseBoolean(springDataGemfireCacheCloseProperty);

return closeProperty && super.isClose();
}

/**
* Sets and then returns a reference to Apache Geode {@link Properties} used to configure the cache.
*
Expand Down

0 comments on commit 1d303af

Please sign in to comment.