SGF-142
This commit is contained in:
@@ -284,6 +284,8 @@ abstract class ParsingUtils {
|
||||
result |= parseExpiration(element, "region-tti", "regionIdleTimeout", attrBuilder);
|
||||
result |= parseExpiration(element, "entry-ttl", "entryTimeToLive", attrBuilder);
|
||||
result |= parseExpiration(element, "entry-tti", "entryIdleTimeout", attrBuilder);
|
||||
result |= parseCustomExpiration(parserContext, element,"custom-entry-ttl","customEntryTimeToLive",attrBuilder);
|
||||
result |= parseCustomExpiration(parserContext, element,"custom-entry-tti","customEntryIdleTimeout",attrBuilder);
|
||||
|
||||
if (result) {
|
||||
// turn on statistics
|
||||
@@ -422,4 +424,18 @@ abstract class ParsingUtils {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean parseCustomExpiration(ParserContext parserContext, Element rootElement, String elementName, String propertyName,
|
||||
BeanDefinitionBuilder attrBuilder) {
|
||||
Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName);
|
||||
|
||||
if (expirationElement == null)
|
||||
return false;
|
||||
|
||||
Object customExpiry = parseRefOrSingleNestedBeanDeclaration(parserContext, expirationElement, attrBuilder);
|
||||
|
||||
attrBuilder.addPropertyValue(propertyName, customExpiry);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -756,22 +756,57 @@ Time to idle (or idle timeout) configuration for the region itself. Default: no
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="entry-ttl" type="expirationType"
|
||||
<xsd:choice>
|
||||
<xsd:element name="entry-ttl" type="expirationType"
|
||||
minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<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" type="expirationType"
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="custom-entry-ttl" type="customExpirationType"
|
||||
minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports
|
||||
type="com.gemstone.gemfire.cache.CustomExpiry" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation><![CDATA[[
|
||||
CustomExpiry time to live configuration for the region entries. Default: no expiration.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
|
||||
<xsd:choice>
|
||||
<xsd:element name="entry-tti" type="expirationType"
|
||||
minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<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:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="custom-entry-tti" type="customExpirationType"
|
||||
minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports
|
||||
type="com.gemstone.gemfire.cache.CustomExpiry" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation><![CDATA[[
|
||||
CustomExpiry Time to idle (or idle timeout) configuration for the region entries. Default: no expiration.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="load-factor" type="xsd:string"
|
||||
default="0.75">
|
||||
@@ -1361,6 +1396,28 @@ When the region or cached object expires, it is destroyed locally only. Not supp
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
<!-- -->
|
||||
<!-- -->
|
||||
<xsd:complexType name="customExpirationType">
|
||||
<xsd:sequence>
|
||||
<xsd:any namespace="##other" processContents="skip" minOccurs="0"
|
||||
maxOccurs="unbounded">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Inner bean definition of the CustomExpiry.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:any>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="ref" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the CustomExpiry bean referred by this declaration. Used as a convenience method. If no reference exists,
|
||||
use inner bean declarations.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
<!-- -->
|
||||
<xsd:complexType name="evictionType">
|
||||
<xsd:sequence minOccurs="0" maxOccurs="1">
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -39,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CustomExpiry;
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
@@ -47,6 +49,7 @@ import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.Region.Entry;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.util.ObjectSizer;
|
||||
@@ -99,6 +102,7 @@ public class DiskStoreAndEvictionRegionParsingTest {
|
||||
testReplicaDataOptions();
|
||||
testPartitionDataOptions();
|
||||
testEntryTtl();
|
||||
testCustomExpiry();
|
||||
}
|
||||
|
||||
private void testDiskStore() {
|
||||
@@ -170,4 +174,39 @@ public class DiskStoreAndEvictionRegionParsingTest {
|
||||
assertEquals(400, regionTTI.getTimeout());
|
||||
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void testCustomExpiry() throws Exception {
|
||||
assertTrue(context.containsBean("replicated-data-custom-expiry"));
|
||||
RegionFactoryBean fb = context.getBean("&replicated-data-custom-expiry", RegionFactoryBean.class);
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
|
||||
assertNotNull(attrs.getCustomEntryIdleTimeout());
|
||||
assertNotNull(attrs.getCustomEntryTimeToLive());
|
||||
|
||||
assertTrue(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry);
|
||||
assertTrue(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry);
|
||||
}
|
||||
|
||||
public static class TestCustomExpiry<K,V> implements CustomExpiry<K,V> {
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.CacheCallback#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.CustomExpiry#getExpiry(com.gemstone.gemfire.cache.Region.Entry)
|
||||
*/
|
||||
@Override
|
||||
public ExpirationAttributes getExpiry(Entry<K, V> entry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user