Class ApplicationListenerMethodAdapter
- All Implemented Interfaces:
EventListener, ApplicationListener<ApplicationEvent>, GenericApplicationListener, SmartApplicationListener, Ordered
- Direct Known Subclasses:
TransactionalApplicationListenerMethodAdapter
GenericApplicationListener adapter that delegates the processing of
an event to an EventListener annotated method.
Delegates to processEvent(ApplicationEvent) to give subclasses
a chance to deviate from the default. Unwraps the content of a
PayloadApplicationEvent if necessary to allow a method declaration
to define any arbitrary event type. If a condition is defined, it is
evaluated prior to invoking the underlying method.
- Since:
- 4.2
- Author:
- Stephane Nicoll, Juergen Hoeller, Sam Brannen, Sebastien Deleuze, Yanming Zhou
-
Field Summary
FieldsFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) Construct a new ApplicationListenerMethodAdapter. -
Method Summary
Modifier and TypeMethodDescriptionInvoke the event listener method with the given argument values.Return the condition to use.protected StringDetermine the default id for the target listener, to be applied in case of noannotation-specified id value.protected StringgetDetailedErrorMessage(Object bean, @Nullable String message) Add additional details such as the bean type and method signature to the given error message.Return an optional identifier for the listener.intgetOrder()Determine this listener's order in a set of listeners for the same event.protected ObjectReturn the target bean instance to use.protected MethodReturn the target listener method.protected voidprotected voidhandleResult(Object result) protected booleanReturn whether default execution is applicable for the target listener.voidHandle an application event.voidprocessEvent(ApplicationEvent event) Process the specifiedApplicationEvent, checking if the condition matches and handling a non-null result, if any.resolveArguments(ApplicationEvent event) Resolve the method arguments to use for the specifiedApplicationEvent.booleanshouldHandle(ApplicationEvent event) Determine whether the listener method would actually handle the given event, checking if the condition matches.booleansupportsEventType(ResolvableType eventType) Determine whether this listener actually supports the given event type.booleansupportsSourceType(@Nullable Class<?> sourceType) Determine whether this listener actually supports the given source type.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ApplicationListener
supportsAsyncExecutionMethods inherited from interface GenericApplicationListener
supportsEventType
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
ApplicationListenerMethodAdapter
Construct a new ApplicationListenerMethodAdapter.- Parameters:
beanName- the name of the bean to invoke the listener method ontargetClass- the target class that the method is declared onmethod- the listener method to invoke
-
-
Method Details
-
onApplicationEvent
Description copied from interface:ApplicationListenerHandle an application event.- Specified by:
onApplicationEventin interfaceApplicationListener<ApplicationEvent>- Parameters:
event- the event to respond to
-
supportsEventType
Description copied from interface:GenericApplicationListenerDetermine whether this listener actually supports the given event type.- Specified by:
supportsEventTypein interfaceGenericApplicationListener- Parameters:
eventType- the event type (nevernull)
-
supportsSourceType
Description copied from interface:SmartApplicationListenerDetermine whether this listener actually supports the given source type.The default implementation always returns
true.- Specified by:
supportsSourceTypein interfaceSmartApplicationListener- Parameters:
sourceType- the source type, ornullif no source
-
getOrder
public int getOrder()Description copied from interface:SmartApplicationListenerDetermine this listener's order in a set of listeners for the same event.The default implementation returns
Ordered.LOWEST_PRECEDENCE.- Specified by:
getOrderin interfaceOrdered- Specified by:
getOrderin interfaceSmartApplicationListener- Returns:
- the order value
- See Also:
-
getListenerId
Description copied from interface:SmartApplicationListenerReturn an optional identifier for the listener.The default value is an empty String.
- Specified by:
getListenerIdin interfaceSmartApplicationListener- See Also:
-
getDefaultListenerId
Determine the default id for the target listener, to be applied in case of noannotation-specified id value.The default implementation builds a method name with parameter types.
- Since:
- 5.3.5
- See Also:
-
isDefaultExecution
protected boolean isDefaultExecution()Return whether default execution is applicable for the target listener.- Since:
- 6.2
- See Also:
-
processEvent
Process the specifiedApplicationEvent, checking if the condition matches and handling a non-null result, if any.- Parameters:
event- the event to process through the listener method
-
shouldHandle
Determine whether the listener method would actually handle the given event, checking if the condition matches.- Parameters:
event- the event to process through the listener method- Since:
- 6.1
-
resolveArguments
Resolve the method arguments to use for the specifiedApplicationEvent.These arguments will be used to invoke the method handled by this instance. Can return
nullto indicate that no suitable arguments could be resolved and therefore the method should not be invoked at all for the specified event. -
handleResult
-
handleAsyncError
-
doInvoke
-
getTargetBean
Return the target bean instance to use. -
getTargetMethod
-
getCondition
Return the condition to use.Matches the
conditionattribute of theEventListenerannotation or any matching attribute on a composed annotation that is meta-annotated with@EventListener. -
getDetailedErrorMessage
-
toString
-