Class AbstractApplicationEventMulticaster
- All Implemented Interfaces:
- Aware,- BeanClassLoaderAware,- BeanFactoryAware,- ApplicationEventMulticaster
- Direct Known Subclasses:
- SimpleApplicationEventMulticaster
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 ApplicationEventMulticaster.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, Stephane Nicoll
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddApplicationListener(ApplicationListener<?> listener) Add a listener to be notified of all events.voidaddApplicationListenerBean(String listenerBeanName) Add a listener bean to be notified of all events.protected Collection<ApplicationListener<?>>Return a Collection containing all ApplicationListeners.protected Collection<ApplicationListener<?>>getApplicationListeners(ApplicationEvent event, ResolvableType eventType) Return a Collection of ApplicationListeners matching the given event type.voidRemove all listeners registered with this multicaster.voidremoveApplicationListener(ApplicationListener<?> listener) Remove a listener from the notification list.voidremoveApplicationListenerBean(String listenerBeanName) Remove a listener bean from the notification list.voidremoveApplicationListenerBeans(Predicate<String> predicate) Remove all matching listener beans from the set of registered listener bean names (referring to bean classes which in turn implement theApplicationListenerinterface directly).voidremoveApplicationListeners(Predicate<ApplicationListener<?>> predicate) Remove all matching listeners from the set of registeredApplicationListenerinstances (which includes adapter classes such asApplicationListenerMethodAdapter, e.g.voidsetBeanClassLoader(ClassLoader classLoader) Callback that supplies the beanclass loaderto a bean instance.voidsetBeanFactory(BeanFactory beanFactory) Callback that supplies the owning factory to a bean instance.protected booleansupportsEvent(Class<?> listenerType, ResolvableType eventType) Filter a listener early through checking its generically declared event type before trying to instantiate it.protected booleansupportsEvent(ApplicationListener<?> listener, ResolvableType eventType, Class<?> sourceType) Determine whether the given listener supports the given event.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.event.ApplicationEventMulticastermulticastEvent, multicastEvent
- 
Constructor Details- 
AbstractApplicationEventMulticasterpublic AbstractApplicationEventMulticaster()
 
- 
- 
Method Details- 
setBeanClassLoaderDescription copied from interface:BeanClassLoaderAwareCallback that supplies the beanclass loaderto a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean'sInitializingBean.afterPropertiesSet()method or a custom init-method.- Specified by:
- setBeanClassLoaderin interface- BeanClassLoaderAware
- Parameters:
- classLoader- the owning class loader
 
- 
setBeanFactoryDescription copied from interface:BeanFactoryAwareCallback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- See Also:
 
- 
addApplicationListenerDescription copied from interface:ApplicationEventMulticasterAdd a listener to be notified of all events.- Specified by:
- addApplicationListenerin interface- ApplicationEventMulticaster
- Parameters:
- listener- the listener to add
- See Also:
 
- 
addApplicationListenerBeanDescription copied from interface:ApplicationEventMulticasterAdd a listener bean to be notified of all events.- Specified by:
- addApplicationListenerBeanin interface- ApplicationEventMulticaster
- Parameters:
- listenerBeanName- the name of the listener bean to add
- See Also:
 
- 
removeApplicationListenerDescription copied from interface:ApplicationEventMulticasterRemove a listener from the notification list.- Specified by:
- removeApplicationListenerin interface- ApplicationEventMulticaster
- Parameters:
- listener- the listener to remove
- See Also:
 
- 
removeApplicationListenerBeanDescription copied from interface:ApplicationEventMulticasterRemove a listener bean from the notification list.- Specified by:
- removeApplicationListenerBeanin interface- ApplicationEventMulticaster
- Parameters:
- listenerBeanName- the name of the listener bean to remove
- See Also:
 
- 
removeApplicationListenersDescription copied from interface:ApplicationEventMulticasterRemove all matching listeners from the set of registeredApplicationListenerinstances (which includes adapter classes such asApplicationListenerMethodAdapter, e.g. for annotatedEventListenermethods).Note: This just applies to instance registrations, not to listeners registered by bean name. - Specified by:
- removeApplicationListenersin interface- ApplicationEventMulticaster
- Parameters:
- predicate- the predicate to identify listener instances to remove, e.g. checking- SmartApplicationListener.getListenerId()
- See Also:
 
- 
removeApplicationListenerBeansDescription copied from interface:ApplicationEventMulticasterRemove all matching listener beans from the set of registered listener bean names (referring to bean classes which in turn implement theApplicationListenerinterface directly).Note: This just applies to bean name registrations, not to programmatically registered ApplicationListenerinstances.- Specified by:
- removeApplicationListenerBeansin interface- ApplicationEventMulticaster
- Parameters:
- predicate- the predicate to identify listener bean names to remove
- See Also:
 
- 
removeAllListenerspublic void removeAllListeners()Description copied from interface:ApplicationEventMulticasterRemove all listeners registered with this multicaster.After a remove call, the multicaster will perform no action on event notification until new listeners are registered. - Specified by:
- removeAllListenersin interface- ApplicationEventMulticaster
- See Also:
 
- 
getApplicationListenersReturn a Collection containing all ApplicationListeners.- Returns:
- a Collection of ApplicationListeners
- See Also:
 
- 
getApplicationListenersprotected Collection<ApplicationListener<?>> getApplicationListeners(ApplicationEvent event, ResolvableType eventType) 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.
- eventType- the event type
- Returns:
- a Collection of ApplicationListeners
- See Also:
 
- 
supportsEventFilter a listener early through checking its generically declared event type before trying to instantiate it.If this method returns truefor a given listener as a first pass, the listener instance will get retrieved and fully evaluated through asupportsEvent(ApplicationListener, ResolvableType, Class)call afterwards.- Parameters:
- listenerType- the listener's type as determined by the BeanFactory
- eventType- the event type to check
- Returns:
- whether the given listener should be included in the candidates for the given event type
 
- 
supportsEventprotected boolean supportsEvent(ApplicationListener<?> listener, ResolvableType eventType, @Nullable Class<?> sourceType) Determine whether the given listener supports the given event.The default implementation detects the SmartApplicationListenerandGenericApplicationListenerinterfaces. In case of a standardApplicationListener, aGenericApplicationListenerAdapterwill be used to introspect the generically declared type of the target listener.- Parameters:
- listener- the target listener to check
- eventType- the event type to check against
- sourceType- the source type to check against
- Returns:
- whether the given listener should be included in the candidates for the given event type
 
 
-