Class SourceFilteringListener
java.lang.Object
org.springframework.context.event.SourceFilteringListener
- All Implemented Interfaces:
EventListener,ApplicationListener<ApplicationEvent>,GenericApplicationListener,SmartApplicationListener,org.springframework.core.Ordered
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.
- 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
ConstructorsModifierConstructorDescriptionprotectedSourceFilteringListener(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
Modifier and TypeMethodDescriptionReturn an optional identifier for the listener.intgetOrder()Determine this listener's order in a set of listeners for the same event.voidHandle an application event.protected voidActually process the event, after having filtered according to the desired event source already.booleansupportsEventType(org.springframework.core.ResolvableType eventType) Determine whether this listener actually supports the given event type.booleansupportsSourceType(Class<?> sourceType) Determine whether this listener actually supports the given source type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.event.GenericApplicationListener
supportsEventType
-
Constructor Details
-
SourceFilteringListener
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
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 Details
-
onApplicationEvent
Description copied from interface:ApplicationListenerHandle an application event.- Specified by:
onApplicationEventin interfaceApplicationListener<ApplicationEvent>- Parameters:
event- the event to respond to
-
supportsEventType
public boolean supportsEventType(org.springframework.core.ResolvableType eventType) 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 interfaceorg.springframework.core.Ordered- Specified by:
getOrderin interfaceSmartApplicationListener
-
getListenerId
Description copied from interface:SmartApplicationListenerReturn an optional identifier for the listener.The default value is an empty String.
-
onApplicationEventInternal
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)
-