Interface AsyncEventListener
- All Superinterfaces:
CacheCallback,Declarable
A callback for events passing through the
A sample implementation of this interface is as follows:
AsyncEventQueue to which this listener is
attached. Implementers of interface AsyncEventListener process batches of
AsyncEvent delivered by the corresponding AsyncEventQueue. A sample implementation of this interface is as follows:
public class MyEventListener implements AsyncEventListener {
public boolean processEvents(List<AsyncEvent> events) {
for (Iterator i = events.iterator(); i.hasNext();) {
AsyncEvent event = (AsyncEvent) i.next();
String originalRegionName = event.getRegion().getName();
// For illustration purpose, use the event to update the duplicate of above region.
final Region duplicateRegion =
CacheHelper.getCache().getRegion(originalRegionName + "_DUP");
final Object key = event.getKey();
final Object value = event.getDeserializedValue();
final Operation op = event.getOperation();
if (op.isCreate()) {
duplicateRegion.create(key, value);
} else if (op.isUpdate()) {
duplicateRegion.put(key, value);
} else if (op.isDestroy()) {
duplicateRegion.destroy(key);
}
}
return true;
}
}
- Since:
- GemFire 7.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanprocessEvents(List<AsyncEvent> events) Process the list ofAsyncEvents.Methods inherited from interface org.apache.geode.cache.CacheCallback
closeMethods inherited from interface org.apache.geode.cache.Declarable
init, initialize
-
Method Details
-
processEvents
Process the list ofAsyncEvents. This method will asynchronously be called when events are queued to be processed. The size of the list will be up to batch size events where batch size is defined in theAsyncEventQueueFactory.- Parameters:
events- The list ofAsyncEventto process- Returns:
- boolean True represents whether the events were successfully processed, false otherwise.
-