SGF-148 - Added 'close' property on CacheFactoryBean which, if false, will leave cache open when ApplicationContext closes

This commit is contained in:
David Turanski
2013-01-21 09:01:39 -05:00
parent 0e92a8f51d
commit 1e7ccc44b1
6 changed files with 84 additions and 3 deletions

View File

@@ -201,6 +201,8 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
protected String beanName;
protected boolean useBeanFactoryLocator = true;
protected boolean close = true;
// PDX options
protected Object pdxSerializer;
@@ -405,6 +407,9 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
@Override
public void destroy() throws Exception {
if (!close) {
return;
}
if (cache != null && !cache.isClosed()) {
cache.close();
}
@@ -614,6 +619,14 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
public void setCriticalHeapPercentage(Float criticalHeapPercentage) {
this.criticalHeapPercentage = criticalHeapPercentage;
}
/**
*
* @param close set to false if destroy() should not close the cache
*/
public void setClose(boolean close) {
this.close = close;
}
/**
*

View File

@@ -67,6 +67,7 @@ class CacheParser extends AbstractSimpleBeanDefinitionParser {
ParsingUtils.setPropertyValue(element, builder, "search-timeout");
ParsingUtils.setPropertyValue(element, builder, "critical-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "eviction-heap-percentage");
ParsingUtils.setPropertyValue(element, builder, "close");
List<Element> txListeners = DomUtils.getChildElementsByTagName(element, "transaction-listener");
if (!CollectionUtils.isEmpty(txListeners)) {

View File

@@ -239,6 +239,15 @@ JavaDocs for com.gemstone.gemfire.cache.control.ResourceManager for more informa
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="close" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[
Determines if the cache should be closed when the application context is closed. This value is
true by default but should be set to false if deploying multiple applications in a jvm that share the
same cache instance.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<!-- -->
<xsd:element name="cache">