use of com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl in project hazelcast by hazelcast.
the class ReplicatedMapService method createReplicatedMapStats.
public LocalReplicatedMapStatsImpl createReplicatedMapStats(String name) {
LocalReplicatedMapStatsImpl stats = getLocalMapStatsImpl(name);
long hits = 0;
long count = 0;
long memoryUsage = 0;
boolean isBinary = (getReplicatedMapConfig(name).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(Math.max(stats.getLastAccessTime(), record.getLastAccessTime()));
stats.setLastUpdateTime(Math.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);
return stats;
}
use of com.hazelcast.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());
switch(type) {
case CLEAR_ALL:
entryListener.mapCleared(mapEvent);
break;
default:
throw new IllegalArgumentException("event type " + type + " not supported");
}
}
}
Aggregations