public interface EntryProcessor<K,V> extends Serializable
Map.Entry
. At the time you receive it
the entry is locked and not released until the EntryProcessor completes.
This obviates the need to explicitly lock as would be required with a ExecutorService
.
Performance can be very high as the data is not moved off the Member partition. This avoids network cost and, if
the storage format is InMemoryFormat.OBJECT
, then there is no de-serialization or serialization
cost.
EntryProcessors execute on the partition thread in a member. Multiple operations on the same partition are queued.
While executing partition migrations are not allowed. Any migrations are queued on the partition thread.
An EntryProcessor may not be re-entrant i.e. it may not access the same Map
. Limitation: you can only access
data on the same partition.
Note that to modify an entry by using EntryProcessors you should explicitly call the
Map.Entry.setValue(V)
method of Map.Entry
such as:
Override
public Object process(Map.Entry entry) {
Value value = entry.getValue();
// process and modify value
// ...
entry.setValue(value);
return result;
}
otherwise EntryProcessor does not guarantee that it will modify the entry.
EntryProcessor instances can be shared between threads. If an EntryProcessor instance contains mutable state, proper
concurrency control needs to be provided to coordinate access to mutable state. Another option is to rely on threadlocals.
Serialized instances of this interface are used in client-member communication, so changing an implementation's binary format
will render it incompatible with its previous versions.AbstractEntryProcessor
Modifier and Type | Method and Description |
---|---|
EntryBackupProcessor<K,V> |
getBackupProcessor()
Get the entry processor to be applied to backup entries.
|
Object |
process(Map.Entry<K,V> entry)
Process the entry without worrying about concurrency.
|
Object process(Map.Entry<K,V> entry)
Note that to modify an entry by using an EntryProcessor you should explicitly call
setValue()
method of Map.Entry
,
for example:
@Override public Object process(Map.Entry entry) { Value value = entry.getValue(); // process and modify value // ... entry.setValue(value); return result; }otherwise the
EntryProcessor
does not guarantee to modify the entry.
The entry's value will be null
, if the entry for the key doesn't exist. You
can create new mapping by setting a non-null value or remove existing mapping
entry by setting the value to null.
entry
- entry to be processedEntryProcessor
, such as
IMap.executeOnKey()
EntryBackupProcessor<K,V> getBackupProcessor()
null
can be returned to indicate that no backups should be made.Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.