@Override
public void run() throws Exception {
final MapServiceContext mapServiceContext = getMapServiceContext();
response = new MapEntrySet();
final InternalPartitionService partitionService = getNodeEngine().getPartitionService();
final RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(), name);
final LocalMapStatsImpl mapStats = mapServiceContext
.getLocalMapStatsProvider().getLocalMapStatsImpl(name);
MapEntrySimple entry;
for (Data key : keys) {
if (partitionService.getPartitionId(key) != getPartitionId()) {
continue;
}
long start = Clock.currentTimeMillis();
Object objectKey = mapServiceContext.toObject(key);
final Map.Entry<Data, Object> mapEntry = recordStore.getMapEntry(key);
final Object valueBeforeProcess = mapEntry.getValue();
final Object valueBeforeProcessObject = mapServiceContext.toObject(valueBeforeProcess);
entry = new MapEntrySimple(objectKey, valueBeforeProcessObject);
final Object result = entryProcessor.process(entry);
final Object valueAfterProcess = entry.getValue();
Data dataValue = null;
if (result != null) {
dataValue = mapServiceContext.toData(result);
response.add(new AbstractMap.SimpleImmutableEntry<Data, Data>(key, dataValue));
}
EntryEventType eventType;
if (valueAfterProcess == null) {
recordStore.remove(key);
mapStats.incrementRemoves(getLatencyFrom(start));
eventType = EntryEventType.REMOVED;
} else {
if (valueBeforeProcessObject == null) {
mapStats.incrementPuts(getLatencyFrom(start));
eventType = EntryEventType.ADDED;
} else if (!entry.isModified()) {
// take this case as a read so no need to fire an event.
mapStats.incrementGets(getLatencyFrom(start));
eventType = NO_NEED_TO_FIRE_EVENT;
} else {
mapStats.incrementPuts(getLatencyFrom(start));
eventType = EntryEventType.UPDATED;
}
// todo if this is a read only operation, record access operations should be done.
if (eventType != NO_NEED_TO_FIRE_EVENT) {
recordStore.put(new AbstractMap.SimpleImmutableEntry<Data, Object>(key, valueAfterProcess));
}
}
fireEvent(key, valueBeforeProcess, valueAfterProcess, eventType);
invalidateNearCache(key);
publishWanReplicationEvent(key, dataValue, recordStore, eventType);