public abstract class

AbstractApplicationEventMulticaster

extends Object
implements BeanFactoryAware ApplicationEventMulticaster
java.lang.Object
   ↳ org.springframework.context.event.AbstractApplicationEventMulticaster
Known Direct Subclasses

Class Overview

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(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.

Summary

Public Constructors
AbstractApplicationEventMulticaster()
Public Methods
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.
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.
final void setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
Protected Methods
Collection<ApplicationListener> getApplicationListeners()
Return a Collection containing all ApplicationListeners.
Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event)
Return a Collection of ApplicationListeners matching the given event type.
boolean supportsEvent(ApplicationListener listener, Class<? extends ApplicationEvent> eventType, Class sourceType)
Determine whether the given listener supports the given event.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactoryAware
From interface org.springframework.context.event.ApplicationEventMulticaster

Public Constructors

public AbstractApplicationEventMulticaster ()

Public Methods

public void addApplicationListener (ApplicationListener listener)

Add a listener to be notified of all events.

Parameters
listener the listener to add

public void addApplicationListenerBean (String listenerBeanName)

Add a listener bean to be notified of all events.

Parameters
listenerBeanName the name of the listener bean to add

public void removeAllListeners ()

Remove all listeners registered with this multicaster.

After a remove call, the multicaster will perform no action on event notification until new listeners are being registered.

public void removeApplicationListener (ApplicationListener listener)

Remove a listener from the notification list.

Parameters
listener the listener to remove

public void removeApplicationListenerBean (String listenerBeanName)

Remove a listener bean from the notification list.

Parameters
listenerBeanName the name of the listener bean to add

public final void setBeanFactory (BeanFactory beanFactory)

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as afterPropertiesSet() or a custom init-method.

Parameters
beanFactory owning BeanFactory (never null). The bean can immediately call methods on the factory.

Protected Methods

protected Collection<ApplicationListener> getApplicationListeners ()

Return a Collection containing all ApplicationListeners.

Returns
  • a Collection of ApplicationListeners

protected Collection<ApplicationListener> getApplicationListeners (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

protected boolean supportsEvent (ApplicationListener listener, Class<? extends 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