/** * Only Constructor * * @param cacheManager * @param configuration */ public ConfigurationHelper(CacheManager cacheManager, Configuration configuration) { if (cacheManager == null || configuration == null) { throw new IllegalArgumentException("Cannot have null parameters"); } this.cacheManager = cacheManager; this.configuration = configuration; this.loader = configuration.getClassLoader(); }
private ClassLoader getClassLoader() { return this.runtimeCfg.getConfiguration().getClassLoader(); }
/** * Create a cache given a cache configuration * * @param cacheConfiguration */ final Ehcache createCache(CacheConfiguration cacheConfiguration) { CacheConfiguration configClone = cacheConfiguration.clone(); // make sure all caches use the same classloader that the CacheManager is configured to use configClone.setClassLoader(configuration.getClassLoader()); Ehcache cache = new Cache(configClone, null, null); cache = applyCacheExceptionHandler(configClone, cache); return cache; }
lookupConfiguration.getPropertySeparator()); ClassLoader loader = getClassLoader();
private void doLoad(final Ehcache cache) { CacheManager manager = cache.getCacheManager(); if (manager == null) { throw new CacheException("Cache must belong to a cache manager to bootstrap"); } DiskStorePathManager pathManager = diskStorePathManager != null ? diskStorePathManager : cache.getCacheManager() .getDiskStorePathManager(); final RotatingSnapshotFile snapshotFile = new RotatingSnapshotFile(pathManager, cache.getName(), manager.getConfiguration().getClassLoader()); try { final Set<Object> keys = snapshotFile.readAll(); int loaded = 0; for (Object key : keys) { if (isInMemoryLimitReached(cache, loaded)) { break; } cache.get(key); loaded++; } LOG.info("Finished loading {} keys (of {} on disk) from previous snapshot for Cache '{}'", new Object[] {Integer.valueOf(loaded), keys.size(), cache.getName()}); } catch (IOException e) { LOG.error("Couldn't load keySet for Cache '{}'", cache.getName(), e); } if (doKeySnapshot) { keySnapshotter = new KeySnapshotter(cache, interval, doKeySnapshotOnDedicatedThread, snapshotFile); } }
private synchronized ClusteredInstanceFactoryWrapper createNewClusteredInstanceFactory() { // shut down the old factory if (clusteredInstanceFactory != null) { info("Shutting down old ClusteredInstanceFactory..."); shutdownClusteredInstanceFactoryWrapper(clusteredInstanceFactory); } info("Creating new ClusteredInstanceFactory"); ClusteredInstanceFactory factory; factory = TerracottaClusteredInstanceHelper.getInstance().newClusteredInstanceFactory(terracottaClientConfiguration, cacheManager.getConfiguration().getClassLoader()); CacheCluster underlyingCacheCluster = factory.getTopology(); cacheCluster.setUnderlyingCacheCluster(underlyingCacheCluster); return new ClusteredInstanceFactoryWrapper(this, factory); }
/** * Only Constructor * * @param cacheManager * @param configuration */ public ConfigurationHelper(CacheManager cacheManager, Configuration configuration) { if (cacheManager == null || configuration == null) { throw new IllegalArgumentException("Cannot have null parameters"); } this.cacheManager = cacheManager; this.configuration = configuration; this.loader = configuration.getClassLoader(); }
/** * Only Constructor * * @param cacheManager * @param configuration */ public ConfigurationHelper(CacheManager cacheManager, Configuration configuration) { if (cacheManager == null || configuration == null) { throw new IllegalArgumentException("Cannot have null parameters"); } this.cacheManager = cacheManager; this.configuration = configuration; this.loader = configuration.getClassLoader(); }
@Override public ClassLoader getClassLoader() { return cacheManager.getConfiguration().getClassLoader(); }
@Override public ClassLoader getClassLoader() { return cacheManager.getConfiguration().getClassLoader(); }
private ClassLoader getClassLoader() { return this.runtimeCfg.getConfiguration().getClassLoader(); }
private ClassLoader getClassLoader() { return this.runtimeCfg.getConfiguration().getClassLoader(); }
if (loader != cacheManager.getConfiguration().getClassLoader()) {
/** * Create a cache given a cache configuration * * @param cacheConfiguration */ final Ehcache createCache(CacheConfiguration cacheConfiguration) { CacheConfiguration configClone = cacheConfiguration.clone(); // make sure all caches use the same classloader that the CacheManager is configured to use configClone.setClassLoader(configuration.getClassLoader()); Ehcache cache = new Cache(configClone, null, null); cache = applyCacheExceptionHandler(configClone, cache); return cache; }
/** * Create a cache given a cache configuration * * @param cacheConfiguration */ final Ehcache createCache(CacheConfiguration cacheConfiguration) { CacheConfiguration configClone = cacheConfiguration.clone(); // make sure all caches use the same classloader that the CacheManager is configured to use configClone.setClassLoader(configuration.getClassLoader()); Ehcache cache = new Cache(configClone, null, null); cache = applyCacheExceptionHandler(configClone, cache); return cache; }
private void doLoad(final Ehcache cache) { CacheManager manager = cache.getCacheManager(); if (manager == null) { throw new CacheException("Cache must belong to a cache manager to bootstrap"); } DiskStorePathManager pathManager = diskStorePathManager != null ? diskStorePathManager : cache.getCacheManager() .getDiskStorePathManager(); final RotatingSnapshotFile snapshotFile = new RotatingSnapshotFile(pathManager, cache.getName(), manager.getConfiguration().getClassLoader()); try { final Set<Object> keys = snapshotFile.readAll(); int loaded = 0; for (Object key : keys) { if (isInMemoryLimitReached(cache, loaded)) { break; } cache.get(key); loaded++; } LOG.info("Finished loading {} keys (of {} on disk) from previous snapshot for Cache '{}'", new Object[] {Integer.valueOf(loaded), keys.size(), cache.getName()}); } catch (IOException e) { LOG.error("Couldn't load keySet for Cache '{}'", cache.getName(), e); } if (doKeySnapshot) { keySnapshotter = new KeySnapshotter(cache, interval, doKeySnapshotOnDedicatedThread, snapshotFile); } }
private synchronized ClusteredInstanceFactoryWrapper createNewClusteredInstanceFactory() { // shut down the old factory if (clusteredInstanceFactory != null) { info("Shutting down old ClusteredInstanceFactory..."); shutdownClusteredInstanceFactoryWrapper(clusteredInstanceFactory); } info("Creating new ClusteredInstanceFactory"); ClusteredInstanceFactory factory; factory = TerracottaClusteredInstanceHelper.getInstance().newClusteredInstanceFactory(terracottaClientConfiguration, cacheManager.getConfiguration().getClassLoader()); CacheCluster underlyingCacheCluster = factory.getTopology(); cacheCluster.setUnderlyingCacheCluster(underlyingCacheCluster); return new ClusteredInstanceFactoryWrapper(this, factory); }
private synchronized ClusteredInstanceFactoryWrapper createNewClusteredInstanceFactory() { // shut down the old factory if (clusteredInstanceFactory != null) { info("Shutting down old ClusteredInstanceFactory..."); shutdownClusteredInstanceFactoryWrapper(clusteredInstanceFactory); } info("Creating new ClusteredInstanceFactory"); ClusteredInstanceFactory factory; factory = TerracottaClusteredInstanceHelper.getInstance().newClusteredInstanceFactory(terracottaClientConfiguration, cacheManager.getConfiguration().getClassLoader()); CacheCluster underlyingCacheCluster = factory.getTopology(); cacheCluster.setUnderlyingCacheCluster(underlyingCacheCluster); return new ClusteredInstanceFactoryWrapper(this, factory); }
private CacheConfiguration toEhcacheConfig(final String name, final Configuration configuration) { final int maxSize = cacheManager.getConfiguration().isMaxBytesLocalHeapSet() ? 0 : DEFAULT_SIZE; CacheConfiguration cfg = new CacheConfiguration(name, maxSize); cfg.setClassLoader(cacheManager.getConfiguration().getClassLoader()); if(configuration.isStoreByValue()) { final CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); copyStrategyConfiguration.setCopyStrategyInstance(new JCacheCopyOnWriteStrategy()); cfg.copyOnRead(true).copyOnWrite(true) .addCopyStrategy(copyStrategyConfiguration); } if(configuration instanceof CompleteConfiguration) { if(((CompleteConfiguration)configuration).isWriteThrough()) { cfg.addCacheWriter(new CacheWriterConfiguration().writeMode(CacheWriterConfiguration.WriteMode.WRITE_THROUGH)); } } return cfg; }
private CacheConfiguration toEhcacheConfig(final String name, final Configuration configuration) { final int maxSize = cacheManager.getConfiguration().isMaxBytesLocalHeapSet() ? 0 : DEFAULT_SIZE; CacheConfiguration cfg = new CacheConfiguration(name, maxSize); cfg.setClassLoader(cacheManager.getConfiguration().getClassLoader()); if(configuration.isStoreByValue()) { final CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); copyStrategyConfiguration.setCopyStrategyInstance(new JCacheCopyOnWriteStrategy()); cfg.copyOnRead(true).copyOnWrite(true) .addCopyStrategy(copyStrategyConfiguration); } if(configuration instanceof CompleteConfiguration) { if(((CompleteConfiguration)configuration).isWriteThrough()) { cfg.addCacheWriter(new CacheWriterConfiguration().writeMode(CacheWriterConfiguration.WriteMode.WRITE_THROUGH)); } } return cfg; }