Package org.springframework.context.event

# Class AbstractApplicationEventMulticaster

java.lang.Object
org.springframework.context.event.AbstractApplicationEventMulticaster

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanClassLoaderAware`, `org.springframework.beans.factory.BeanFactoryAware`, `ApplicationEventMulticaster`

Direct Known Subclasses:
  `SimpleApplicationEventMulticaster`

public abstract class AbstractApplicationEventMulticaster extends Object implements ApplicationEventMulticaster, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware
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 `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 by default. Alternative implementations could be more sophisticated in those respects.

Since:
  1.2.3
Author:
  Juergen Hoeller, Stephane Nicoll
See Also:
  - `getApplicationListeners(ApplicationEvent, ResolvableType)`
  - `SimpleApplicationEventMulticaster`

## Constructor Summary

Constructors
Constructor
Description
`AbstractApplicationEventMulticaster()`

## Method Summary

Modifier and Type
Method
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, org.springframework.core.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`, for example, for annotated `EventListener` methods).
`void`
`setBeanClassLoader(ClassLoader classLoader)`
`void`
`setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)`
`protected boolean`
`supportsEvent(Class<?> listenerType, org.springframework.core.ResolvableType eventType)`
Filter a listener early through checking its generically declared event type before trying to instantiate it.
`protected boolean`
`supportsEvent(ApplicationListener<?> listener, org.springframework.core.ResolvableType eventType, Class<?> sourceType)`
Determine whether the given listener supports the given event.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.context.event.ApplicationEventMulticaster

`multicastEvent, multicastEvent`

## Constructor Details

### AbstractApplicationEventMulticaster

public AbstractApplicationEventMulticaster()

## Method Details

### setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)

Specified by:
  `setBeanClassLoader` in interface `org.springframework.beans.factory.BeanClassLoaderAware`

### setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

Specified by:
  `setBeanFactory` in interface `org.springframework.beans.factory.BeanFactoryAware`

### addApplicationListener

public void addApplicationListener(ApplicationListener<?> listener)
Description copied from interface: `ApplicationEventMulticaster`
Add a listener to be notified of all events.

Specified by:
  `addApplicationListener` in interface `ApplicationEventMulticaster`
Parameters:
  `listener` - the listener to add
See Also:
  - `ApplicationEventMulticaster.removeApplicationListener(ApplicationListener)`
  - `ApplicationEventMulticaster.removeApplicationListeners(Predicate)`

### addApplicationListenerBean

public void addApplicationListenerBean(String listenerBeanName)
Description copied from interface: `ApplicationEventMulticaster`
Add a listener bean to be notified of all events.

Specified by:
  `addApplicationListenerBean` in interface `ApplicationEventMulticaster`
Parameters:
  `listenerBeanName` - the name of the listener bean to add
See Also:
  - `ApplicationEventMulticaster.removeApplicationListenerBean(String)`
  - `ApplicationEventMulticaster.removeApplicationListenerBeans(Predicate)`

### removeApplicationListener

public void removeApplicationListener(ApplicationListener<?> listener)
Description copied from interface: `ApplicationEventMulticaster`
Remove a listener from the notification list.

Specified by:
  `removeApplicationListener` in interface `ApplicationEventMulticaster`
Parameters:
  `listener` - the listener to remove
See Also:
  - `ApplicationEventMulticaster.addApplicationListener(ApplicationListener)`
  - `ApplicationEventMulticaster.removeApplicationListeners(Predicate)`

### removeApplicationListenerBean

public void removeApplicationListenerBean(String listenerBeanName)
Description copied from interface: `ApplicationEventMulticaster`
Remove a listener bean from the notification list.

Specified by:
  `removeApplicationListenerBean` in interface `ApplicationEventMulticaster`
Parameters:
  `listenerBeanName` - the name of the listener bean to remove
See Also:
  - `ApplicationEventMulticaster.addApplicationListenerBean(String)`
  - `ApplicationEventMulticaster.removeApplicationListenerBeans(Predicate)`

### removeApplicationListeners

public void removeApplicationListeners(Predicate<ApplicationListener<?>> predicate)
Description copied from interface: `ApplicationEventMulticaster`
Remove all matching listeners from the set of registered `ApplicationListener` instances (which includes adapter classes such as `ApplicationListenerMethodAdapter`, for example, for annotated `EventListener` methods).

Note: This just applies to instance registrations, not to listeners registered by bean name.

Specified by:
  `removeApplicationListeners` in interface `ApplicationEventMulticaster`
Parameters:
  `predicate` - the predicate to identify listener instances to remove, for example, checking `SmartApplicationListener.getListenerId()`
See Also:
  - `ApplicationEventMulticaster.addApplicationListener(ApplicationListener)`
  - `ApplicationEventMulticaster.removeApplicationListener(ApplicationListener)`

### removeApplicationListenerBeans

public void removeApplicationListenerBeans(Predicate<String> predicate)
Description copied from interface: `ApplicationEventMulticaster`
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).

Note: This just applies to bean name registrations, not to programmatically registered `ApplicationListener` instances.

Specified by:
  `removeApplicationListenerBeans` in interface `ApplicationEventMulticaster`
Parameters:
  `predicate` - the predicate to identify listener bean names to remove
See Also:
  - `ApplicationEventMulticaster.addApplicationListenerBean(String)`
  - `ApplicationEventMulticaster.removeApplicationListenerBean(String)`

### removeAllListeners

public void removeAllListeners()
Description copied from interface: `ApplicationEventMulticaster`
Remove all listeners registered with this multicaster.

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

Specified by:
  `removeAllListeners` in interface `ApplicationEventMulticaster`
See Also:
  - `ApplicationEventMulticaster.removeApplicationListeners(Predicate)`

### getApplicationListeners

protected Collection<ApplicationListener<?>> getApplicationListeners()
Return a Collection containing all ApplicationListeners.

Returns:
  a Collection of ApplicationListeners
See Also:
  - `ApplicationListener`

### getApplicationListeners

protected Collection<ApplicationListener<?>> getApplicationListeners(ApplicationEvent event, org.springframework.core.ResolvableType eventType)
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.
  `eventType` - the event type
Returns:
  a Collection of ApplicationListeners
See Also:
  - `ApplicationListener`

### supportsEvent

protected boolean supportsEvent(Class<?> listenerType, org.springframework.core.ResolvableType eventType)
Filter a listener early through checking its generically declared event type before trying to instantiate it.

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.

Parameters:
  `listenerType` - the listener's type as determined by the BeanFactory
  `eventType` - the event type to check
Returns:
  whether the given listener should be included in the candidates for the given event type

### supportsEvent

protected boolean supportsEvent(ApplicationListener<?> listener, org.springframework.core.ResolvableType eventType, @Nullable Class<?> sourceType)
Determine whether the given listener supports the given event.

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.

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