protected CacheMonitorState snapshotAndCalculateStatistics(String name, boolean calculate)
{
Cache cache = cacheManager.getCache(name);
CacheMonitorStateImpl state = new CacheMonitorStateImpl(name);
Statistics statistics = cache.getStatistics();
state.setMemoryStoreSize(cache.getMemoryStoreSize());
if (calculate)
{
state.setInMemorySize(cache.calculateInMemorySize());
if (calculateObjectCount)
{
state.setObjectCount(statistics.getObjectCount());
}
else
{
state.setObjectCount(0);
}
calculatedStates.put(name, new CalculatedState(state.getInMemorySize(), state.getObjectCount()));
}
else
{
CalculatedState cs = calculatedStates.get(name);
if (cs == null)
{
state.setInMemorySize(0);
state.setObjectCount(0);
}
else
{
state.setInMemorySize(cs.inMemorySize);
state.setObjectCount(cs.objectCount);
}
}
state.setSize(cache.getSize());
state.setDiskStoreSize(cache.getDiskStoreSize());
state.setAverageGetTime(statistics.getAverageGetTime());
state.setCacheHits(statistics.getCacheHits());
state.setCacheMisses(statistics.getCacheMisses());
state.setEvictionCount(statistics.getEvictionCount());
state.setInMemoryHits(statistics.getInMemoryHits());
state.setOnDiskHits(statistics.getOnDiskHits());
state.setMaxElementsInMemory(cache.getCacheConfiguration().getMaxElementsInMemory());
state.setMaxElementsOnDisk(cache.getCacheConfiguration().getMaxElementsOnDisk());
state.setTimeToIdle(cache.getCacheConfiguration().getTimeToIdleSeconds());
state.setTimeToLive(cache.getCacheConfiguration().getTimeToLiveSeconds());
return state;