public class ApplicationListenerMethodAdapter extends Object implements GenericApplicationListener
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.
Modifier and Type | Field and Description |
---|---|
protected Log |
logger |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ApplicationListenerMethodAdapter(String beanName,
Class<?> targetClass,
Method method)
Construct a new ApplicationListenerMethodAdapter.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
doInvoke(Object... args)
Invoke the event listener method with the given argument values.
|
protected String |
getCondition()
Return the condition to use.
|
protected String |
getDefaultListenerId()
Determine the default id for the target listener, to be applied in case of
no
annotation-specified id value . |
protected String |
getDetailedErrorMessage(Object bean,
String message)
Add additional details such as the bean type and method signature to
the given error message.
|
String |
getListenerId()
Return an optional identifier for the listener.
|
int |
getOrder()
Determine this listener's order in a set of listeners for the same event.
|
protected Object |
getTargetBean()
Return the target bean instance to use.
|
protected Method |
getTargetMethod()
Return the target listener method.
|
protected void |
handleAsyncError(Throwable t) |
protected void |
handleResult(Object result) |
void |
onApplicationEvent(ApplicationEvent event)
Handle an application event.
|
void |
processEvent(ApplicationEvent event)
Process the specified
ApplicationEvent , checking if the condition
matches and handling a non-null result, if any. |
protected Object[] |
resolveArguments(ApplicationEvent event)
Resolve the method arguments to use for the specified
ApplicationEvent . |
boolean |
supportsEventType(ResolvableType eventType)
Determine whether this listener actually supports the given event type.
|
boolean |
supportsSourceType(Class<?> sourceType)
Determine whether this listener actually supports the given source type.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
supportsEventType
forPayload
protected final Log logger
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
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 invokepublic void onApplicationEvent(ApplicationEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ApplicationEvent>
event
- the event to respond topublic boolean supportsEventType(ResolvableType eventType)
GenericApplicationListener
supportsEventType
in interface GenericApplicationListener
eventType
- the event type (never null
)public boolean supportsSourceType(@Nullable Class<?> sourceType)
SmartApplicationListener
The default implementation always returns true
.
supportsSourceType
in interface SmartApplicationListener
sourceType
- the source type, or null
if no sourcepublic int getOrder()
SmartApplicationListener
The default implementation returns Ordered.LOWEST_PRECEDENCE
.
getOrder
in interface SmartApplicationListener
getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
public String getListenerId()
SmartApplicationListener
The default value is an empty String.
protected String getDefaultListenerId()
annotation-specified id value
.
The default implementation builds a method name with parameter types.
getListenerId()
public void processEvent(ApplicationEvent event)
ApplicationEvent
, checking if the condition
matches and handling a non-null result, if any.@Nullable protected Object[] resolveArguments(ApplicationEvent event)
ApplicationEvent
.
These arguments will be used to invoke the method handled by this instance.
Can return null
to indicate that no suitable arguments could be resolved
and therefore the method should not be invoked at all for the specified event.
protected void handleResult(Object result)
protected void handleAsyncError(Throwable t)
@Nullable protected Object doInvoke(Object... args)
protected Object getTargetBean()
protected Method getTargetMethod()
@Nullable protected String getCondition()
Matches the condition
attribute of the EventListener
annotation or any matching attribute on a composed annotation that
is meta-annotated with @EventListener
.
protected String getDetailedErrorMessage(Object bean, String message)
message
- error message to append the HandlerMethod details to