Search in sources :

Example 1 with LocalMultiMapStatsImpl

use of com.hazelcast.monitor.impl.LocalMultiMapStatsImpl in project hazelcast by hazelcast.

the class MultiMapService method createStats.

public LocalMultiMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
    Address thisAddress = clusterService.getThisAddress();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
        IPartition partition = nodeEngine.getPartitionService().getPartition(i);
        MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
        MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
        if (multiMapContainer == null) {
            continue;
        }
        Address owner = partition.getOwnerOrNull();
        if (owner != null) {
            if (owner.equals(thisAddress)) {
                lockedEntryCount += multiMapContainer.getLockedCount();
                for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                    hits += multiMapValue.getHits();
                    ownedEntryCount += multiMapValue.getCollection(false).size();
                }
            } else {
                int backupCount = multiMapContainer.getConfig().getTotalBackupCount();
                for (int j = 1; j <= backupCount; j++) {
                    Address replicaAddress = partition.getReplicaAddress(j);
                    int memberSize = nodeEngine.getClusterService().getMembers().size();
                    int tryCount = REPLICA_ADDRESS_TRY_COUNT;
                    // wait if the partition table is not updated yet
                    while (memberSize > backupCount && replicaAddress == null && tryCount-- > 0) {
                        try {
                            Thread.sleep(REPLICA_ADDRESS_SLEEP_WAIT_MILLIS);
                        } catch (InterruptedException e) {
                            throw ExceptionUtil.rethrow(e);
                        }
                        replicaAddress = partition.getReplicaAddress(j);
                    }
                    if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
                        for (MultiMapValue multiMapValue : multiMapContainer.getMultiMapValues().values()) {
                            backupEntryCount += multiMapValue.getCollection(false).size();
                        }
                    }
                }
            }
        }
    }
    stats.setOwnedEntryCount(ownedEntryCount);
    stats.setBackupEntryCount(backupEntryCount);
    stats.setHits(hits);
    stats.setLockedEntryCount(lockedEntryCount);
    return stats;
}
Also used : Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) LocalMultiMapStatsImpl(com.hazelcast.monitor.impl.LocalMultiMapStatsImpl) IPartition(com.hazelcast.spi.partition.IPartition) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Aggregations

ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)1 LocalMultiMapStatsImpl (com.hazelcast.monitor.impl.LocalMultiMapStatsImpl)1 Address (com.hazelcast.nio.Address)1 IPartition (com.hazelcast.spi.partition.IPartition)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1