/** * Accessor */ public boolean isOverflowToOffHeap() { return cacheConfiguration.isOverflowToOffHeap(); }
/** * Adds an {@link Ehcache} to the CacheManager. * <p> * Memory and Disk stores will be configured for it and it will be added to the map of caches. Also notifies the * CacheManagerEventListener after the cache was initialised and added. * * @param cache * @throws IllegalStateException * if the cache is not {@link Status#STATUS_UNINITIALISED} before this method is called. * @throws ObjectExistsException * if the cache already exists in the CacheManager * @throws CacheException * if there was an error adding the cache to the CacheManager */ public synchronized void addCache(Ehcache cache) throws IllegalStateException, ObjectExistsException, CacheException { checkStatus(); if (cache == null) { return; } final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration(); final boolean verifyOffHeapUsage = runtimeCfg.hasOffHeapPool() && ((!cacheConfiguration.isOverflowToDisk() && !cacheConfiguration.isOverflowToOffHeapSet()) || cacheConfiguration .isOverflowToOffHeap()); if (verifyOffHeapUsage && (cacheConfiguration.isMaxBytesLocalOffHeapPercentageSet() || cacheConfiguration.getMaxBytesLocalOffHeap() > 0)) { throw new CacheException("CacheManager uses OffHeap settings, you can't add cache using offHeap dynamically!"); } addCacheNoCheck(cache, true); }
/** * {@inheritDoc} */ @Override public boolean isOverflowToOffHeap() { return cache.getCacheConfiguration().isOverflowToOffHeap(); }
element.addAttribute(new SimpleNodeAttribute("overflowToOffHeap", cacheConfiguration.isOverflowToOffHeap()));
private boolean determineCachePinned(CacheConfiguration cacheConfiguration) { PinningConfiguration pinningConfiguration = cacheConfiguration.getPinningConfiguration(); if (pinningConfiguration == null) { return false; } switch (pinningConfiguration.getStore()) { case LOCALMEMORY: return false; case INCACHE: return !cacheConfiguration.isOverflowToOffHeap() && !cacheConfiguration.isOverflowToDisk(); default: throw new IllegalArgumentException(); } }
private boolean determineStorePinned(CacheConfiguration cacheConfiguration) { PinningConfiguration pinningConfiguration = cacheConfiguration.getPinningConfiguration(); if (pinningConfiguration == null) { return false; } switch (pinningConfiguration.getStore()) { case LOCALMEMORY: return false; case INCACHE: return !cacheConfiguration.isOverflowToOffHeap() && !cacheConfiguration.isOverflowToDisk(); default: throw new IllegalArgumentException(); } }
/** * Returns a {@link String} representation of {@link Cache}. */ @Override public String toString() { StringBuilder dump = new StringBuilder(); dump.append("[") .append(" name = ").append(configuration.getName()) .append(" status = ").append(cacheStatus.getStatus()) .append(" eternal = ").append(configuration.isEternal()) .append(" overflowToDisk = ").append(configuration.isOverflowToDisk()) .append(" maxEntriesLocalHeap = ").append(configuration.getMaxEntriesLocalHeap()) .append(" maxEntriesLocalDisk = ").append(configuration.getMaxEntriesLocalDisk()) .append(" memoryStoreEvictionPolicy = ").append(configuration.getMemoryStoreEvictionPolicy()) .append(" timeToLiveSeconds = ").append(configuration.getTimeToLiveSeconds()) .append(" timeToIdleSeconds = ").append(configuration.getTimeToIdleSeconds()) .append(" persistence = ").append(configuration.getPersistenceConfiguration() == null ? "none" : configuration.getPersistenceConfiguration().getStrategy()) .append(" diskExpiryThreadIntervalSeconds = ").append(configuration.getDiskExpiryThreadIntervalSeconds()) .append(registeredEventListeners) .append(" maxBytesLocalHeap = ").append(configuration.getMaxBytesLocalHeap()) .append(" overflowToOffHeap = ").append(configuration.isOverflowToOffHeap()) .append(" maxBytesLocalOffHeap = ").append(configuration.getMaxBytesLocalOffHeap()) .append(" maxBytesLocalDisk = ").append(configuration.getMaxBytesLocalDisk()) .append(" pinned = ") .append(configuration.getPinningConfiguration() != null ? configuration.getPinningConfiguration().getStore().name() : "false") .append(" ]"); return dump.toString(); }
/** * Calculates the number of caches in the configuration that are diskPersistent */ public final int numberOfCachesThatUseDiskStorage() { int count = 0; Set cacheConfigurations = configuration.getCacheConfigurations().entrySet(); for (CacheConfiguration cacheConfig : configuration.getCacheConfigurations().values()) { if (cacheConfig.isOverflowToDisk() || cacheConfig.isDiskPersistent() || (cacheConfig.isOverflowToOffHeap() && cacheConfig.isSearchable())) { count++; } else { PersistenceConfiguration persistence = cacheConfig.getPersistenceConfiguration(); if (persistence != null) { switch (persistence.getStrategy()) { case LOCALTEMPSWAP: case LOCALRESTARTABLE: count++; break; default: break; } } } } return count; }
private void warnTieredSizing() { if (isOverflowToOffHeap()) { if (getMaxBytesLocalHeap() >= getMaxBytesLocalOffHeap() && getMaxBytesLocalOffHeap() != 0) { LOG.warn("Configuration problem for cache " + getName() + ": MaxBytesLocalHeap equal or greater than MaxBytesLocalOffHeap. " + "This will result in useless off heap storage."); } if (isOverflowToDisk()) { if (getMaxBytesLocalOffHeap() >= getMaxBytesLocalDisk() && getMaxBytesLocalDisk() != 0) { LOG.warn("Configuration problem for cache " + getName() + ": MaxBytesLocalOffHeap equal or greater than MaxBytesLocalDisk. " + "This will result in useless disk storage."); } } } if (isOverflowToDisk()) { if (getMaxEntriesLocalHeap() >= getMaxEntriesLocalDisk() && getMaxEntriesLocalDisk() != 0) { LOG.warn("Configuration problem for cache " + getName() + ": MaxEntriesLocalHeap equal or greater than MaxEntriesLocalDisk. " + "This will result in useless disk storage."); } } }
/** * Accessor */ public boolean isOverflowToOffHeap() { return cacheConfiguration.isOverflowToOffHeap(); }
/** * Accessor */ public boolean isOverflowToOffHeap() { return cacheConfiguration.isOverflowToOffHeap(); }
/** * Accessor */ public boolean isOverflowToOffHeap() { return cacheConfiguration.isOverflowToOffHeap(); }
/** * Constructor for the LruMemoryStore object * The backing {@link java.util.LinkedHashMap} is created with LRU by access order. */ public LruMemoryStore(Ehcache cache, Store diskStore) { status = Status.STATUS_UNINITIALISED; this.maximumSize = cache.getCacheConfiguration().getMaxEntriesLocalHeap(); this.cachePinned = determineCachePinned(cache.getCacheConfiguration()); this.elementPinningEnabled = !cache.getCacheConfiguration().isOverflowToOffHeap(); this.cache = cache; this.diskStore = diskStore; if (cache.getCacheConfiguration().isOverflowToDisk()) { evictionObserver = null; } else { evictionObserver = StatisticBuilder.operation(EvictionOutcome.class).named("eviction").of(this).build(); } map = new SpoolingLinkedHashMap(); status = Status.STATUS_ALIVE; copyStrategyHandler = MemoryStore.getCopyStrategyHandler(cache); }
@Override public Object getConfigValue(Ehcache cache) { try { return cache.getCacheConfiguration().isOverflowToOffHeap(); } catch (NoSuchMethodError e) { return "na"; } } },
/** * {@inheritDoc} */ @Override public boolean isOverflowToOffHeap() { return cache.getCacheConfiguration().isOverflowToOffHeap(); }
/** * {@inheritDoc} */ @Override public boolean isOverflowToOffHeap() { return cache.getCacheConfiguration().isOverflowToOffHeap(); }
final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap();
FeaturesManager featuresManager = cacheManager.getFeaturesManager(); if (featuresManager == null) { if (configuration.isOverflowToOffHeap()) { throw new CacheException("Cache " + configuration.getName() + " cannot be configured because the enterprise features manager could not be found. "
builder.maxBytesLocalHeap(ehcacheConfig.getMaxBytesLocalHeap()); builder.maxBytesLocalOffheap(ehcacheConfig.getMaxBytesLocalOffHeap()); builder.offheapEnabled(ehcacheConfig.isOverflowToOffHeap()); builder.compressionEnabled(terracottaConfiguration.isCompressionEnabled()); builder.copyOnReadEnabled(ehcacheConfig.isCopyOnRead());
/** * Constructor for the LruMemoryStore object * The backing {@link java.util.LinkedHashMap} is created with LRU by access order. */ public LruMemoryStore(Ehcache cache, Store diskStore) { status = Status.STATUS_UNINITIALISED; this.maximumSize = cache.getCacheConfiguration().getMaxEntriesLocalHeap(); this.cachePinned = determineCachePinned(cache.getCacheConfiguration()); this.elementPinningEnabled = !cache.getCacheConfiguration().isOverflowToOffHeap(); this.cache = cache; this.diskStore = diskStore; map = new SpoolingLinkedHashMap(); status = Status.STATUS_ALIVE; }