Search in sources :

Example 41 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class CacheXmlParser method startExpirationAttributes.

/**
   * When a <code>expiration-attributes</code> element is first encountered, we create an
   * ExpirationAttibutes?? object from the element's attributes and push it on the stack.
   */
private void startExpirationAttributes(Attributes atts) {
    int timeout = parseInt(atts.getValue(TIMEOUT));
    String action = atts.getValue(ACTION);
    ExpirationAttributes expire;
    if (action == null) {
        expire = new ExpirationAttributes(timeout);
    } else if (action.equals(INVALIDATE)) {
        expire = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
    } else if (action.equals(DESTROY)) {
        expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
    } else if (action.equals(LOCAL_INVALIDATE)) {
        expire = new ExpirationAttributes(timeout, ExpirationAction.LOCAL_INVALIDATE);
    } else if (action.equals(LOCAL_DESTROY)) {
        expire = new ExpirationAttributes(timeout, ExpirationAction.LOCAL_DESTROY);
    } else {
        throw new InternalGemFireException(LocalizedStrings.CacheXmlParser_UNKNOWN_EXPIRATION_ACTION_0.toLocalizedString(action));
    }
    stack.push(expire);
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 42 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes 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 43 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class RemoteTransactionDUnitTest method testExpirySuspend_bug45984.

@Test
public void testExpirySuspend_bug45984() {
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String regionName = getName();
    // create region with expiration
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
            try {
                RegionFactory<String, String> rf = getCache().createRegionFactory();
                rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
                rf.setScope(Scope.DISTRIBUTED_ACK);
                rf.create(regionName);
            } finally {
                System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
            }
            return null;
        }
    });
    // create replicate region
    vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            final Region<String, String> r = getCache().getRegion(regionName);
            WaitCriterion wc2 = new WaitCriterion() {

                @Override
                public boolean done() {
                    return !r.containsKey("key") && !r.containsKey("nonTXKey");
                }

                @Override
                public String description() {
                    return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
                }
            };
            ExpiryTask.suspendExpiration();
            Region.Entry entry = null;
            long tilt;
            try {
                r.put("key", "value");
                LocalRegion lr = (LocalRegion) r;
                r.put("nonTXkey", "nonTXvalue");
                getCache().getCacheTransactionManager().begin();
                r.put("key", "newvalue");
                TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
            } finally {
                ExpiryTask.permitExpiration();
            }
            TransactionId tx = getCache().getCacheTransactionManager().suspend();
            // A remote tx will allow expiration to happen on the side that
            // is not hosting the tx. But it will not allow an expiration
            // initiated on the hosting jvm.
            // tx is hosted in vm2 so expiration can happen in vm1.
            Wait.waitForCriterion(wc2, 30000, 5, true);
            getCache().getCacheTransactionManager().resume(tx);
            assertTrue(r.containsKey("key"));
            getCache().getCacheTransactionManager().commit();
            Wait.waitForCriterion(wc2, 30000, 5, true);
            return null;
        }
    });
}
Also used : Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) TransactionId(org.apache.geode.cache.TransactionId) Entry(org.apache.geode.cache.Region.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 44 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class Bug47388DUnitTest method createCacheServerWithPRDatastore.

@SuppressWarnings("deprecation")
public static Integer createCacheServerWithPRDatastore() throws Exception {
    Properties props = new Properties();
    Bug47388DUnitTest test = new Bug47388DUnitTest();
    DistributedSystem ds = test.getSystem(props);
    ds.disconnect();
    cache = (GemFireCacheImpl) CacheFactory.create(test.getSystem());
    RegionFactory<String, String> rf = cache.createRegionFactory(RegionShortcut.PARTITION);
    rf.setEntryTimeToLive(new ExpirationAttributes(3, ExpirationAction.DESTROY)).setPartitionAttributes(new PartitionAttributesFactory<String, String>().setRedundantCopies(1).setTotalNumBuckets(4).create()).setConcurrencyChecksEnabled(false);
    rf.create(REGION_NAME);
    CacheServer server = cache.addCacheServer();
    server.setPort(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
    server.start();
    return server.getPort();
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 45 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class CQListGIIDUnitTest method createRegion.

public static Region createRegion(String name, String rootName, RegionAttributes attrs) throws CacheException {
    Region root = cache.getRegion(rootName);
    if (root == null) {
        // don't put listeners on root region
        RegionAttributes rootAttrs = attrs;
        AttributesFactory fac = new AttributesFactory(attrs);
        ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
        // fac.setCacheListener(null);
        fac.setCacheLoader(null);
        fac.setCacheWriter(null);
        fac.setPoolName(null);
        fac.setPartitionAttributes(null);
        fac.setRegionTimeToLive(expiration);
        fac.setEntryTimeToLive(expiration);
        fac.setRegionIdleTimeout(expiration);
        fac.setEntryIdleTimeout(expiration);
        rootAttrs = fac.create();
        root = cache.createRegion(rootName, rootAttrs);
    }
    return createSubregion(root, name, attrs, null);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Aggregations

ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)84 Region (org.apache.geode.cache.Region)51 AttributesFactory (org.apache.geode.cache.AttributesFactory)50 Test (org.junit.Test)50 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 LocalRegion (org.apache.geode.internal.cache.LocalRegion)41 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)35 Entry (org.apache.geode.cache.Region.Entry)21 EntryEvent (org.apache.geode.cache.EntryEvent)15 CacheException (org.apache.geode.cache.CacheException)12 AttributesMutator (org.apache.geode.cache.AttributesMutator)11 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)11 Host (org.apache.geode.test.dunit.Host)11 VM (org.apache.geode.test.dunit.VM)11 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)11 Properties (java.util.Properties)10 EntryExpiryTask (org.apache.geode.internal.cache.EntryExpiryTask)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 Cache (org.apache.geode.cache.Cache)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8