use of org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener 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();
}
Aggregations