Class SafeApplicationEventMulticaster
- java.lang.Object
-
- org.alfresco.repo.management.SafeApplicationEventMulticaster
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.event.ApplicationEventMulticaster
public class SafeApplicationEventMulticaster extends java.lang.Object implements org.springframework.context.event.ApplicationEventMulticaster, org.springframework.context.ApplicationContextAwareAbstract implementation of theApplicationEventMulticasterinterface, 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.SimpleApplicationEventMulticastersimply 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 Constructor Description SafeApplicationEventMulticaster()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddApplicationListener(org.springframework.context.ApplicationListener listener)voidaddApplicationListenerBean(java.lang.String listenerBeanName)protected java.util.Collection<org.springframework.context.ApplicationListener>getApplicationListeners()Return a Collection containing all ApplicationListeners.protected java.util.Collection<org.springframework.context.ApplicationListener>getApplicationListeners(org.springframework.context.ApplicationEvent event)Return a Collection of ApplicationListeners matching the given event type.protected java.util.concurrent.ExecutorgetTaskExecutor()Return 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)voidremoveAllListeners()voidremoveApplicationListener(org.springframework.context.ApplicationListener listener)voidremoveApplicationListenerBean(java.lang.String listenerBeanName)voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetTaskExecutor(java.util.concurrent.Executor taskExecutor)Set the TaskExecutor to execute application listeners with.protected booleansupportsEvent(org.springframework.context.ApplicationListener listener, java.lang.Class<? extends org.springframework.context.ApplicationEvent> eventType, java.lang.Class sourceType)Determine whether the given listener supports the given event.
-
-
-
Method Detail
-
setTaskExecutor
public void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
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
protected java.util.concurrent.Executor 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
public void addApplicationListenerBean(java.lang.String listenerBeanName)
- 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
public void removeApplicationListenerBean(java.lang.String listenerBeanName)
- Specified by:
removeApplicationListenerBeanin 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
protected java.util.Collection<org.springframework.context.ApplicationListener> getApplicationListeners()
Return a Collection containing all ApplicationListeners.- Returns:
- a Collection of ApplicationListeners
- See Also:
ApplicationListener
-
getApplicationListeners
protected java.util.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, java.lang.Class<? extends org.springframework.context.ApplicationEvent> eventType, java.lang.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
-
-