use of org.apache.geode.cache.ExpirationAction in project geode by apache.
the class RegionAlterFunction method parseExpirationAttributes.
/**
* Converts the expiration attributes passed as arguments from the command to the function into a
* type suitable for applying to a Region.
*
* @param newExpirationAttrs Attributes supplied by the command
* @param oldExpirationAttributes Attributes currently applied to the Region.
*
* @return A new pair of expiration attributes taken from the command if it was given or the
* current value from the Region if it was not.
*/
private ExpirationAttributes parseExpirationAttributes(RegionFunctionArgs.ExpirationAttrs newExpirationAttrs, ExpirationAttributes oldExpirationAttributes) {
ExpirationAction action = oldExpirationAttributes.getAction();
int timeout = oldExpirationAttributes.getTimeout();
if (newExpirationAttrs.getTime() != null) {
timeout = newExpirationAttrs.getTime();
}
if (newExpirationAttrs.getAction() != null) {
action = newExpirationAttrs.getAction();
}
return new ExpirationAttributes(timeout, action);
}
use of org.apache.geode.cache.ExpirationAction in project geode by apache.
the class ExpiryTask method expire.
protected boolean expire(boolean isPending) throws CacheException {
ExpirationAction action = getAction();
if (action == null)
return false;
boolean result = expire(action, isPending);
if (result && expiryTaskListener != null) {
expiryTaskListener.afterExpire(this);
}
return result;
}
use of org.apache.geode.cache.ExpirationAction in project geode by apache.
the class CacheXml66DUnitTest method testModifyRegionViaCacheXml.
/**
* Tests that loading cache XML can modify a region.
*/
@Test
public void testModifyRegionViaCacheXml() throws Exception {
CacheCreation creation = new CacheCreation();
int timeout1a = 123;
ExpirationAction action1a = ExpirationAction.LOCAL_DESTROY;
int timeout1b = 456;
ExpirationAction action1b = ExpirationAction.DESTROY;
RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1a, action1a));
Region root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1b, action1b));
Region subregion = root.createSubregion("subregion", attrs);
testXml(creation);
Cache cache = getCache();
root = cache.getRegion("root");
assertEquals(timeout1a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1a, root.getAttributes().getEntryIdleTimeout().getAction());
subregion = root.getSubregion("subregion");
assertEquals(timeout1b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1b, subregion.getAttributes().getEntryIdleTimeout().getAction());
creation = new CacheCreation();
int timeout2a = 234;
ExpirationAction action2a = ExpirationAction.LOCAL_INVALIDATE;
int timeout2b = 567;
ExpirationAction action2b = ExpirationAction.INVALIDATE;
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2a, action2a));
attrs.setCacheListener(new MyTestCacheListener());
root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2b, action2b));
subregion = root.createSubregion("subregion", attrs);
cache.loadCacheXml(generate(creation));
root = cache.getRegion("root");
subregion = root.getSubregion("subregion");
assertEquals(timeout2a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2a, root.getAttributes().getEntryIdleTimeout().getAction());
assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
assertEquals(timeout2b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2b, subregion.getAttributes().getEntryIdleTimeout().getAction());
}
use of org.apache.geode.cache.ExpirationAction in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for <code>ExpirationAttributes</code>
*/
private void generate(String kind, ExpirationAttributes attrs, CustomExpiry custom) throws SAXException {
if (attrs == null) {
return;
}
handler.startElement("", kind, kind, EMPTY);
int timeout = attrs.getTimeout();
ExpirationAction action = attrs.getAction();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", TIMEOUT, "", String.valueOf(timeout));
String actionString;
if (action.equals(ExpirationAction.DESTROY)) {
actionString = DESTROY;
} else if (action.equals(ExpirationAction.INVALIDATE)) {
actionString = INVALIDATE;
} else if (action.equals(ExpirationAction.LOCAL_DESTROY)) {
actionString = LOCAL_DESTROY;
} else if (action.equals(ExpirationAction.LOCAL_INVALIDATE)) {
actionString = LOCAL_INVALIDATE;
} else {
throw new InternalGemFireException(LocalizedStrings.CacheXmlGenerator_UNKNOWN_EXPIRATIONACTION_0.toLocalizedString(action));
}
atts.addAttribute("", "", ACTION, "", actionString);
handler.startElement("", EXPIRATION_ATTRIBUTES, EXPIRATION_ATTRIBUTES, atts);
if (custom != null) {
AttributesImpl endAtts = new AttributesImpl();
handler.startElement("", CUSTOM_EXPIRY, CUSTOM_EXPIRY, endAtts);
generate((Declarable) custom, false);
handler.endElement("", CUSTOM_EXPIRY, CUSTOM_EXPIRY);
}
handler.endElement("", EXPIRATION_ATTRIBUTES, EXPIRATION_ATTRIBUTES);
handler.endElement("", kind, kind);
}
Aggregations