use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class RegionHelper method getRegionAttributes.
private static RegionAttributes getRegionAttributes(Cache cache, RegionConfiguration configuration) {
// Create the requested attributes
RegionAttributes baseRequestedAttributes = cache.getRegionAttributes(configuration.getRegionAttributesId());
if (baseRequestedAttributes == null) {
throw new IllegalArgumentException("No region attributes named " + configuration.getRegionAttributesId() + " are defined.");
}
AttributesFactory requestedFactory = new AttributesFactory(baseRequestedAttributes);
// Set the expiration time and action if necessary
int maxInactiveInterval = configuration.getMaxInactiveInterval();
if (maxInactiveInterval != RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) {
requestedFactory.setStatisticsEnabled(true);
if (configuration.getCustomExpiry() == null) {
requestedFactory.setEntryIdleTimeout(new ExpirationAttributes(maxInactiveInterval, ExpirationAction.DESTROY));
} else {
requestedFactory.setCustomEntryIdleTimeout(configuration.getCustomExpiry());
}
}
// Add the gateway delta region cache listener if necessary
if (configuration.getEnableGatewayDeltaReplication()) {
// Add the listener that forwards created/destroyed deltas to the gateway
requestedFactory.addCacheListener(new GatewayDeltaForwarderCacheListener(cache));
}
// Add the debug cache listener if necessary
if (configuration.getEnableDebugListener()) {
requestedFactory.addCacheListener(new DebugCacheListener());
}
if (configuration.getSessionExpirationCacheListener()) {
requestedFactory.addCacheListener(new SessionExpirationCacheListener());
}
// Add the cacheWriter if necessary
if (configuration.getCacheWriterName() != null) {
try {
CacheWriter writer = (CacheWriter) Class.forName(configuration.getCacheWriterName()).newInstance();
requestedFactory.setCacheWriter(writer);
} catch (InstantiationException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not set a cacheWriter for the region", e);
}
}
return requestedFactory.create();
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class PdxOrderByJUnitTest method createRegion.
public Region createRegion(String name, String rootName, RegionAttributes attrs) throws CacheException {
Region root = getRootRegion(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 = createRootRegion(rootName, rootAttrs);
}
return root.createSubregion(name, attrs);
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class Bug35214DUnitTest method testNoEntryExpireDuringGII.
/**
* make sure entries do not expire during a GII
*/
@Test
public void testNoEntryExpireDuringGII() throws Exception {
initOtherVm();
AsyncInvocation updater = null;
try {
updater = updateOtherVm();
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable e1) {
Assert.fail("failed due to " + e1, e1);
}
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30;
callbackFailure = false;
try {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setStatisticsEnabled(true);
af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
CacheListener cl1 = new CacheListenerAdapter() {
public void afterRegionCreate(RegionEvent re) {
afterRegionCreateSeen = true;
}
public void afterInvalidate(EntryEvent e) {
callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen);
// make sure region is initialized
callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized());
expirationCount++;
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
}
};
af.addCacheListener(cl1);
final Region r1 = createRootRegion("r1", af.create());
ThreadUtils.join(updater, 60 * 1000);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return r1.values().size() == 0;
}
public String description() {
return "region never became empty";
}
};
Wait.waitForCriterion(ev, 2 * 1000, 200, true);
{
assertEquals(0, r1.values().size());
assertEquals(ENTRY_COUNT, r1.keySet().size());
}
} finally {
org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
}
assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class HARegionQueue method getHARegionQueueInstance.
/**
* Creates a HARegionQueue object with default attributes
*
* @param regionName uniquely identifies the HARegionQueue in the VM.For HARegionQueues across the
* VM to communicate with each other , the name should be identical
* @param cache Gemfire Cache instance
* @param hrqa HARegionQueueAttribute instance used for configuring the HARegionQueue
* @param haRgnQType int identifying whether the HARegionQueue is of type blocking or non blocking
* @param isPrimary whether this is the primary queue for the client
* @param canHandleDelta boolean indicating whether the HARegionQueue can handle delta or not
* @return an instance of HARegionQueue
*/
public static HARegionQueue getHARegionQueueInstance(String regionName, InternalCache cache, HARegionQueueAttributes hrqa, final int haRgnQType, final boolean isDurable, Map haContainer, ClientProxyMembershipID clientProxyId, final byte clientConflation, boolean isPrimary, boolean canHandleDelta) throws IOException, ClassNotFoundException, CacheException, InterruptedException {
HARegionQueue hrq = null;
switch(haRgnQType) {
case BLOCKING_HA_QUEUE:
if (!isDurable && !canHandleDelta) {
hrq = new BlockingHARegionQueue(regionName, cache, hrqa, haContainer, clientProxyId, clientConflation, isPrimary);
} else {
hrq = new DurableHARegionQueue(regionName, cache, hrqa, haContainer, clientProxyId, clientConflation, isPrimary);
}
break;
case NON_BLOCKING_HA_QUEUE:
hrq = new HARegionQueue(regionName, cache, hrqa, haContainer, clientProxyId, clientConflation, isPrimary);
break;
default:
throw new IllegalArgumentException(LocalizedStrings.HARegionQueue_HARGNQTYPE_CAN_EITHER_BE_BLOCKING_0_OR_NON_BLOCKING_1.toLocalizedString(new Object[] { BLOCKING_HA_QUEUE, NON_BLOCKING_HA_QUEUE }));
}
if (!isDurable) {
Integer expiryTime = Integer.getInteger(REGION_ENTRY_EXPIRY_TIME, hrqa.getExpiryTime());
hrqa.setExpiryTime(expiryTime);
ExpirationAttributes ea = new ExpirationAttributes(hrqa.getExpiryTime(), ExpirationAction.LOCAL_INVALIDATE);
hrq.region.getAttributesMutator().setEntryTimeToLive(ea);
}
return hrq;
}
use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.
the class CacheXmlParser method endEntryTimeToLive.
/**
* When a <code>entry-time-to-live</code> element is finished, an optional Declarable (the
* custom-expiry) is followed by the {@link ExpirationAttributes} are on top of the stack followed
* by either the {@link RegionAttributesCreation} to which the expiration attributes are assigned,
* or the attributes for a {@link PartitionAttributes} to which the attributes are assigned.
*/
private void endEntryTimeToLive() {
Declarable custom = null;
if (stack.peek() instanceof Declarable) {
custom = (Declarable) stack.pop();
}
ExpirationAttributes expire = (ExpirationAttributes) stack.pop();
Object a = stack.peek();
// } else
if (a instanceof RegionAttributesCreation) {
((RegionAttributesCreation) a).setEntryTimeToLive(expire);
if (custom != null) {
((RegionAttributesCreation) a).setCustomEntryTimeToLive((CustomExpiry) custom);
}
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_PARTITIONATTRIBUTES.toLocalizedString(ENTRY_TIME_TO_LIVE));
}
}
Aggregations