public void run() {
final MapServiceContext mapServiceContext = getMapServiceContext();
response = new MapEntrySet();
MapEntrySimple entry;
final RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(), name);
final LocalMapStatsImpl mapStats
= mapServiceContext.getLocalMapStatsProvider().getLocalMapStatsImpl(name);
final Iterator<Record> iterator = recordStore.iterator();
while (iterator.hasNext()) {
final Record record = iterator.next();
final long start = Clock.currentTimeMillis();
final Data key = record.getKey();
final Object valueBeforeProcess = record.getValue();
final Object valueBeforeProcessObject = mapServiceContext.toObject(valueBeforeProcess);
Object objectKey = mapServiceContext.toObject(key);
if (getPredicate() != null) {
final SerializationService ss = getNodeEngine().getSerializationService();
QueryEntry queryEntry = new QueryEntry(ss, key, objectKey, valueBeforeProcessObject);
if (!getPredicate().apply(queryEntry)) {
continue;
}
}
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);