use of com.hazelcast.replicatedmap.LocalReplicatedMapStats in project hazelcast by hazelcast.
the class LocalReplicatedMapStatsProvider method getLocalReplicatedMapStats.
LocalReplicatedMapStats getLocalReplicatedMapStats(String name) {
ReplicatedMapConfig replicatedMapConfig = getReplicatedMapConfig(name);
final LocalReplicatedMapStats result;
if (!replicatedMapConfig.isStatisticsEnabled()) {
result = EMPTY_LOCAL_MAP_STATS;
} else {
LocalReplicatedMapStatsImpl stats = getLocalReplicatedMapStatsImpl(name);
long hits = 0;
long count = 0;
long memoryUsage = 0;
boolean isBinary = (replicatedMapConfig.getInMemoryFormat() == InMemoryFormat.BINARY);
for (PartitionContainer container : partitionContainers) {
ReplicatedRecordStore store = container.getRecordStore(name);
if (store == null) {
continue;
}
Iterator<ReplicatedRecord> iterator = store.recordIterator();
while (iterator.hasNext()) {
ReplicatedRecord record = iterator.next();
stats.setLastAccessTime(max(stats.getLastAccessTime(), record.getLastAccessTime()));
stats.setLastUpdateTime(max(stats.getLastUpdateTime(), record.getUpdateTime()));
hits += record.getHits();
if (isBinary) {
memoryUsage += ((HeapData) record.getValueInternal()).getHeapCost();
}
count++;
}
}
stats.setOwnedEntryCount(count);
stats.setHits(hits);
stats.setOwnedEntryMemoryCost(memoryUsage);
result = stats;
}
return result;
}
use of com.hazelcast.replicatedmap.LocalReplicatedMapStats in project hazelcast by hazelcast.
the class ReplicatedMapServiceTest method testGetLocalReplicatedMapStatsNoObjectGenerationIfDisabledStats.
@Test
public void testGetLocalReplicatedMapStatsNoObjectGenerationIfDisabledStats() {
String name = randomMapName();
ReplicatedMapConfig replicatedMapConfig = new ReplicatedMapConfig();
replicatedMapConfig.setName(name);
replicatedMapConfig.setStatisticsEnabled(false);
nodeEngine.getConfig().addReplicatedMapConfig(replicatedMapConfig);
ReplicatedMapService service = new ReplicatedMapService(nodeEngine);
LocalReplicatedMapStats stats = service.getLocalReplicatedMapStats(name);
LocalReplicatedMapStats stats2 = service.getLocalReplicatedMapStats(name);
LocalReplicatedMapStats stats3 = service.getLocalReplicatedMapStats(name);
assertSame(stats, stats2);
assertSame(stats2, stats3);
}
Aggregations