/** * Create an {@link EhCacheCache} instance. * @param ehcache the backing Ehcache instance */ public EhCacheCache(Ehcache ehcache) { Assert.notNull(ehcache, "Ehcache must not be null"); Status status = ehcache.getStatus(); if (!Status.STATUS_ALIVE.equals(status)) { throw new IllegalArgumentException( "An 'alive' Ehcache is required - current cache is " + status.toString()); } this.cache = ehcache; }
/** * Create an {@link EhCacheCache} instance. * @param ehcache the backing Ehcache instance */ public EhCacheCache(Ehcache ehcache) { Assert.notNull(ehcache, "Ehcache must not be null"); Status status = ehcache.getStatus(); if (!Status.STATUS_ALIVE.equals(status)) { throw new IllegalArgumentException( "An 'alive' Ehcache is required - current cache is " + status.toString()); } this.cache = ehcache; }
@Override protected Collection<Cache> loadCaches() { net.sf.ehcache.CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); Status status = cacheManager.getStatus(); if (!Status.STATUS_ALIVE.equals(status)) { throw new IllegalStateException( "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); } String[] names = getCacheManager().getCacheNames(); Collection<Cache> caches = new LinkedHashSet<>(names.length); for (String name : names) { caches.add(new EhCacheCache(getCacheManager().getEhcache(name))); } return caches; }
@Override protected Collection<Cache> loadCaches() { net.sf.ehcache.CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); Status status = cacheManager.getStatus(); if (!Status.STATUS_ALIVE.equals(status)) { throw new IllegalStateException( "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); } String[] names = getCacheManager().getCacheNames(); Collection<Cache> caches = new LinkedHashSet<>(names.length); for (String name : names) { caches.add(new EhCacheCache(getCacheManager().getEhcache(name))); } return caches; }
@Override protected Collection<Cache> loadCaches() { Assert.notNull(this.cacheManager, "A backing EhCache CacheManager is required"); Status status = this.cacheManager.getStatus(); Assert.isTrue(Status.STATUS_ALIVE.equals(status), "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); String[] names = this.cacheManager.getCacheNames(); Collection<Cache> caches = Sets.newLinkedHashSetWithExpectedSize(names.length); for (String name : names) { if (enableMetrics) { caches.add(new InstrumentedEhCacheCache(this.cacheManager.getEhcache(name))); } else { caches.add(new EhCacheCache(this.cacheManager.getEhcache(name))); } } return caches; }
/** * Checks that the replicator is is <code>STATUS_ALIVE</code>. */ public final boolean alive() { if (status == null) { return false; } else { return (status.equals(Status.STATUS_ALIVE)); } }
/** * Checks the state of the CacheManager for legal operation */ protected void checkStatus() { if (!(status.equals(Status.STATUS_ALIVE))) { if (status.equals(Status.STATUS_UNINITIALISED)) { throw new IllegalStateException("The CacheManager has not yet been initialised. It cannot be used yet."); } else if (status.equals(Status.STATUS_SHUTDOWN)) { throw new IllegalStateException("The CacheManager has been shut down. It can no longer be used."); } } }
private void reinitialisationCheck() throws IllegalStateException { if (diskStorePathManager != null || ehcaches.size() != 0 || status.equals(Status.STATUS_SHUTDOWN)) { throw new IllegalStateException("Attempt to reinitialise the CacheManager"); } }
Assert.notNull(ehcache, "Ehcache must not be null"); Status status = ehcache.getStatus(); Assert.isTrue(Status.STATUS_ALIVE.equals(status), "An 'alive' Ehcache is required - current cache is " + status.toString()); this.cache = ehcache;
/** * Prepares for shutdown. */ public final synchronized void dispose() { if (status.equals(Status.STATUS_SHUTDOWN)) { return; } status = Status.STATUS_SHUTDOWN; flush(); //release reference to cache cache = null; }
@Override public void run() { synchronized (this) { if (status.equals(Status.STATUS_ALIVE)) { // clear shutdown hook reference to prevent // removeShutdownHook to remove it during shutdown shutdownHook = null; LOG.info("VM shutting down with the CacheManager still active. Calling shutdown."); shutdown(); } } } };
private boolean isAlive() { return ehcache.getStatus().equals(Status.STATUS_ALIVE); }
/** * Prepares for shutdown. */ public synchronized void dispose() { if (status.equals(Status.STATUS_SHUTDOWN)) { return; } status = Status.STATUS_SHUTDOWN; flush(); poolAccessor.unlink(); }
/** * Stop the listener. It * <ul> * <li>unbinds the objects from the registry * <li>unexports Remote objects * </ul> */ public void dispose() throws CacheException { if (!status.equals(Status.STATUS_ALIVE)) { return; } try { int counter = 0; synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { RMICachePeer rmiCachePeer = (RMICachePeer) iterator.next(); disposeRMICachePeer(rmiCachePeer); counter++; } stopRegistry(); } LOG.debug(counter + " RMICachePeers unbound from registry in RMI listener"); status = Status.STATUS_SHUTDOWN; } catch (Exception e) { throw new CacheException("Problem unbinding remote cache peers. Initial cause was " + e.getMessage(), e); } }
/** * {@inheritDoc} */ public void init() throws CacheException { if (!status.equals(Status.STATUS_UNINITIALISED)) { return; } RMICachePeer rmiCachePeer = null; try { startRegistry(); int counter = 0; populateListOfRemoteCachePeers(); synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { rmiCachePeer = (RMICachePeer) iterator.next(); bind(rmiCachePeer.getUrl(), rmiCachePeer); counter++; } } LOG.debug(counter + " RMICachePeers bound in registry for RMI listener"); status = Status.STATUS_ALIVE; } catch (Exception e) { String url = null; if (rmiCachePeer != null) { url = rmiCachePeer.getUrl(); } throw new CacheException("Problem starting listener for RMICachePeer " + url + ". Initial cause was " + e.getMessage(), e); } }
/** * Remove a cache from the CacheManager. The cache is disposed of. * * @param cacheName * the cache name * @throws IllegalStateException * if the cache is not {@link Status#STATUS_ALIVE} */ public synchronized void removeCache(String cacheName) throws IllegalStateException { checkStatus(); // NPE guard if (cacheName == null || cacheName.length() == 0) { return; } Ehcache cache = ehcaches.remove(cacheName); if (cache != null && cache.getStatus().equals(Status.STATUS_ALIVE)) { cache.dispose(); runtimeCfg.removeCache(cache.getCacheConfiguration()); cacheManagerEventListenerRegistry.notifyCacheRemoved(cache.getName()); } }
if (status.equals(Status.STATUS_SHUTDOWN)) { LOG.debug("CacheManager already shutdown"); return;
if (status.equals(Status.STATUS_ALIVE)) { cacheManagerEventListenerRegistry.notifyCacheAdded(cache.getName());
/** * Sets the bootstrap cache loader. * * @param bootstrapCacheLoader the loader to be used * @throws CacheException if this method is called after the cache is initialized */ public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader) throws CacheException { if (!status.equals(Status.STATUS_UNINITIALISED)) { throw new CacheException( "A bootstrap cache loader can only be set before the cache is initialized. " + name); } this.bootstrapCacheLoader = bootstrapCacheLoader; }
@Override public boolean removeCacheElement(Ehcache cache, String key) { if (cache == null || !cache.getStatus().equals(Status.STATUS_ALIVE)) { return false; } return cache.remove(key); }