Search in sources :

Example 6 with CacheException

use of net.sf.ehcache.CacheException in project killbill by killbill.

the class EhCacheCacheManagerProvider method get.

@Override
public CacheManager get() {
    final CacheManager cacheManager;
    try {
        final InputStream inputStream = UriAccessor.accessUri(cacheConfig.getCacheConfigLocation());
        cacheManager = CacheManager.create(inputStream);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    } catch (final URISyntaxException e) {
        throw new RuntimeException(e);
    }
    for (final BaseCacheLoader cacheLoader : cacheLoaders) {
        cacheLoader.init();
        final Ehcache cache = cacheManager.getEhcache(cacheLoader.getCacheType().getCacheName());
        if (cache == null) {
            logger.warn("Cache for cacheName='{}' not configured - check your ehcache.xml", cacheLoader.getCacheType().getCacheName());
            continue;
        }
        // Make sure we start from a clean state - this is mainly useful for tests
        for (final CacheLoader existingCacheLoader : cache.getRegisteredCacheLoaders()) {
            cache.unregisterCacheLoader(existingCacheLoader);
        }
        cache.registerCacheLoader(cacheLoader);
        // Instrument the cache
        final Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
        try {
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        } catch (final CacheException e) {
            logger.warn("Unable to instrument cache {}: {}", cache.getName(), e.getMessage());
        }
    }
    return cacheManager;
}
Also used : CacheException(net.sf.ehcache.CacheException) InputStream(java.io.InputStream) CacheManager(net.sf.ehcache.CacheManager) InstrumentedEhcache(com.codahale.metrics.ehcache.InstrumentedEhcache) Ehcache(net.sf.ehcache.Ehcache) CacheLoader(net.sf.ehcache.loader.CacheLoader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Example 7 with CacheException

use of net.sf.ehcache.CacheException in project spring-security by spring-projects.

the class EhCacheBasedAclCache method getFromCache.

public MutableAcl getFromCache(Serializable pk) {
    Assert.notNull(pk, "Primary key (identifier) required");
    Element element = null;
    try {
        element = cache.get(pk);
    } catch (CacheException ignored) {
    }
    if (element == null) {
        return null;
    }
    return initializeTransientFields((MutableAcl) element.getValue());
}
Also used : CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element)

Example 8 with CacheException

use of net.sf.ehcache.CacheException in project spring-security by spring-projects.

the class EhCacheBasedAclCache method getFromCache.

public MutableAcl getFromCache(ObjectIdentity objectIdentity) {
    Assert.notNull(objectIdentity, "ObjectIdentity required");
    Element element = null;
    try {
        element = cache.get(objectIdentity);
    } catch (CacheException ignored) {
    }
    if (element == null) {
        return null;
    }
    return initializeTransientFields((MutableAcl) element.getValue());
}
Also used : CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element)

Example 9 with CacheException

use of net.sf.ehcache.CacheException in project ORCID-Source by ORCID.

the class OrcidEhcacheManagementService method createObjectName.

static ObjectName createObjectName(net.sf.ehcache.CacheManager cacheManager) {
    ObjectName objectName;
    try {
        int hashCode = OrcidEhcacheManagementService.class.getClassLoader().hashCode();
        String suffix = "_" + hashCode;
        String safeCacheManagerName = EhcacheHibernateMbeanNames.mbeanSafe(cacheManager.getName() + suffix);
        LOGGER.info("Cache manager name = {}", safeCacheManagerName);
        cacheManager.setName(safeCacheManagerName);
        objectName = new ObjectName("net.sf.ehcache:type=CacheManager,name=" + safeCacheManagerName);
    } catch (MalformedObjectNameException e) {
        throw new CacheException(e);
    }
    return objectName;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CacheException(net.sf.ehcache.CacheException) ObjectName(javax.management.ObjectName)

Example 10 with CacheException

use of net.sf.ehcache.CacheException in project simplejpa by appoxy.

the class EhCacheFactory method createCache.

public synchronized EhcacheWrapper createCache(String name) {
    if (manager == null) {
        throw new CacheException("CacheFactory was not initialized. Call init() before creating a cache.");
    }
    try {
        Cache cache = manager.getCache(name);
        if (cache == null) {
            log.warning("Could not find a specific ehcache configuration for cache named [" + name + "]; using defaults.");
            manager.addCache(name);
            cache = manager.getCache(name);
        }
        Ehcache backingCache = cache;
        if (!backingCache.getCacheEventNotificationService().hasCacheEventListeners()) {
            if (listeners.size() > 0) {
                for (CacheEventListener listener : listeners) {
                    if (!backingCache.getCacheEventNotificationService().getCacheEventListeners().contains(listener)) {
                        backingCache.getCacheEventNotificationService().registerListener(listener);
                    } else {
                    }
                }
            }
        }
        return new EhcacheWrapper(cache);
    } catch (net.sf.ehcache.CacheException e) {
        throw new CacheException("Could not create cache: " + name, e);
    }
}
Also used : CacheEventListener(net.sf.ehcache.event.CacheEventListener) CacheException(net.sf.ehcache.CacheException) Ehcache(net.sf.ehcache.Ehcache) Cache(net.sf.ehcache.Cache) CacheException(net.sf.ehcache.CacheException)

Aggregations

CacheException (net.sf.ehcache.CacheException)17 Element (net.sf.ehcache.Element)6 Cache (net.sf.ehcache.Cache)5 CacheManager (net.sf.ehcache.CacheManager)4 Ehcache (net.sf.ehcache.Ehcache)3 InstrumentedEhcache (com.codahale.metrics.ehcache.InstrumentedEhcache)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 Iterator (java.util.Iterator)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 StateMachineConfig (org.killbill.automaton.StateMachineConfig)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Test (org.testng.annotations.Test)2 FileInputStream (java.io.FileInputStream)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1