protected void addCacheListeners (Ehcache cache) { // add a listener that updates our local cache cache.getCacheEventNotificationService().registerListener(_cacheEventListener); // add an RMI replicator (TODO: this should be optional) (TODO: do we want only one of // these and to register the same one with all caches?) Properties props = new Properties(); props.setProperty("replicateAsynchronously", "true"); props.setProperty("replicatePuts", "false"); props.setProperty("replicateUpdates", "true"); props.setProperty("replicateUpdatesViaCopy", "false"); props.setProperty("replicateRemovals", "true"); cache.getCacheEventNotificationService().registerListener( new RMICacheReplicatorFactory().createCacheEventListener(props)); }
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; }
/** * Create the cache event listener that does the replication. * * @return the event listener */ private CacheEventListener createEventListener() { return new RMICacheReplicatorFactory().createCacheEventListener(settings); }