public static Ehcache createInMemoryCache(String cacheName, CacheEntryFactory entryFactory, int maxElements) { CacheManager manager = CacheManager.getInstance(); Ehcache cache = getCache(cacheName); if (cache == null) { // Create the cache cache = new Cache(cacheName, maxElements, memoryStoreEvictionPolicy, overflowToDisk, diskStorePath, eternal, timeToLive, timeToIdle, diskPersistent, diskExpiryThreadIntervalSeconds, null); // Associate the cacheEntryFactory with the cache SelfPopulatingCache selfPopulatingCache = new SelfPopulatingCache(cache, entryFactory); // Add any additional listener properties if (manager.getCachePeerListener("RMI") != null) { LOG.info("Setting RMI properties"); Properties properties = new Properties(); properties.put("replicateAsynchronously", "true"); properties.put("replicatePuts", "false"); properties.put("replicateUpdates", "true"); properties.put("replicateRemovals", "true"); properties.put("replicateUpdatesViaCopy", "false"); properties.put("asynchronousReplicationIntervalMillis", "1000"); RMICacheReplicatorFactory factory = new RMICacheReplicatorFactory(); CacheEventListener listener = factory.createCacheEventListener(properties); selfPopulatingCache.getCacheEventNotificationService().registerListener(listener); RMIBootstrapCacheLoaderFactory bootstrapFactory = new RMIBootstrapCacheLoaderFactory(); BootstrapCacheLoader bootstrapCacheLoader = bootstrapFactory.createBootstrapCacheLoader(new Properties()); selfPopulatingCache.setBootstrapCacheLoader(bootstrapCacheLoader); LOG.debug("RMI enabled"); } // Make the cache available manager.addCache(selfPopulatingCache); LOG.info("cache created: " + cache.getName()); } return cache; }
@Override public final void setBootstrapCacheLoader( BootstrapCacheLoader bootstrapCacheLoader) throws CacheException { throw new UnsupportedOperationException("Cache is read-only...operation not supported"); }
@Override public BootstrapCacheLoader getBootstrapCacheLoader() { init(); return super.getBootstrapCacheLoader(); }
@Override public void setBootstrapCacheLoader( BootstrapCacheLoader bootstrapCacheLoader) throws CacheException { init(); super.setBootstrapCacheLoader(bootstrapCacheLoader); }
/** * Set an EhCache {@link net.sf.ehcache.bootstrap.BootstrapCacheLoader} * for this cache, if any. */ public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader) { this.bootstrapCacheLoader = bootstrapCacheLoader; }
/** * Set an EHCache {@link net.sf.ehcache.bootstrap.BootstrapCacheLoader} * for this cache, if any. */ public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader) { this.bootstrapCacheLoader = bootstrapCacheLoader; }