Search in sources :

Example 1 with SessionExpirationCacheListener

use of org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener 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)

Example 2 with SessionExpirationCacheListener

use of org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener in project geode by apache.

the class PeerToPeerSessionCache method createOrRetrieveLocalRegion.

private Region<String, HttpSession> createOrRetrieveLocalRegion() {
    // Attempt to retrieve the fronting region
    String frontingRegionName = this.sessionRegion.getName() + "_local";
    Region<String, HttpSession> frontingRegion = this.cache.getRegion(frontingRegionName);
    if (frontingRegion == null) {
        // Create the region factory
        RegionFactory<String, HttpSession> factory = this.cache.createRegionFactory(RegionShortcut.LOCAL_HEAP_LRU);
        // Add the cache loader and writer
        factory.setCacheLoader(new LocalSessionCacheLoader(this.sessionRegion));
        factory.setCacheWriter(new LocalSessionCacheWriter(this.sessionRegion));
        // Set the expiration time, action and listener if necessary
        int maxInactiveInterval = getSessionManager().getMaxInactiveInterval();
        if (maxInactiveInterval != RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) {
            factory.setStatisticsEnabled(true);
            factory.setCustomEntryIdleTimeout(new SessionCustomExpiry());
            factory.addCacheListener(new SessionExpirationCacheListener());
        }
        // Create the region
        frontingRegion = factory.create(frontingRegionName);
        if (getSessionManager().getLogger().isDebugEnabled()) {
            getSessionManager().getLogger().debug("Created new local session region: " + frontingRegion);
        }
    } else {
        if (getSessionManager().getLogger().isDebugEnabled()) {
            getSessionManager().getLogger().debug("Retrieved existing local session region: " + frontingRegion);
        }
    }
    return frontingRegion;
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionExpirationCacheListener(org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener) SessionCustomExpiry(org.apache.geode.modules.util.SessionCustomExpiry) LocalSessionCacheLoader(org.apache.geode.modules.session.catalina.callback.LocalSessionCacheLoader) LocalSessionCacheWriter(org.apache.geode.modules.session.catalina.callback.LocalSessionCacheWriter)

Example 3 with SessionExpirationCacheListener

use of org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener in project geode by apache.

the class ClientServerSessionCache method createLocalSessionRegion.

private Region<String, HttpSession> createLocalSessionRegion() {
    ClientRegionFactory<String, HttpSession> factory = null;
    if (getSessionManager().getEnableLocalCache()) {
        // Create the region factory with caching and heap LRU enabled
        factory = this.cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
        // Set the expiration time, action and listener if necessary
        int maxInactiveInterval = getSessionManager().getMaxInactiveInterval();
        if (maxInactiveInterval != RegionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL) {
            factory.setStatisticsEnabled(true);
            factory.setCustomEntryIdleTimeout(new SessionCustomExpiry());
            factory.addCacheListener(new SessionExpirationCacheListener());
        }
    } else {
        // Create the region factory without caching enabled
        factory = this.cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
        factory.addCacheListener(new SessionExpirationCacheListener());
    }
    // Create the region
    Region region = factory.create(getSessionManager().getRegionName());
    /*
     * If we're using an empty client region, we register interest so that expired sessions are
     * destroyed correctly.
     */
    if (!getSessionManager().getEnableLocalCache()) {
        region.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS);
    }
    return region;
}
Also used : HttpSession(javax.servlet.http.HttpSession) SessionExpirationCacheListener(org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener) SessionCustomExpiry(org.apache.geode.modules.util.SessionCustomExpiry) Region(org.apache.geode.cache.Region)

Aggregations

SessionExpirationCacheListener (org.apache.geode.modules.session.catalina.callback.SessionExpirationCacheListener)3 HttpSession (javax.servlet.http.HttpSession)2 SessionCustomExpiry (org.apache.geode.modules.util.SessionCustomExpiry)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 GatewayDeltaForwarderCacheListener (org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener)1 LocalSessionCacheLoader (org.apache.geode.modules.session.catalina.callback.LocalSessionCacheLoader)1 LocalSessionCacheWriter (org.apache.geode.modules.session.catalina.callback.LocalSessionCacheWriter)1