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;
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations