Search in sources :

Example 1 with LocalReplicatedMapStats

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;
}
Also used : LocalReplicatedMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl) ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EmptyLocalReplicatedMapStats(com.hazelcast.internal.monitor.impl.EmptyLocalReplicatedMapStats) LocalReplicatedMapStats(com.hazelcast.replicatedmap.LocalReplicatedMapStats)

Example 2 with LocalReplicatedMapStats

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);
}
Also used : ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) LocalReplicatedMapStats(com.hazelcast.replicatedmap.LocalReplicatedMapStats) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)2 LocalReplicatedMapStats (com.hazelcast.replicatedmap.LocalReplicatedMapStats)2 EmptyLocalReplicatedMapStats (com.hazelcast.internal.monitor.impl.EmptyLocalReplicatedMapStats)1 LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)1 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)1 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1