Eh107CacheStatisticsMXBean( String cacheName, Eh107CacheManager cacheManager, InternalCache<?, ?> cache) { super(cacheName, cacheManager, "CacheStatistics"); this.bulkMethodEntries = cache.getBulkMethodEntries(); get = findCacheStatistic(cache, CacheOperationOutcomes.GetOutcome.class, "get"); put = findCacheStatistic(cache, CacheOperationOutcomes.PutOutcome.class, "put"); remove = findCacheStatistic(cache, CacheOperationOutcomes.RemoveOutcome.class, "remove"); putIfAbsent = findCacheStatistic(cache, CacheOperationOutcomes.PutIfAbsentOutcome.class, "putIfAbsent"); replace = findCacheStatistic(cache, CacheOperationOutcomes.ReplaceOutcome.class, "replace"); conditionalRemove = findCacheStatistic( cache, CacheOperationOutcomes.ConditionalRemoveOutcome.class, "conditionalRemove"); lowestTierEviction = findLowestTierStatistic(cache, StoreOperationOutcomes.EvictionOutcome.class, "eviction"); averageGetTime = new LatencyMonitor<CacheOperationOutcomes.GetOutcome>( allOf(CacheOperationOutcomes.GetOutcome.class)); get.addDerivedStatistic(averageGetTime); averagePutTime = new LatencyMonitor<CacheOperationOutcomes.PutOutcome>( allOf(CacheOperationOutcomes.PutOutcome.class)); put.addDerivedStatistic(averagePutTime); averageRemoveTime = new LatencyMonitor<CacheOperationOutcomes.RemoveOutcome>( allOf(CacheOperationOutcomes.RemoveOutcome.class)); remove.addDerivedStatistic(averageRemoveTime); }
@Override public long getCacheRemovals() { return normalize( getBulkCount(BulkOps.REMOVE_ALL) - compensatingCounters.bulkRemovals + remove.sum(EnumSet.of(CacheOperationOutcomes.RemoveOutcome.SUCCESS)) + conditionalRemove.sum( EnumSet.of(CacheOperationOutcomes.ConditionalRemoveOutcome.SUCCESS)) - compensatingCounters.cacheRemovals); }
private long getMisses() { return getBulkCount(BulkOps.GET_ALL_MISS) + get.sum( EnumSet.of( CacheOperationOutcomes.GetOutcome.MISS_NO_LOADER, CacheOperationOutcomes.GetOutcome.MISS_WITH_LOADER)) + putIfAbsent.sum(EnumSet.of(CacheOperationOutcomes.PutIfAbsentOutcome.PUT)) + replace.sum(EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.MISS_NOT_PRESENT)) + conditionalRemove.sum( EnumSet.of(CacheOperationOutcomes.ConditionalRemoveOutcome.FAILURE_KEY_MISSING)); }
@Override public long getCachePuts() { return normalize( getBulkCount(BulkOps.PUT_ALL) - compensatingCounters.bulkPuts + put.sum(EnumSet.of(CacheOperationOutcomes.PutOutcome.PUT)) + put.sum(EnumSet.of(CacheOperationOutcomes.PutOutcome.UPDATED)) + putIfAbsent.sum(EnumSet.of(CacheOperationOutcomes.PutIfAbsentOutcome.PUT)) + replace.sum(EnumSet.of(CacheOperationOutcomes.ReplaceOutcome.HIT)) - compensatingCounters.cachePuts); }
/** * Gets a reference to the {@link org.terracotta.statistics.OperationStatistic} instance holding * the class of statistics specified for the {@code Ehcache} instance provided. * * @param ehcache the {@code Ehcache} instance for which the {@code OperationStatistic} instance * should be obtained * @param statsClass the {@code Class} of statistics for which the {@code OperationStatistic} * instance should be obtained * @param <E> the {@code Enum} type for the statistics * @return a reference to the {@code OperationStatistic} instance holding the {@code statsClass} * statistics; may be {@code null} if {@code statsClass} statistics do not exist for {@code * ehcache} */ private static <E extends Enum<E>> OperationStatistic<E> getOperationStatistic( final Ehcache<?, ?> ehcache, final Class<E> statsClass) { for (final TreeNode statNode : ContextManager.nodeFor(ehcache).getChildren()) { final Object statObj = statNode.getContext().attributes().get("this"); if (statObj instanceof OperationStatistic<?>) { @SuppressWarnings("unchecked") final OperationStatistic<E> statistic = (OperationStatistic<E>) statObj; if (statistic.type().equals(statsClass)) { return statistic; } } } return null; }
private long getHits() { return getBulkCount(BulkOps.GET_ALL_HITS) + get.sum( EnumSet.of( CacheOperationOutcomes.GetOutcome.HIT_NO_LOADER, CacheOperationOutcomes.GetOutcome.HIT_WITH_LOADER)) + putIfAbsent.sum(EnumSet.of(CacheOperationOutcomes.PutIfAbsentOutcome.PUT)) + replace.sum( EnumSet.of( CacheOperationOutcomes.ReplaceOutcome.HIT, CacheOperationOutcomes.ReplaceOutcome.MISS_PRESENT)) + conditionalRemove.sum( EnumSet.of( CacheOperationOutcomes.ConditionalRemoveOutcome.SUCCESS, CacheOperationOutcomes.ConditionalRemoveOutcome.FAILURE_KEY_PRESENT)); }
/** * Gets the value of the statistic indicated from an {@link * org.terracotta.statistics.OperationStatistic} instance. * * @param operationStatistic the {@code OperationStatistic} instance from which the statistic is * to be obtained * @param statId the {@code Enum} constant identifying the statistic for which the value must be * obtained * @param <E> The {@code Enum} type for the statistics * @return the value, possibly null, for {@code statId} about {@code ehcache} */ private static <E extends Enum<E>> Number getStatistic( final OperationStatistic<E> operationStatistic, final E statId) { if (operationStatistic != null) { final ValueStatistic<Long> valueStatistic = operationStatistic.statistic(statId); return (valueStatistic == null ? null : valueStatistic.value()); } return null; }
@Override public long getCacheEvictions() { return normalize( lowestTierEviction.sum(EnumSet.of(StoreOperationOutcomes.EvictionOutcome.SUCCESS)) - compensatingCounters.cacheEvictions); }