Interface EntryProcessor<K,V,T>
-
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of cached valuesT- the type of the return value
public interface EntryProcessor<K,V,T>An invocable function that allows applications to perform compound operations on aCache.Entryatomically, according to the defined consistency of aCache.Any
Cache.Entrymutations will not take effect until after theprocess(MutableEntry, Object...)method has completed execution.If an exception is thrown by an
EntryProcessor, a Caching Implementation must wrap anyExceptionthrown wrapped in anEntryProcessorException. If this occurs no mutations will be made to theCache.Entry.Implementations may execute
EntryProcessors in situ, thus avoiding locking, round-trips and expensive network transfers.Effect of
MutableEntryoperationsCache.Entryaccess, via a call toCache.Entry.getValue(), will behave as ifCache.get(Object)was called for the key. This includes updating necessary statistics, consulting the configuredExpiryPolicyand loading from a configuredCacheLoader.Cache.Entrymutation, via a call toMutableEntry.setValue(Object), will behave as ifCache.put(Object, Object)was called for the key. This includes updating necessary statistics, consulting the configuredExpiryPolicy, notifyingCacheEntryListeners and writing to a configuredCacheWriter.Cache.Entryremoval, via a call toMutableEntry.remove(), will behave as ifCache.remove(Object)was called for the key. This includes updating necessary statistics, notifyingCacheEntryListeners and causing a delete on a configuredCacheWriter.As implementations may choose to execute
EntryProcessors remotely,EntryProcessors, together with specified parameters and return values, may be required to implementSerializable.Effect of multiple
Only the net effect of multiple operations has visibility outside of the Entry Processor. The entry is locked by the entry processor for the entire scope of the entry processor, so intermediate effects are not visible.MutableEntryoperations performed by oneEntryProcessorExample 1
In this example, anEntryProcessorcalls:MutableEntry.getValue()MutableEntry.setValue(Object)MutableEntry.getValue()MutableEntry.setValue(Object)
Cacheeffects:
Final value of the cache: last setValue
Statistics: one get and one put as the second get and the first put are internal to the EntryProcessor.
Listeners: second put will cause either a put or an update depending on whether there was an initial value for the entry.
CacheLoader: Invoked by the first get only if the entry is not present, a loader was registered and read through is enabled.
CacheWriter: Invoked by the second put only as the first put was internal to the Entry Processor.
ExpiryPolicy: The first get and the second put only are visible to the ExpiryPolicy.
Example 2
In this example, anEntryProcessorcalls:MutableEntry.getValue()MutableEntry.remove()}MutableEntry.getValue()MutableEntry.setValue(Object)
Cacheeffects:
Final value of the cache: last setValue
Statistics: one get and one put as the second get and the first put are internal to the EntryProcessor.
Listeners: second put will cause either a put or an update depending on whether there was an initial value for the entry.
CacheLoader: Invoked by the first get only if the entry is not present, a loader was registered and read through is enabled.
CacheWriter: Invoked by the second put only as the first put was internal to the Entry Processor.
ExpiryPolicy: The first get and the second put only are visible to the ExpiryPolicy.
Example 3
In this example, anEntryProcessorcalls:MutableEntry.getValue()MutableEntry.setValue(Object)}MutableEntry.getValue()MutableEntry.setValue(Object)MutableEntry.remove()
Cacheeffects:
Final value of the cache: the entry is removed if it was present
Statistics: one get and one remove as the second get and the two puts are internal to the EntryProcessor.
Listeners: remove if there was initial value in the cache, otherwise no listener invoked.
CacheLoader: Invoked by the first get only if the entry is not present, a loader was registered and read through is enabled.
CacheWriter: Invoked by the remove only as the two puts are internal to the Entry Processor, provided that the first #getValue was non-null.
ExpiryPolicy: The first get only is visible to the ExpiryPolicy. There is no remove event in ExpiryPolicy.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Tprocess(MutableEntry<K,V> entry, java.lang.Object... arguments)Process an entry.
-
-
-
Method Detail
-
process
T process(MutableEntry<K,V> entry, java.lang.Object... arguments) throws EntryProcessorException
Process an entry.- Parameters:
entry- the entryarguments- a number of arguments to the process.- Returns:
- the user-defined result of the processing, if any.
- Throws:
EntryProcessorException- if there is a failure in entry processing.
-
-