public class SourceFilteringListener extends Object implements SmartApplicationListener
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 |
---|---|
int |
getOrder()
Return the order value of this object, with a
higher value meaning greater in terms of sorting.
|
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(Class<? extends ApplicationEvent> 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.
|
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(Class<? extends ApplicationEvent> eventType)
SmartApplicationListener
supportsEventType
in interface SmartApplicationListener
public boolean supportsSourceType(Class<?> sourceType)
SmartApplicationListener
supportsSourceType
in interface SmartApplicationListener
public int getOrder()
Ordered
Normally starting with 0, with Integer.MAX_VALUE
indicating the greatest value. Same order values will result
in arbitrary positions for the affected objects.
Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).
protected void onApplicationEventInternal(ApplicationEvent event)
The default implementation invokes the specified delegate, if any.
event
- the event to process (matching the specified source)