Class ContinuousQueryListenerAdapter

java.lang.Object
org.springframework.data.gemfire.listener.adapter.ContinuousQueryListenerAdapter
All Implemented Interfaces:
ContinuousQueryListener

public class ContinuousQueryListenerAdapter extends Object implements ContinuousQueryListener
Event listener adapter that delegates the handling of messages to target listener methods via reflection, with flexible event type conversion. Allows listener methods to operate on event content types, completely independent from the GemFire/Geode API.

Modeled as much as possible after the JMS MessageListenerAdapter in the core Spring Framework.

By default, the content of incoming GemFire/Geode CQ events gets extracted before being passed into the target listener method, to let the target method operate on event content types such as Object or Operation instead of the raw CqEvent.

Find below some examples of method signatures compliant with this adapter class. This first example handles all CqEvent types and gets passed the contents of each event type as an argument.

public interface PojoListener {
    void handleEvent(CqEvent event);
    void handleEvent(Operation baseOp);
    void handleEvent(Object key);
    void handleEvent(Object key, Object newValue);
    void handleEvent(Throwable cause);
    void handleEvent(CqEvent event, Operation baseOp, byte[] deltaValue);
    void handleEvent(CqEvent event, Operation baseOp, Operation queryOp, Object key, Object newValue);
 }
Since:
1.1.0
Author:
Juergen Hoeller, Costin Leau, Oliver Gierke, John Blum
See Also:
  • Field Details

    • DEFAULT_LISTENER_METHOD_NAME

      public static final String DEFAULT_LISTENER_METHOD_NAME
      See Also:
    • logger

      protected final org.slf4j.Logger logger
  • Constructor Details

  • Method Details

    • setDelegate

      public final void setDelegate(Object delegate)
      Sets the target object to which CQ events are delegated. Specified listener methods have to be present on this target object. If no explicit delegate object has been configured then listener methods are expected to present on this adapter instance. In other words, on a custom subclass of this adapter, defining listener methods.
      Parameters:
      delegate - Object to delegate listening for CQ events.
      Throws:
      IllegalArgumentException - if delegate is null.
    • getDelegate

      public Object getDelegate()
      Returns a reference to the target object used to listen for and handle CQ events.
      Returns:
      a reference to the target object used to listen for and handle CQ events.
    • setDefaultListenerMethod

      public void setDefaultListenerMethod(String defaultListenerMethod)
      Specify the name of the default listener method to delegate to in the case where no specific listener method has been determined. Out-of-the-box value is "handleEvent.
      Parameters:
      defaultListenerMethod - the name of the default listener method to invoke.
      See Also:
    • getDefaultListenerMethod

      protected String getDefaultListenerMethod()
      Return the name of the default listener method to delegate to.
      Returns:
      the name of the default listener method to invoke on CQ events.
    • getListenerMethodName

      protected String getListenerMethodName(CqEvent event)
      Determine the name of the listener method that is supposed to handle the given event.

      The default implementation simply returns the configured default listener method, if any.

      Parameters:
      event - the GemFire event
      Returns:
      the name of the listener method (never null)
      See Also:
    • onEvent

      public void onEvent(CqEvent event)
      Standard ContinuousQueryListener callback method for handling CQ events.

      Delegates the CQ event to the target listener method, with appropriate conversion of the event arguments. In case of an exception, the handleListenerException(Throwable) method will be invoked.

      Specified by:
      onEvent in interface ContinuousQueryListener
      Parameters:
      event - incoming CQ event.
      See Also:
    • handleListenerException

      protected void handleListenerException(Throwable cause)
      Handle the given exception that arose during listener execution. The default implementation logs the exception at error level.
      Parameters:
      cause - the exception to handle
    • invokeListenerMethod

      protected void invokeListenerMethod(CqEvent event, String methodName)
      Invoke the specified listener method.
      Parameters:
      event - the event arguments to be passed in
      methodName - the method to invoke
      See Also: