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 Object implements org.springframework.context.event.ApplicationEventMulticaster, org.springframework.context.ApplicationContextAware
Abstract implementation of the 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.

Since:
1.2.3
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • SafeApplicationEventMulticaster

      public SafeApplicationEventMulticaster()
  • Method Details

    • setTaskExecutor

      public void setTaskExecutor(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 Executor getTaskExecutor()
      Return the current TaskExecutor for this multicaster.
    • addApplicationListener

      public void addApplicationListener(org.springframework.context.ApplicationListener listener)
      Specified by:
      addApplicationListener in interface org.springframework.context.event.ApplicationEventMulticaster
    • addApplicationListenerBean

      public void addApplicationListenerBean(String listenerBeanName)
      Specified by:
      addApplicationListenerBean in interface org.springframework.context.event.ApplicationEventMulticaster
    • removeApplicationListener

      public void removeApplicationListener(org.springframework.context.ApplicationListener listener)
      Specified by:
      removeApplicationListener in interface org.springframework.context.event.ApplicationEventMulticaster
    • removeApplicationListenerBean

      public void removeApplicationListenerBean(String listenerBeanName)
      Specified by:
      removeApplicationListenerBean in interface org.springframework.context.event.ApplicationEventMulticaster
    • removeApplicationListeners

      public void removeApplicationListeners(Predicate<org.springframework.context.ApplicationListener<?>> predicate)
      Specified by:
      removeApplicationListeners in interface org.springframework.context.event.ApplicationEventMulticaster
    • removeApplicationListenerBeans

      public void removeApplicationListenerBeans(Predicate<String> predicate)
      Specified by:
      removeApplicationListenerBeans in interface org.springframework.context.event.ApplicationEventMulticaster
    • removeAllListeners

      public void removeAllListeners()
      Specified by:
      removeAllListeners in interface org.springframework.context.event.ApplicationEventMulticaster
    • multicastEvent

      public void multicastEvent(org.springframework.context.ApplicationEvent event)
      Specified by:
      multicastEvent in interface org.springframework.context.event.ApplicationEventMulticaster
    • multicastEvent

      public void multicastEvent(org.springframework.context.ApplicationEvent event, org.springframework.core.ResolvableType eventType)
      Specified by:
      multicastEvent in interface org.springframework.context.event.ApplicationEventMulticaster
    • multicastEventInternal

      protected void multicastEventInternal(org.springframework.context.ApplicationEvent event)
    • getApplicationListeners

      protected Collection<org.springframework.context.ApplicationListener> getApplicationListeners()
      Return a Collection containing all ApplicationListeners.
      Returns:
      a Collection of ApplicationListeners
      See Also:
      • ApplicationListener
    • getApplicationListeners

      protected 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, Class<? extends org.springframework.context.ApplicationEvent> eventType, Class sourceType)
      Determine whether the given listener supports the given event.

      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.

      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
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException