use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class PartitionWideEntryOperation method runWithPartitionScanForNative.
// TODO unify this method with `runWithPartitionScan`
private void runWithPartitionScanForNative() {
// if we reach here, it means we didn't manage to leverage index and we fall-back to full-partition scan
int totalEntryCount = recordStore.size();
responses = new MapEntries(totalEntryCount);
Queue<Object> outComes = new LinkedList<>();
operator = operator(this, entryProcessor, getPredicate());
recordStore.forEach((key, record) -> {
Data dataKey = toHeapData(key);
Data response = operator.operateOnKey(dataKey).getResult();
if (response != null) {
responses.add(dataKey, response);
}
EntryEventType eventType = operator.getEventType();
if (eventType != null) {
outComes.add(dataKey);
outComes.add(operator.getOldValue());
outComes.add(operator.getByPreferringDataNewValue());
outComes.add(eventType);
outComes.add(operator.getEntry().getNewTtl());
}
}, false);
// in this case, iteration can miss some entries.
while (!outComes.isEmpty()) {
Data dataKey = (Data) outComes.poll();
Object oldValue = outComes.poll();
Object newValue = outComes.poll();
EntryEventType eventType = (EntryEventType) outComes.poll();
long newTtl = (long) outComes.poll();
operator.init(dataKey, oldValue, newValue, null, eventType, null, newTtl).doPostOperateOps();
}
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class AbstractEvictableRecordStore method doPostEvictionOperations.
@Override
public void doPostEvictionOperations(Data dataKey, Object value, ExpiryReason expiryReason) {
if (eventService.hasEventRegistration(SERVICE_NAME, name)) {
EntryEventType eventType = expiryReason != NOT_EXPIRED ? EXPIRED : EVICTED;
mapEventPublisher.publishEvent(thisAddress, name, eventType, dataKey, value, null);
}
if (expiryReason == MAX_IDLE_SECONDS) {
// only send expired key to back-up if
// it is expired according to idleness.
expirySystem.accumulateOrSendExpiredKey(dataKey, value.hashCode());
}
}
use of com.hazelcast.core.EntryEventType 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);
}
}
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class MapListenerFlagOperator method setAndGetAllListenerFlags.
/**
* Sets and gets all listener flags.
*/
private static int setAndGetAllListenerFlags() {
int listenerFlags = 0;
EntryEventType[] values = EntryEventType.values();
for (EntryEventType eventType : values) {
listenerFlags = listenerFlags | eventType.getType();
}
return listenerFlags;
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class InternalMapListenerAdapter method onEvent.
@Override
public void onEvent(IMapEvent event) {
EntryEventType eventType = event.getEventType();
if (eventType == null) {
return;
}
ListenerAdapter listenerAdapter = listenerAdapters[eventType.ordinal()];
if (listenerAdapter == null) {
return;
}
listenerAdapter.onEvent(event);
}
Aggregations