Search in sources :

Example 1 with GatewayDeltaForwarderCacheListener

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();
}
Also used : GatewayDeltaForwarderCacheListener(org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener) RegionAttributes(org.apache.geode.cache.RegionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) SessionExpirationCacheListener(org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener) CacheWriter(org.apache.geode.cache.CacheWriter) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 GatewayDeltaForwarderCacheListener (org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener)1 SessionExpirationCacheListener (org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener)1