public abstract class AbstractApplicationEventMulticaster extends Object implements ApplicationEventMulticaster, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware
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.
getApplicationListeners(ApplicationEvent)
,
SimpleApplicationEventMulticaster
Constructor and Description |
---|
AbstractApplicationEventMulticaster() |
Modifier and Type | Method and Description |
---|---|
void |
addApplicationListener(ApplicationListener listener)
Add a listener to be notified of all events.
|
void |
addApplicationListenerBean(String listenerBeanName)
Add a listener bean to be notified of all events.
|
protected Collection<ApplicationListener> |
getApplicationListeners()
Return a Collection containing all ApplicationListeners.
|
protected Collection<ApplicationListener> |
getApplicationListeners(ApplicationEvent event)
Return a Collection of ApplicationListeners matching the given
event type.
|
void |
removeAllListeners()
Remove all listeners registered with this multicaster.
|
void |
removeApplicationListener(ApplicationListener listener)
Remove a listener from the notification list.
|
void |
removeApplicationListenerBean(String listenerBeanName)
Remove a listener bean from the notification list.
|
void |
setBeanClassLoader(ClassLoader classLoader) |
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
protected boolean |
supportsEvent(ApplicationListener listener,
Class<? extends ApplicationEvent> eventType,
Class<?> sourceType)
Determine whether the given listener supports the given event.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
multicastEvent
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface org.springframework.beans.factory.BeanClassLoaderAware
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
setBeanFactory
in interface org.springframework.beans.factory.BeanFactoryAware
public void addApplicationListener(ApplicationListener listener)
ApplicationEventMulticaster
addApplicationListener
in interface ApplicationEventMulticaster
listener
- the listener to addpublic void addApplicationListenerBean(String listenerBeanName)
ApplicationEventMulticaster
addApplicationListenerBean
in interface ApplicationEventMulticaster
listenerBeanName
- the name of the listener bean to addpublic void removeApplicationListener(ApplicationListener listener)
ApplicationEventMulticaster
removeApplicationListener
in interface ApplicationEventMulticaster
listener
- the listener to removepublic void removeApplicationListenerBean(String listenerBeanName)
ApplicationEventMulticaster
removeApplicationListenerBean
in interface ApplicationEventMulticaster
listenerBeanName
- the name of the listener bean to addpublic void removeAllListeners()
ApplicationEventMulticaster
After a remove call, the multicaster will perform no action on event notification until new listeners are being registered.
removeAllListeners
in interface ApplicationEventMulticaster
protected Collection<ApplicationListener> getApplicationListeners()
ApplicationListener
protected Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event)
event
- the event to be propagated. Allows for excluding
non-matching listeners early, based on cached matching information.ApplicationListener
protected boolean supportsEvent(ApplicationListener listener, Class<? extends ApplicationEvent> eventType, Class<?> sourceType)
The default implementation detects the SmartApplicationListener
interface. In case of a standard ApplicationListener
, a
GenericApplicationListenerAdapter
will be used to introspect
the generically declared type of the target listener.
listener
- the target listener to checkeventType
- the event type to check againstsourceType
- the source type to check against