Class SafeApplicationEventMulticaster
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.event.ApplicationEventMulticaster
ApplicationEventMulticaster interface, providing the basic listener registration facility.
Doesn't permit multiple instances of the same listener by default, as it keeps listeners in a linked Set. The collection class used to hold ApplicationListener objects can be overridden through the "collectionClass" bean property.
Implementing ApplicationEventMulticaster's actual multicastEvent(org.springframework.context.ApplicationEvent) method is left to subclasses. SimpleApplicationEventMulticaster simply multicasts all events to all registered listeners, invoking them in the calling thread. Alternative implementations could be more sophisticated in those respects.
- Since:
- 1.2.3
- Author:
- Juergen Hoeller
- See Also:
-
getApplicationListeners(ApplicationEvent)SimpleApplicationEventMulticaster
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddApplicationListener(org.springframework.context.ApplicationListener listener) voidaddApplicationListenerBean(String listenerBeanName) protected Collection<org.springframework.context.ApplicationListener>Return a Collection containing all ApplicationListeners.protected Collection<org.springframework.context.ApplicationListener>getApplicationListeners(org.springframework.context.ApplicationEvent event) Return a Collection of ApplicationListeners matching the given event type.protected ExecutorReturn the current TaskExecutor for this multicaster.voidmulticastEvent(org.springframework.context.ApplicationEvent event) voidmulticastEvent(org.springframework.context.ApplicationEvent event, org.springframework.core.ResolvableType eventType) protected voidmulticastEventInternal(org.springframework.context.ApplicationEvent event) voidvoidremoveApplicationListener(org.springframework.context.ApplicationListener listener) voidremoveApplicationListenerBean(String listenerBeanName) voidremoveApplicationListenerBeans(Predicate<String> predicate) voidremoveApplicationListeners(Predicate<org.springframework.context.ApplicationListener<?>> predicate) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetTaskExecutor(Executor taskExecutor) Set the TaskExecutor to execute application listeners with.protected booleansupportsEvent(org.springframework.context.ApplicationListener listener, Class<? extends org.springframework.context.ApplicationEvent> eventType, Class sourceType) Determine whether the given listener supports the given event.
-
Constructor Details
-
SafeApplicationEventMulticaster
public SafeApplicationEventMulticaster()
-
-
Method Details
-
setTaskExecutor
Set the TaskExecutor to execute application listeners with.Default is a SyncTaskExecutor, executing the listeners synchronously in the calling thread.
Consider specifying an asynchronous TaskExecutor here to not block the caller until all listeners have been executed. However, note that asynchronous execution will not participate in the caller's thread context (class loader, transaction association) unless the TaskExecutor explicitly supports this.
-
getTaskExecutor
Return the current TaskExecutor for this multicaster. -
addApplicationListener
public void addApplicationListener(org.springframework.context.ApplicationListener listener) - Specified by:
addApplicationListenerin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
addApplicationListenerBean
- Specified by:
addApplicationListenerBeanin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
removeApplicationListener
public void removeApplicationListener(org.springframework.context.ApplicationListener listener) - Specified by:
removeApplicationListenerin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
removeApplicationListenerBean
- Specified by:
removeApplicationListenerBeanin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
removeApplicationListeners
public void removeApplicationListeners(Predicate<org.springframework.context.ApplicationListener<?>> predicate) - Specified by:
removeApplicationListenersin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
removeApplicationListenerBeans
- Specified by:
removeApplicationListenerBeansin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
removeAllListeners
public void removeAllListeners()- Specified by:
removeAllListenersin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
multicastEvent
public void multicastEvent(org.springframework.context.ApplicationEvent event) - Specified by:
multicastEventin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
multicastEvent
public void multicastEvent(org.springframework.context.ApplicationEvent event, org.springframework.core.ResolvableType eventType) - Specified by:
multicastEventin interfaceorg.springframework.context.event.ApplicationEventMulticaster
-
multicastEventInternal
protected void multicastEventInternal(org.springframework.context.ApplicationEvent event) -
getApplicationListeners
Return a Collection containing all ApplicationListeners.- Returns:
- a Collection of ApplicationListeners
- See Also:
-
ApplicationListener
-
getApplicationListeners
protected Collection<org.springframework.context.ApplicationListener> getApplicationListeners(org.springframework.context.ApplicationEvent event) Return a Collection of ApplicationListeners matching the given event type. Non-matching listeners get excluded early.- Parameters:
event- the event to be propagated. Allows for excluding non-matching listeners early, based on cached matching information.- Returns:
- a Collection of ApplicationListeners
- See Also:
-
ApplicationListener
-
supportsEvent
protected boolean supportsEvent(org.springframework.context.ApplicationListener listener, Class<? extends org.springframework.context.ApplicationEvent> eventType, Class sourceType) Determine whether the given listener supports the given event.The default implementation detects the
SmartApplicationListenerinterface. In case of a standardApplicationListener, aGenericApplicationListenerAdapterwill be used to introspect the generically declared type of the target listener.- Parameters:
listener- the target listener to checkeventType- the event type to check againstsourceType- the source type to check against- Returns:
- whether the given listener should be included in the candidates for the given event type
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-