private boolean isAlive() { return ehcache.getStatus().equals(Status.STATUS_ALIVE); }
public TableModel get( final DataCacheKey key ) { final Cache cache = this.cache; synchronized ( this ) { if ( cache == null ) { return null; } if ( cache.getStatus() != Status.STATUS_ALIVE ) { this.cache = null; return null; } } final Element element = cache.get( key ); if ( element == null ) { return null; } return (TableModel) element.getObjectValue(); }
/** * Call {@link Cache#removeAll()} on the specified cache, if it exists and is alive. * * @see Status#STATUS_ALIVE * @see Cache#getStatus() * @param cacheName */ public void clearCache(String cacheName) { Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { cache.removeAll(); logger.warn("finished removeAll for cache: " + cacheName); } }
/** * Call {@link Cache#removeAll()} on the specified cache, if it exists and is alive. * * @see Status#STATUS_ALIVE * @see Cache#getStatus() * @param cacheName */ public void clearCache(String cacheName) { Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { cache.removeAll(); logger.warn("finished removeAll for cache: " + cacheName); } }
/** * @see Status#STATUS_ALIVE * @see Cache#getStatus() * @see Cache#getStatistics() * @param cacheName * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or * doesn't exist */ public Statistics getCacheStatistics(String cacheName) { Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { Statistics result = cache.getStatistics(); return result; } return null; }
/** * @see Status#STATUS_ALIVE * @see Cache#getStatus() * @see Cache#getStatistics() * @param cacheName * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or * doesn't exist */ public Statistics getCacheStatistics(String cacheName) { Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { Statistics result = cache.getStatistics(); return result; } return null; }
private void shutdownIfActive( Cache cache ) { if( Status.STATUS_ALIVE.equals( cache.getStatus() ) ) { System.out.println( "Attempting to dispose of: " + cache.getName() + "..." ); cache.dispose(); } else { System.out.println( "Cache('"+ cache.getName() +"') was not alive. Skipping dispose()..." ); } } }
@SuppressWarnings("unchecked") public V get(K key) { try { Element element = cache.get(key); if (element != null) { return (V) element.getObjectValue(); } else { return null; } } catch (IllegalStateException ie) { throw new org.alfresco.wcm.client.impl.cache.CacheException("Failed to get from EhCache as state invalid: \n" + " state: " + cache.getStatus() + "\n" + " key: " + key, ie); } catch (CacheException e) { throw new org.alfresco.wcm.client.impl.cache.CacheException("Failed to get from EhCache: \n" + " key: " + key, e); } }
@Override public void close() { if (this.cache != null){ if( Status.STATUS_ALIVE.equals( cache.getStatus() ) ) { System.out.println( "Attempting to dispose of: " + cache.getName() + "..." ); cache.dispose(); } } if (cacheManager != null){ cacheManager.clearAll(); } service.close(); }
@Override public CacheCompactionResult purgeExpiredCacheEntries() { int cacheCount = 0; int totalEntriesCount = 0; int purgedEntriesCount = 0; for (String name : cacheManager.getCacheNames()) { try { Cache cache = cacheManager.getCache(name); if (cache != null && cache.getStatus().equals(Status.STATUS_ALIVE)) { int before = cache.getSize(); cache.evictExpiredElements(); int after = cache.getSize(); cacheCount++; totalEntriesCount += before; purgedEntriesCount += (before - after); } } catch (Exception e) { LOG.warn("Unable to purge expired cache entries for cahe '" + name + "'", e); } } return new CacheCompactionResult(cacheCount, totalEntriesCount, purgedEntriesCount); }
private synchronized void initialize() { if ( manager != null ) { if ( manager.getStatus() != Status.STATUS_ALIVE ) { initializeCacheManager(); } } if ( cache != null ) { if ( cache.getStatus() == Status.STATUS_ALIVE ) { return; } } if ( manager.cacheExists( CACHE_NAME ) == false ) { cache = new Cache( CACHE_NAME, // cache name 500, // maxElementsInMemory false, // overflowToDisk false, // eternal 600, // timeToLiveSeconds 600, // timeToIdleSeconds false, // diskPersistent 120 ); // diskExpiryThreadIntervalSeconds manager.addCache( cache ); } else { cache = manager.getCache( CACHE_NAME ); } }
public Map<String, CacheStatistics> getAllCacheStatistics() { final Map<String, CacheStatistics> allCacheStatistics = new TreeMap<>(CaseInsenstivieStringComparator.INSTANCE); for (final String cacheName : this.cacheManager.getCacheNames()) { final Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration(); final Statistics statistics = cache.getStatistics(); final CacheStatistics cacheStatistics = new CacheStatistics(); cacheStatistics.hits = statistics.getCacheHits(); cacheStatistics.misses = statistics.getCacheMisses(); cacheStatistics.size = statistics.getObjectCount(); cacheStatistics.maxSize = cacheConfiguration.getMaxElementsInMemory() + cacheConfiguration.getMaxElementsOnDisk(); allCacheStatistics.put(cacheName, cacheStatistics); } } return allCacheStatistics; }
public Map<String, CacheStatistics> getAllCacheStatistics() { final Map<String, CacheStatistics> allCacheStatistics = new TreeMap<>(CaseInsenstivieStringComparator.INSTANCE); for (final String cacheName : this.cacheManager.getCacheNames()) { final Cache cache = this.cacheManager.getCache(cacheName); if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) { final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration(); final Statistics statistics = cache.getStatistics(); final CacheStatistics cacheStatistics = new CacheStatistics(); cacheStatistics.hits = statistics.getCacheHits(); cacheStatistics.misses = statistics.getCacheMisses(); cacheStatistics.size = statistics.getObjectCount(); cacheStatistics.maxSize = cacheConfiguration.getMaxElementsInMemory() + cacheConfiguration.getMaxElementsOnDisk(); allCacheStatistics.put(cacheName, cacheStatistics); } } return allCacheStatistics; }