Search in sources :

Example 1 with LocalReplicatedMapStatsImpl

use of com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl 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 LocalReplicatedMapStatsImpl

use of com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl in project hazelcast by hazelcast.

the class ReplicatedMapGetMessageTask method processResponseBeforeSending.

@Override
protected Object processResponseBeforeSending(Object response) {
    ReplicatedMapService replicatedMapService = getService(ReplicatedMapService.SERVICE_NAME);
    if (replicatedMapService.getReplicatedMapConfig(parameters.name).isStatisticsEnabled()) {
        LocalReplicatedMapStatsImpl stats = replicatedMapService.getLocalReplicatedMapStatsImpl(parameters.name);
        stats.incrementGetsNanos(Timer.nanosElapsed(startTimeNanos));
    }
    return response;
}
Also used : LocalReplicatedMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService)

Example 3 with LocalReplicatedMapStatsImpl

use of com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl in project hazelcast by hazelcast.

the class ReplicatedMapEventPublishingService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    if ((event instanceof EntryEventData)) {
        EntryEventData entryEventData = (EntryEventData) event;
        Member member = getMember(entryEventData);
        EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
        EntryListener entryListener = (EntryListener) listener;
        switch(entryEvent.getEventType()) {
            case ADDED:
                entryListener.entryAdded(entryEvent);
                break;
            case EVICTED:
                entryListener.entryEvicted(entryEvent);
                break;
            case UPDATED:
                entryListener.entryUpdated(entryEvent);
                break;
            case REMOVED:
                entryListener.entryRemoved(entryEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + entryEvent.getEventType() + " not supported");
        }
        String mapName = ((EntryEventData) event).getMapName();
        Boolean statisticsEnabled = statisticsMap.get(mapName);
        if (statisticsEnabled == null) {
            ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
            statisticsEnabled = mapConfig.isStatisticsEnabled();
            statisticsMap.put(mapName, statisticsEnabled);
        }
        if (statisticsEnabled) {
            int partitionId = nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
            ReplicatedRecordStore recordStore = replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
            if (recordStore instanceof AbstractReplicatedRecordStore) {
                LocalReplicatedMapStatsImpl stats = ((AbstractReplicatedRecordStore) recordStore).getStats();
                stats.incrementReceivedEvents();
            }
        }
    } else if (event instanceof MapEventData) {
        MapEventData mapEventData = (MapEventData) event;
        Member member = getMember(mapEventData);
        MapEvent mapEvent = new MapEvent(mapEventData.getMapName(), member, mapEventData.getEventType(), mapEventData.getNumberOfEntries());
        EntryListener entryListener = (EntryListener) listener;
        EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
        if (type == EntryEventType.CLEAR_ALL) {
            entryListener.mapCleared(mapEvent);
        } else {
            throw new IllegalArgumentException("Unsupported EntryEventType: " + type);
        }
    }
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) MapEvent(com.hazelcast.map.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryListener(com.hazelcast.core.EntryListener) EntryEventType(com.hazelcast.core.EntryEventType) LocalReplicatedMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) EntryEvent(com.hazelcast.core.EntryEvent) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Member(com.hazelcast.cluster.Member)

Aggregations

LocalReplicatedMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalReplicatedMapStatsImpl)3 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)2 ReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore)2 Member (com.hazelcast.cluster.Member)1 EntryEvent (com.hazelcast.core.EntryEvent)1 EntryEventType (com.hazelcast.core.EntryEventType)1 EntryListener (com.hazelcast.core.EntryListener)1 EmptyLocalReplicatedMapStats (com.hazelcast.internal.monitor.impl.EmptyLocalReplicatedMapStats)1 MapEvent (com.hazelcast.map.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)1 MapEventData (com.hazelcast.map.impl.event.MapEventData)1 LocalReplicatedMapStats (com.hazelcast.replicatedmap.LocalReplicatedMapStats)1 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1 AbstractReplicatedRecordStore (com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore)1 ReplicatedRecord (com.hazelcast.replicatedmap.impl.record.ReplicatedRecord)1