PMI Handlers
PMI Operation Types
EventHandlers are registered through the static ServiceEvents class. The following registration calls are available:
ServiceEvents.setForEachEventHandler(Cache<K,V> cache, String handlerName, CacheEntryForEachHandler<K,V,P> eventHandler)
ServiceEvents.setForEachEventHandler(Cache<K,V> cache, String handlerName, CacheEntryForEachHandler<K,V,P> eventHandler, ParamHolder<P> paramHolder)
ServiceEvents.setReduceEventHandler(Cache<K,V> cache, String handlerName, CacheEntryReduceHandler<K,V,P,R> eventHandler)
ServiceEvents.setReduceEventHandler(Cache<K,V> cache, String handlerName, CacheEntryReduceHandler<K,V,P,R> eventHandler, ParamHolder<P> paramHolder)
Choosing a PMI Operation Type
Developers implement custom PMI logic by implementing an invocation handler, which is a class that derives from one of two base classes available in the library. These classes are the CacheEntryForEachHandler and the CacheEntryReduceHandler. Both classes are invoked on all entries in a cache; however, the CacheEntryReduceHandler returns a final result. For this reason, the delineation between the two classes can be summarized as:
If a PMI will evaluate an object and then optionally update that object, then
CacheEntryForEachHandler
should be used.If a PMI will evaluate an object, produce a result that should be returned to the caller, and then optionally update that object, then
CacheEntryReduceHandler
should be used.
Supplying Additional Invoke Parameters
Both PMI operations can optionally supply a parameter. To do this, create a class (or define an anonymous lambda) extending ParamHolder
. This class will be used to deserialize the param object supplied during the invoke.