public class SafeApplicationEventMulticaster extends Object implements org.springframework.context.event.ApplicationEventMulticaster, org.springframework.context.ApplicationContextAware
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.
getApplicationListeners(ApplicationEvent),
SimpleApplicationEventMulticaster| Constructor and Description |
|---|
SafeApplicationEventMulticaster() |
| Modifier and Type | Method and Description |
|---|---|
void |
addApplicationListener(org.springframework.context.ApplicationListener listener) |
void |
addApplicationListenerBean(String listenerBeanName) |
protected Collection<org.springframework.context.ApplicationListener> |
getApplicationListeners()
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 Executor |
getTaskExecutor()
Return the current TaskExecutor for this multicaster.
|
void |
multicastEvent(org.springframework.context.ApplicationEvent event) |
void |
multicastEvent(org.springframework.context.ApplicationEvent event,
org.springframework.core.ResolvableType eventType) |
protected void |
multicastEventInternal(org.springframework.context.ApplicationEvent event) |
void |
removeAllListeners() |
void |
removeApplicationListener(org.springframework.context.ApplicationListener listener) |
void |
removeApplicationListenerBean(String listenerBeanName) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setTaskExecutor(Executor taskExecutor)
Set the TaskExecutor to execute application listeners with.
|
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.
|
public void setTaskExecutor(Executor taskExecutor)
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.
protected Executor getTaskExecutor()
public void addApplicationListener(org.springframework.context.ApplicationListener listener)
addApplicationListener in interface org.springframework.context.event.ApplicationEventMulticasterpublic void addApplicationListenerBean(String listenerBeanName)
addApplicationListenerBean in interface org.springframework.context.event.ApplicationEventMulticasterpublic void removeApplicationListener(org.springframework.context.ApplicationListener listener)
removeApplicationListener in interface org.springframework.context.event.ApplicationEventMulticasterpublic void removeApplicationListenerBean(String listenerBeanName)
removeApplicationListenerBean in interface org.springframework.context.event.ApplicationEventMulticasterpublic void removeAllListeners()
removeAllListeners in interface org.springframework.context.event.ApplicationEventMulticasterpublic void multicastEvent(org.springframework.context.ApplicationEvent event)
multicastEvent in interface org.springframework.context.event.ApplicationEventMulticasterpublic void multicastEvent(org.springframework.context.ApplicationEvent event,
org.springframework.core.ResolvableType eventType)
multicastEvent in interface org.springframework.context.event.ApplicationEventMulticasterprotected void multicastEventInternal(org.springframework.context.ApplicationEvent event)
protected Collection<org.springframework.context.ApplicationListener> getApplicationListeners()
ApplicationListenerprotected Collection<org.springframework.context.ApplicationListener> getApplicationListeners(org.springframework.context.ApplicationEvent event)
event - the event to be propagated. Allows for excluding non-matching
listeners early, based on cached matching information.ApplicationListenerprotected boolean supportsEvent(org.springframework.context.ApplicationListener listener,
Class<? extends org.springframework.context.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 againstpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionCopyright © 2005–2018 Alfresco Software. All rights reserved.