Class SourceFilteringListener
- java.lang.Object
- org.springframework.context.event.SourceFilteringListener
- All Implemented Interfaces:
EventListener
,ApplicationListener<ApplicationEvent>
,GenericApplicationListener
,SmartApplicationListener
,Ordered
public class SourceFilteringListener extends Object implements GenericApplicationListener, SmartApplicationListener
ApplicationListener
decorator that filters events from a specified event source, invoking its delegate listener for matchingApplicationEvent
objects only.Can also be used as base class, overriding the
onApplicationEventInternal(org.springframework.context.ApplicationEvent)
method instead of specifying a delegate listener.- Since:
- 2.0.5
- Author:
- Juergen Hoeller, Stephane Nicoll
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Modifier Constructor Description protected
SourceFilteringListener(Object source)
Create a SourceFilteringListener for the given event source, expecting subclasses to override theonApplicationEventInternal(org.springframework.context.ApplicationEvent)
method (instead of specifying a delegate listener).SourceFilteringListener(Object source, ApplicationListener<?> delegate)
Create a SourceFilteringListener for the given event source.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(Class<? extends ApplicationEvent> eventType)
Determine whether this listener actually supports the given event type.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.
Constructor Detail
SourceFilteringListener
public SourceFilteringListener(Object source, ApplicationListener<?> delegate)
Create a SourceFilteringListener for the given event source.- Parameters:
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 source
SourceFilteringListener
protected SourceFilteringListener(Object source)
Create a SourceFilteringListener for the given event source, expecting subclasses to override theonApplicationEventInternal(org.springframework.context.ApplicationEvent)
method (instead of specifying a delegate listener).- Parameters:
source
- the event source that this listener filters for, only processing events from this source
Method Detail
onApplicationEvent
public void onApplicationEvent(ApplicationEvent event)
Description copied from interface:ApplicationListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationListener<ApplicationEvent>
- Parameters:
event
- the event to respond to
supportsEventType
public boolean supportsEventType(ResolvableType eventType)
Description copied from interface:GenericApplicationListener
Determine whether this listener actually supports the given event type.- Specified by:
supportsEventType
in interfaceGenericApplicationListener
- Parameters:
eventType
- the event type (nevernull
)
supportsEventType
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType)
Description copied from interface:SmartApplicationListener
Determine whether this listener actually supports the given event type.- Specified by:
supportsEventType
in interfaceSmartApplicationListener
- Parameters:
eventType
- the event type (nevernull
)
supportsSourceType
public boolean supportsSourceType(@Nullable Class<?> sourceType)
Description copied from interface:GenericApplicationListener
Determine whether this listener actually supports the given source type.The default implementation always returns
true
.- Specified by:
supportsSourceType
in interfaceGenericApplicationListener
- Specified by:
supportsSourceType
in interfaceSmartApplicationListener
- Parameters:
sourceType
- the source type, ornull
if no source
getOrder
public int getOrder()
Description copied from interface:GenericApplicationListener
Determine this listener's order in a set of listeners for the same event.The default implementation returns
Ordered.LOWEST_PRECEDENCE
.- Specified by:
getOrder
in interfaceGenericApplicationListener
- Specified by:
getOrder
in interfaceOrdered
- Specified by:
getOrder
in interfaceSmartApplicationListener
- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
onApplicationEventInternal
protected void onApplicationEventInternal(ApplicationEvent event)
Actually process the event, after having filtered according to the desired event source already.The default implementation invokes the specified delegate, if any.
- Parameters:
event
- the event to process (matching the specified source)