Interface AsyncEventListener

All Superinterfaces:
CacheCallback, Declarable

public interface AsyncEventListener extends CacheCallback
A callback for events passing through the 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 Details

    • processEvents

      boolean processEvents(List<AsyncEvent> events)
      Process the list of AsyncEvents. 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 the AsyncEventQueueFactory.
      Parameters:
      events - The list of AsyncEvent to process
      Returns:
      boolean True represents whether the events were successfully processed, false otherwise.