protected SizeOfPolicyConfiguration sizeOfPolicy(final String path, final Config conf) { SizeOfPolicyConfiguration sizeOfPolicy = new SizeOfPolicyConfiguration(); sint(path, conf, "maxDepth", sizeOfPolicy::maxDepth); sstr(path, conf, "maxDepthExceededBehavior", sizeOfPolicy::maxDepthExceededBehavior); return sizeOfPolicy; }
private void init() { if (sizeOfPolicyConfiguration == null) { return; } addAttribute(new SimpleNodeAttribute("maxDepth", sizeOfPolicyConfiguration.getMaxDepth()) .optional(true).defaultValue(SizeOfPolicyConfiguration.DEFAULT_MAX_SIZEOF_DEPTH)); addAttribute(new SimpleNodeAttribute("maxDepthExceededBehavior", sizeOfPolicyConfiguration.getMaxDepthExceededBehavior()) .optional(true).defaultValue(SizeOfPolicyConfiguration.DEFAULT_MAX_DEPTH_EXCEEDED_BEHAVIOR)); }
/** * Sets the behavior of the SizeOf engine when the max depth is reached * * @param maxDepthExceededBehavior the behavior of the SizeOf engine when the max depth is reached */ public void setMaxDepthExceededBehavior(String maxDepthExceededBehavior) { if (maxDepthExceededBehavior == null) { throw new IllegalArgumentException("maxDepthExceededBehavior must be non-null"); } this.maxDepthExceededBehavior(MaxDepthExceededBehavior.valueOf(MaxDepthExceededBehavior.class, maxDepthExceededBehavior.toUpperCase())); }
/** * Helper method which resolves the MaxDepthExceededBehavior of a cache, using the cache manager's one if none was configured * on the cache itself. * * @param cache the cache from which to resolve the MaxDepthExceededBehavior * @return the resolved MaxDepthExceededBehavior */ public static MaxDepthExceededBehavior resolveBehavior(Ehcache cache) { if (cache == null) { return DEFAULT_MAX_DEPTH_EXCEEDED_BEHAVIOR; } CacheManager cacheManager = cache.getCacheManager(); if (cacheManager == null) { return resolvePolicy(null, cache.getCacheConfiguration()).getMaxDepthExceededBehavior(); } else { return resolvePolicy(cacheManager.getConfiguration(), cache.getCacheConfiguration()).getMaxDepthExceededBehavior(); } }
/** * Helper method which resolves the max depth of a cache, using the cache manager's one if none was configured * on the cache itself. * * @param cache the cache from which to resolve the max depth * @return the resolved max depth */ public static int resolveMaxDepth(Ehcache cache) { if (cache == null) { return DEFAULT_MAX_SIZEOF_DEPTH; } CacheManager cacheManager = cache.getCacheManager(); return resolvePolicy(cacheManager == null ? null : cacheManager.getConfiguration(), cache.getCacheConfiguration()).getMaxDepth(); }
/** * Measures the size of the memory store by using the sizeof engine. * <p> * Warning: This method can be very expensive to run. Allow approximately 1 second * per 1MB of entries. Running this method could create liveness problems * because the object lock is held for a long period * * @return the size, in bytes */ public final synchronized long getSizeInBytes() throws CacheException { SizeOfEngine defaultSizeOfEngine = SizeOfEngineLoader.newSizeOfEngine( SizeOfPolicyConfiguration.resolveMaxDepth(cache), SizeOfPolicyConfiguration.resolveBehavior(cache) .equals(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT), true ); long sizeInBytes = 0; for (Object o : map.entrySet()) { Map.Entry entry = (Map.Entry)o; Element element = (Element) entry.getValue(); if (element != null) { Size size = defaultSizeOfEngine.sizeOf(entry.getKey(), element, null); sizeInBytes += size.getCalculated(); } } return sizeInBytes; }
private static void addSizeOfPolicyConfigurationElement(NodeElement element, CacheConfiguration cacheConfiguration) { SizeOfPolicyConfiguration sizeOfPolicyConfiguration = cacheConfiguration.getSizeOfPolicyConfiguration(); if (sizeOfPolicyConfiguration != null && !Configuration.DEFAULT_SIZEOF_POLICY_CONFIGURATION.equals(sizeOfPolicyConfiguration)) { element.addChildElement(new SizeOfPolicyConfigurationElement(element, sizeOfPolicyConfiguration)); } }
/** * Builder method to set the behavior of the SizeOf engine when the max depth is reached using a String object * * @param maxDepthExceededBehavior the behavior of the SizeOf engine when the max depth is reached * @return this SizeOfPolicyConfiguration object */ public SizeOfPolicyConfiguration maxDepthExceededBehavior(String maxDepthExceededBehavior) { setMaxDepthExceededBehavior(maxDepthExceededBehavior); return this; }
/** * Builder method to set the maximum depth the SizeOf engine can normally traverse * * @param maxDepth the maximum depth the SizeOf engine can normally traverse * @return this SizeOfPolicyConfiguration object */ public SizeOfPolicyConfiguration maxDepth(int maxDepth) { setMaxDepth(maxDepth); return this; }
configuration.setName(this.cacheManagerName); configuration.getSizeOfPolicyConfiguration().maxDepthExceededBehavior(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT); configuration.getSizeOfPolicyConfiguration().maxDepth(100);
@Override public Properties getProperties() { Configuration ec = cacheManager.getConfiguration(); Properties p = new Properties(); p.put("name", ec.getName()); p.put("source", ec.getConfigurationSource().toString()); p.put("timeoutSeconds", ec.getDefaultTransactionTimeoutInSeconds()); p.put("maxBytesDisk", ec.getMaxBytesLocalDisk()); p.put("maxBytesHeap", ec.getMaxBytesLocalHeap()); p.put("maxDepth", ec.getSizeOfPolicyConfiguration().getMaxDepth()); p.put("defaultCacheMaxEntries", ec.getDefaultCacheConfiguration().getMaxEntriesLocalHeap()); p.put("defaultCacheTimeToIdleSecs", ec.getDefaultCacheConfiguration().getTimeToIdleSeconds()); p.put("defaultCacheTimeToLiveSecs", ec.getDefaultCacheConfiguration().getTimeToLiveSeconds()); p.put("defaultCacheEternal", ec.getDefaultCacheConfiguration().isEternal()); return p; }
private DiskStore(DiskStorageFactory disk, Ehcache cache, Pool onHeapPool, Pool onDiskPool) { this.segments = new Segment[DEFAULT_SEGMENT_COUNT]; this.segmentShift = Integer.numberOfLeadingZeros(segments.length - 1); EventRateSimpleMovingAverage hitRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS); EventRateSimpleMovingAverage missRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS); OperationStatistic<GetOutcome> getStatistic = StatisticsManager.getOperationStatisticFor(getObserver); getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.HIT), hitRate)); getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.MISS), missRate)); this.onHeapPoolAccessor = onHeapPool.createPoolAccessor(new DiskStoreHeapPoolParticipant(hitRate, missRate), SizeOfPolicyConfiguration.resolveMaxDepth(cache), SizeOfPolicyConfiguration.resolveBehavior(cache).equals(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT)); this.onDiskPoolAccessor = onDiskPool.createPoolAccessor(new DiskStoreDiskPoolParticipant(hitRate, missRate), new DiskSizeOfEngine()); for (int i = 0; i < this.segments.length; ++i) { this.segments[i] = new Segment(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, disk, cache.getCacheConfiguration(), onHeapPoolAccessor, onDiskPoolAccessor, cache.getCacheEventNotificationService(), evictionObserver); } this.disk = disk; this.disk.bind(this); this.status.set(Status.STATUS_ALIVE); }
/** * Helper method which resolves the max depth of a cache, using the cache manager's one if none was configured * on the cache itself. * * @param cache the cache from which to resolve the max depth * @return the resolved max depth */ public static int resolveMaxDepth(Ehcache cache) { if (cache == null) { return DEFAULT_MAX_SIZEOF_DEPTH; } CacheManager cacheManager = cache.getCacheManager(); return resolvePolicy(cacheManager == null ? null : cacheManager.getConfiguration(), cache.getCacheConfiguration()).getMaxDepth(); }
/** * Helper method which resolves the MaxDepthExceededBehavior of a cache, using the cache manager's one if none was configured * on the cache itself. * * @param cache the cache from which to resolve the MaxDepthExceededBehavior * @return the resolved MaxDepthExceededBehavior */ public static MaxDepthExceededBehavior resolveBehavior(Ehcache cache) { if (cache == null) { return DEFAULT_MAX_DEPTH_EXCEEDED_BEHAVIOR; } CacheManager cacheManager = cache.getCacheManager(); if (cacheManager == null) { return resolvePolicy(null, cache.getCacheConfiguration()).getMaxDepthExceededBehavior(); } else { return resolvePolicy(cacheManager.getConfiguration(), cache.getCacheConfiguration()).getMaxDepthExceededBehavior(); } }
private void testAddSizeOfPolicyElement() { SizeOfPolicyConfiguration sizeOfPolicyConfiguration = configuration.getSizeOfPolicyConfiguration(); if (sizeOfPolicyConfiguration != null && !Configuration.DEFAULT_SIZEOF_POLICY_CONFIGURATION.equals(sizeOfPolicyConfiguration)) { addChildElement(new SizeOfPolicyConfigurationElement(this, sizeOfPolicyConfiguration)); } }
/** * Builder method to set the behavior of the SizeOf engine when the max depth is reached using a String object * * @param maxDepthExceededBehavior the behavior of the SizeOf engine when the max depth is reached * @return this SizeOfPolicyConfiguration object */ public SizeOfPolicyConfiguration maxDepthExceededBehavior(String maxDepthExceededBehavior) { setMaxDepthExceededBehavior(maxDepthExceededBehavior); return this; }
/** * Builder method to set the maximum depth the SizeOf engine can normally traverse * * @param maxDepth the maximum depth the SizeOf engine can normally traverse * @return this SizeOfPolicyConfiguration object */ public SizeOfPolicyConfiguration maxDepth(int maxDepth) { setMaxDepth(maxDepth); return this; }
} else { this.poolAccessor = pool.createPoolAccessor(new Participant(), SizeOfPolicyConfiguration.resolveMaxDepth(cache), SizeOfPolicyConfiguration.resolveBehavior(cache).equals(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT));
sizeOfPolicyConfiguration = getConfiguration().getSizeOfPolicyConfiguration(); return SizeOfEngineLoader.newSizeOfEngine(sizeOfPolicyConfiguration.getMaxDepth(), sizeOfPolicyConfiguration.getMaxDepthExceededBehavior().isAbort(), false);
/** * Helper method which resolves the max depth of a cache, using the cache manager's one if none was configured * on the cache itself. * * @param cache the cache from which to resolve the max depth * @return the resolved max depth */ public static int resolveMaxDepth(Ehcache cache) { if (cache == null) { return DEFAULT_MAX_SIZEOF_DEPTH; } CacheManager cacheManager = cache.getCacheManager(); return resolvePolicy(cacheManager == null ? null : cacheManager.getConfiguration(), cache.getCacheConfiguration()).getMaxDepth(); }