public abstract class AbstractApplicationEventMulticaster extends Object implements ApplicationEventMulticaster, BeanClassLoaderAware, 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, ResolvableType)
,
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,
ResolvableType eventType)
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 |
removeApplicationListenerBeans(Predicate<String> predicate)
Remove all matching listener beans from the set of registered
listener bean names (referring to bean classes which in turn
implement the
ApplicationListener interface directly). |
void |
removeApplicationListeners(Predicate<ApplicationListener<?>> predicate)
Remove all matching listeners from the set of registered
ApplicationListener instances (which includes adapter classes
such as ApplicationListenerMethodAdapter , e.g. |
void |
setBeanClassLoader(ClassLoader classLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
|
protected boolean |
supportsEvent(ApplicationListener<?> listener,
ResolvableType eventType,
Class<?> sourceType)
Determine whether the given listener supports the given event.
|
protected boolean |
supportsEvent(Class<?> listenerType,
ResolvableType eventType)
Filter a listener early through checking its generically declared event
type before trying to instantiate it.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
multicastEvent, multicastEvent
public void setBeanClassLoader(ClassLoader classLoader)
BeanClassLoaderAware
class loader
to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- the owning class loaderpublic void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public void addApplicationListener(ApplicationListener<?> listener)
ApplicationEventMulticaster
addApplicationListener
in interface ApplicationEventMulticaster
listener
- the listener to addApplicationEventMulticaster.removeApplicationListener(ApplicationListener)
,
ApplicationEventMulticaster.removeApplicationListeners(Predicate)
public void addApplicationListenerBean(String listenerBeanName)
ApplicationEventMulticaster
addApplicationListenerBean
in interface ApplicationEventMulticaster
listenerBeanName
- the name of the listener bean to addApplicationEventMulticaster.removeApplicationListenerBean(String)
,
ApplicationEventMulticaster.removeApplicationListenerBeans(Predicate)
public void removeApplicationListener(ApplicationListener<?> listener)
ApplicationEventMulticaster
removeApplicationListener
in interface ApplicationEventMulticaster
listener
- the listener to removeApplicationEventMulticaster.addApplicationListener(ApplicationListener)
,
ApplicationEventMulticaster.removeApplicationListeners(Predicate)
public void removeApplicationListenerBean(String listenerBeanName)
ApplicationEventMulticaster
removeApplicationListenerBean
in interface ApplicationEventMulticaster
listenerBeanName
- the name of the listener bean to removeApplicationEventMulticaster.addApplicationListenerBean(String)
,
ApplicationEventMulticaster.removeApplicationListenerBeans(Predicate)
public void removeApplicationListeners(Predicate<ApplicationListener<?>> predicate)
ApplicationEventMulticaster
ApplicationListener
instances (which includes adapter classes
such as ApplicationListenerMethodAdapter
, e.g. for annotated
EventListener
methods).
Note: This just applies to instance registrations, not to listeners registered by bean name.
removeApplicationListeners
in interface ApplicationEventMulticaster
predicate
- the predicate to identify listener instances to remove,
e.g. checking SmartApplicationListener.getListenerId()
ApplicationEventMulticaster.addApplicationListener(ApplicationListener)
,
ApplicationEventMulticaster.removeApplicationListener(ApplicationListener)
public void removeApplicationListenerBeans(Predicate<String> predicate)
ApplicationEventMulticaster
ApplicationListener
interface directly).
Note: This just applies to bean name registrations, not to
programmatically registered ApplicationListener
instances.
removeApplicationListenerBeans
in interface ApplicationEventMulticaster
predicate
- the predicate to identify listener bean names to removeApplicationEventMulticaster.addApplicationListenerBean(String)
,
ApplicationEventMulticaster.removeApplicationListenerBean(String)
public void removeAllListeners()
ApplicationEventMulticaster
After a remove call, the multicaster will perform no action on event notification until new listeners are registered.
removeAllListeners
in interface ApplicationEventMulticaster
ApplicationEventMulticaster.removeApplicationListeners(Predicate)
protected Collection<ApplicationListener<?>> getApplicationListeners()
ApplicationListener
protected Collection<ApplicationListener<?>> getApplicationListeners(ApplicationEvent event, ResolvableType eventType)
event
- the event to be propagated. Allows for excluding
non-matching listeners early, based on cached matching information.eventType
- the event typeApplicationListener
protected boolean supportsEvent(Class<?> listenerType, ResolvableType eventType)
If this method returns true
for a given listener as a first pass,
the listener instance will get retrieved and fully evaluated through a
supportsEvent(ApplicationListener, ResolvableType, Class)
call afterwards.
listenerType
- the listener's type as determined by the BeanFactoryeventType
- the event type to checkprotected boolean supportsEvent(ApplicationListener<?> listener, ResolvableType eventType, @Nullable Class<?> sourceType)
The default implementation detects the SmartApplicationListener
and GenericApplicationListener
interfaces. 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