Search in sources :

Example 1 with ExpirationAction

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);
}
Also used : ExpirationAction(org.apache.geode.cache.ExpirationAction) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 2 with ExpirationAction

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;
}
Also used : ExpirationAction(org.apache.geode.cache.ExpirationAction)

Example 3 with ExpirationAction

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());
}
Also used : ExpirationAction(org.apache.geode.cache.ExpirationAction) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 4 with ExpirationAction

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);
}
Also used : DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ExpirationAction(org.apache.geode.cache.ExpirationAction) InternalGemFireException(org.apache.geode.InternalGemFireException)

Aggregations

ExpirationAction (org.apache.geode.cache.ExpirationAction)4 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)2 InternalGemFireException (org.apache.geode.InternalGemFireException)1 Cache (org.apache.geode.cache.Cache)1 Region (org.apache.geode.cache.Region)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)1 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)1 Test (org.junit.Test)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1