public class SourceFilteringListener extends Object implements GenericApplicationListener
ApplicationListener
decorator that filters
events from a specified event source, invoking its delegate listener for
matching ApplicationEvent
objects only.
Can also be used as base class, overriding the onApplicationEventInternal(org.springframework.context.ApplicationEvent)
method instead of specifying a delegate listener.
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Modifier | Constructor and Description |
---|---|
protected |
SourceFilteringListener(Object source)
Create a SourceFilteringListener for the given event source,
expecting subclasses to override the
onApplicationEventInternal(org.springframework.context.ApplicationEvent)
method (instead of specifying a delegate listener). |
|
SourceFilteringListener(Object source,
ApplicationListener<?> delegate)
Create a SourceFilteringListener for the given event source.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
onApplicationEvent(ApplicationEvent event)
Handle an application event.
|
protected void |
onApplicationEventInternal(ApplicationEvent event)
Actually process the event, after having filtered according to the
desired event source already.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
supportsEventType
forPayload
public SourceFilteringListener(Object source, ApplicationListener<?> delegate)
source
- the event source that this listener filters for,
only processing events from this sourcedelegate
- the delegate listener to invoke with event
from the specified sourceprotected SourceFilteringListener(Object source)
onApplicationEventInternal(org.springframework.context.ApplicationEvent)
method (instead of specifying a delegate listener).source
- the event source that this listener filters for,
only processing events from this sourcepublic 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 void onApplicationEventInternal(ApplicationEvent event)
The default implementation invokes the specified delegate, if any.
event
- the event to process (matching the specified source)