+ add support for expiration attributes
This commit is contained in:
Costin Leau
2011-08-17 18:46:10 +03:00
parent d4870d0316
commit a9a7286f2d
9 changed files with 194 additions and 42 deletions

View File

@@ -1,35 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>head</name>
<comment></comment>
<projects>
</projects>
<name>spring-gemfire</name>
<comment>Spring GemFire</comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
<linkedResources/>
</projectDescription>

View File

@@ -1,13 +1,13 @@
#Sun Jun 06 11:27:13 EEST 2010
#
#Wed Aug 17 18:25:39 EEST 2011
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error

View File

@@ -3,7 +3,7 @@
<title>Spring GemFire Integration Schema</title>
<para>Spring GemFire Schema</para>
<programlisting language="xml"><xi:include href="../../../../../src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd" parse="text" xmlns:xi="http://www.w3.org/2001/XInclude">
<programlisting language="xml"><xi:include href="../../../../../src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd" parse="text" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:fallback>
<para><emphasis>FIXME: SGF SCHEMA LOCATION/NAME CHANGED</emphasis></para>
</xi:fallback>

View File

@@ -32,6 +32,8 @@ import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import com.gemstone.gemfire.cache.DiskWriteAttributesFactory;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
/**
* Various minor utility used by the parser.
@@ -66,7 +68,8 @@ abstract class ParsingUtils {
*/
static void addBeanAliasAsMetadata(Element element, BeanDefinitionBuilder builder) {
String[] aliases = new String[0];
String name = element.getAttributeNS(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI, AbstractBeanDefinitionParser.NAME_ATTRIBUTE);
String name = element.getAttributeNS(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI,
AbstractBeanDefinitionParser.NAME_ATTRIBUTE);
if (StringUtils.hasLength(name)) {
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
@@ -78,7 +81,8 @@ abstract class ParsingUtils {
static BeanDefinitionHolder replaceBeanAliasAsMetadata(BeanDefinitionHolder holder) {
BeanDefinition beanDefinition = holder.getBeanDefinition();
return new BeanDefinitionHolder(beanDefinition, holder.getBeanName(), (String[]) beanDefinition.removeAttribute(ALIASES_KEY));
return new BeanDefinitionHolder(beanDefinition, holder.getBeanName(),
(String[]) beanDefinition.removeAttribute(ALIASES_KEY));
}
/**
@@ -184,6 +188,7 @@ abstract class ParsingUtils {
/**
* Parses the eviction sub-element. Populates the given attribute factory with the proper attributes.
*
* @param parserContext
* @param element
* @param attrBuilder
* @return true if parsing actually occured, false otherwise
@@ -222,4 +227,64 @@ abstract class ParsingUtils {
static void parseStatistics(Element element, BeanDefinitionBuilder attrBuilder) {
setPropertyValue(element, attrBuilder, "statistics", "statisticsEnabled");
}
/**
* Parses the expiration sub-elements. Populates the given attribute factory with proper attributes.
*
* @param parserContext
* @param element
* @param attrBuilder
* @return
*/
static boolean parseExpiration(ParserContext parserContext, Element element, BeanDefinitionBuilder attrBuilder) {
boolean result = false;
result |= parseExpiration(element, "region-ttl", "regionTimeToLive", attrBuilder);
result |= parseExpiration(element, "region-tti", "regionIdleTimeout", attrBuilder);
result |= parseExpiration(element, "entry-ttl", "entryTimeToLive", attrBuilder);
result |= parseExpiration(element, "entry-tti", "entryIdleTimeout", attrBuilder);
if (result) {
// turn on statistics
attrBuilder.addPropertyValue("statisticsEnabled", Boolean.TRUE);
}
return result;
}
private static boolean parseExpiration(Element rootElement, String elementName, String propertyName, BeanDefinitionBuilder attrBuilder) {
Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
if (expirationElement == null)
return false;
int expirationTime = 0;
ExpirationAction action = ExpirationAction.INVALIDATE;
// do manual conversion since the enum is not public
String attr = expirationElement.getAttribute("timeout");
if (StringUtils.hasText(attr)) {
expirationTime = Integer.valueOf(attr);
}
attr = expirationElement.getAttribute("action");
if (StringUtils.hasText(attr)) {
// figure out action based on string length
attr = attr.trim();
if (attr.length() == 10) {
action = ExpirationAction.INVALIDATE;
}
else if (attr.length() == 7) {
action = ExpirationAction.DESTROY;
}
else if (attr.length() == 13) {
action = ExpirationAction.LOCAL_DESTROY;
}
else if (attr.length() == 16) {
action = ExpirationAction.LOCAL_INVALIDATE;
}
}
attrBuilder.addPropertyValue(propertyName, new ExpirationAttributes(expirationTime, action));
return true;
}
}

View File

@@ -76,6 +76,7 @@ class PartitionedRegionParser extends AliasReplacingBeanDefinitionParser {
// region attributes
BeanDefinitionBuilder attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class);
ParsingUtils.parseExpiration(parserContext, element, attrBuilder);
ParsingUtils.parseEviction(parserContext, element, attrBuilder);
ParsingUtils.parseDiskStorage(element, attrBuilder);
ParsingUtils.parseStatistics(element, attrBuilder);

View File

@@ -71,6 +71,7 @@ class ReplicatedRegionParser extends AliasReplacingBeanDefinitionParser {
attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr));
}
ParsingUtils.parseExpiration(parserContext, element, attrBuilder);
ParsingUtils.parseEviction(parserContext, element, attrBuilder);
ParsingUtils.parseDiskStorage(element, attrBuilder);

View File

@@ -92,7 +92,6 @@ across concurrent threads in the same VM, whether or not transactions are used.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
@@ -281,6 +280,35 @@ arbitrarily pick one.
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="region-ttl" minOccurs="0" maxOccurs="1" type="expirationType">
<xsd:annotation>
<xsd:documentation><![CDATA[[
Time to live configuration for the region itself. Default: no expiration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="region-tti" minOccurs="0" maxOccurs="1" type="expirationType">
<xsd:annotation>
<xsd:documentation><![CDATA[[
Time to idle (or idle timeout) configuration for the region itself. Default: no expiration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="entry-ttl" minOccurs="0" maxOccurs="1" type="expirationType">
<xsd:annotation>
<xsd:documentation><![CDATA[[
Time to live configuration for the region entries. Default: no expiration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="entry-tti" minOccurs="0" maxOccurs="1" type="expirationType">
<xsd:annotation>
<xsd:documentation><![CDATA[[
Time to idle (or idle timeout) configuration for the region entries. Default: no expiration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
@@ -317,7 +345,7 @@ up to date copy of the data.
<xsd:element name="eviction" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Eviction policy for the partitioned region.
Eviction policy for the replicated region.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
@@ -466,6 +494,50 @@ The delay in milliseconds that new members will wait before satisfying redundanc
</xsd:complexType>
</xsd:element>
<xsd:complexType name="expirationType">
<xsd:attribute name="timeout" type="xsd:string" default="0">
<xsd:annotation>
<xsd:documentation><![CDATA[
The amount of time before the expiration action takes place. Defaults to zero (which means never timeout).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="action" default="INVALIDATE">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="INVALIDATE">
<xsd:annotation>
<xsd:documentation><![CDATA[
When the region or cached object expires, it is invalidated.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="DESTROY">
<xsd:annotation>
<xsd:documentation><![CDATA[
When the region or cached object expires, it is destroyed.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="LOCAL_INVALIDATE">
<xsd:annotation>
<xsd:documentation><![CDATA[
When the region or cached object expires, it is invalidated locally only. Not supported on partitioned regions.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="LOCAL_DESTROY">
<xsd:annotation>
<xsd:documentation><![CDATA[
When the region or cached object expires, it is destroyed locally only. Not supported on partitioned regions.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="evictionType">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element name="object-sizer" type="beanDeclarationType">

View File

@@ -36,6 +36,8 @@ import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.EvictionAttributes;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.util.ObjectSizer;
@@ -85,4 +87,28 @@ public class DiskStoreAndEvictionRegionParsingTest {
ObjectSizer sizer = evicAttr.getObjectSizer();
assertEquals(SimpleObjectSizer.class, sizer.getClass());
}
@Test
public void testEntryTtl() throws Exception {
assertTrue(context.containsBean("replicated-data"));
RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class);
RegionAttributes attrs = TestUtils.readField("attributes", fb);
ExpirationAttributes entryTTL = attrs.getEntryTimeToLive();
assertEquals(100, entryTTL.getTimeout());
assertEquals(ExpirationAction.DESTROY, entryTTL.getAction());
ExpirationAttributes entryTTI = attrs.getEntryIdleTimeout();
assertEquals(200, entryTTI.getTimeout());
assertEquals(ExpirationAction.INVALIDATE, entryTTI.getAction());
ExpirationAttributes regionTTL = attrs.getRegionTimeToLive();
assertEquals(300, regionTTL.getTimeout());
assertEquals(ExpirationAction.DESTROY, regionTTL.getAction());
ExpirationAttributes regionTTI = attrs.getRegionIdleTimeout();
assertEquals(400, regionTTI.getTimeout());
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
}
}

View File

@@ -15,6 +15,12 @@
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
<gfe:region-ttl timeout="300" action="DESTROY"/>
<gfe:region-tti timeout="400" action="INVALIDATE"/>
<gfe:entry-ttl timeout="100" action="DESTROY"/>
<gfe:entry-tti timeout="200" action="INVALIDATE"/>
<gfe:eviction type="ENTRY_COUNT" threshold="50" />
</gfe:replicated-region>