Class ContinuousQueryListenerAdapter
- All Implemented Interfaces:
ContinuousQueryListener
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
- See Also:
-
Method
Operation
CqEvent
CqQuery
ContinuousQueryListener
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a new instance ofContinuousQueryListenerAdapter
with default settings.ContinuousQueryListenerAdapter
(Object delegate) Constructs a new instance ofContinuousQueryListenerAdapter
initialized with the givendelegate
. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
Return the name of the default listener method to delegate to.Returns a reference to the target object used to listen for and handle CQ events.protected String
getListenerMethodName
(org.apache.geode.cache.query.CqEvent event) Determine the name of the listener method that is supposed to handle the given event.protected void
handleListenerException
(Throwable cause) Handle the given exception that arose during listener execution.protected void
invokeListenerMethod
(org.apache.geode.cache.query.CqEvent event, String methodName) Invoke the specified listener method.void
onEvent
(org.apache.geode.cache.query.CqEvent event) StandardContinuousQueryListener
callback method for handling CQ events.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.final void
setDelegate
(Object delegate) Sets the target object to which CQ events are delegated.
-
Field Details
-
DEFAULT_LISTENER_METHOD_NAME
- See Also:
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
ContinuousQueryListenerAdapter
public ContinuousQueryListenerAdapter()Constructs a new instance ofContinuousQueryListenerAdapter
with default settings. -
ContinuousQueryListenerAdapter
Constructs a new instance ofContinuousQueryListenerAdapter
initialized with the givendelegate
.- Parameters:
delegate
-delegate
of the listener method event callback.- See Also:
-
-
Method Details
-
setDelegate
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
- ifdelegate
is null.
-
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
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
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
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(org.apache.geode.cache.query.CqEvent event) StandardContinuousQueryListener
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 interfaceContinuousQueryListener
- Parameters:
event
- incomingCQ event
.- See Also:
-
handleListenerException
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
Invoke the specified listener method.- Parameters:
event
- the event arguments to be passed inmethodName
- the method to invoke- See Also:
-