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);
}
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);
}
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;
}
});
}
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();
}
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);
}
Aggregations