final Object valueBeforeProcess = mapEntry.getValue();
final Object valueBeforeProcessObject = mapService.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 = mapService.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;
}
// take this case as a read so no need to fire an event.
else if (!entry.isModified()) {
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));
}
}
if (eventType != __NO_NEED_TO_FIRE_EVENT) {
final Data oldValue = mapService.toData(valueBeforeProcess);
final Data value = mapService.toData(valueAfterProcess);
mapService.publishEvent(getCallerAddress(), name, eventType, key, oldValue, value);
if (mapService.isNearCacheAndInvalidationEnabled(name)) {
mapService.invalidateAllNearCaches(name, key);
}
if (mapContainer.getWanReplicationPublisher() != null && mapContainer.getWanMergePolicy() != null) {
if (EntryEventType.REMOVED.equals(eventType)) {
mapService.publishWanReplicationRemove(name, key, Clock.currentTimeMillis());
} else {
Record record = recordStore.getRecord(key);
Data tempValue = mapService.toData(dataValue);
final SimpleEntryView entryView = mapService.createSimpleEntryView(key, tempValue, record);
mapService.publishWanReplicationUpdate(name, entryView);
}
}
}