org.springframework.context.event

## 类 SimpleApplicationEventMulticaster

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

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, ApplicationEventMulticaster

      public class SimpleApplicationEventMulticaster
      extends AbstractApplicationEventMulticaster

  Simple implementation of the `ApplicationEventMulticaster` interface.

  Multicasts all events to all registered listeners, leaving it up to the listeners to ignore events that they are not interested in. Listeners will usually perform corresponding `instanceof` checks on the passed-in event object.

  By default, all listeners are invoked in the calling thread. This allows the danger of a rogue listener blocking the entire application, but adds minimal overhead. Specify an alternative task executor to have listeners executed in different threads, for example from a thread pool.

  作者:
    Rod Johnson, Juergen Hoeller, Stephane Nicoll
  另请参阅:
    `setTaskExecutor(java.util.concurrent.Executor)`

- - ### 构造器概要

    构造器
    构造器和说明
    `SimpleApplicationEventMulticaster()` Create a new SimpleApplicationEventMulticaster.
    `SimpleApplicationEventMulticaster(org.springframework.beans.factory.BeanFactory beanFactory)` Create a new SimpleApplicationEventMulticaster for the given BeanFactory.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected org.springframework.util.ErrorHandler` | `getErrorHandler()` Return the current error handler for this multicaster.
    `protected Executor` | `getTaskExecutor()` Return the current task executor for this multicaster.
    `protected void` | `invokeListener(ApplicationListener<?> listener, ApplicationEvent event)` Invoke the given listener with the given event.
    `void` | `multicastEvent(ApplicationEvent event)` Multicast the given application event to appropriate listeners.
    `void` | `multicastEvent(ApplicationEvent event, org.springframework.core.ResolvableType eventType)` Multicast the given application event to appropriate listeners.
    `void` | `setErrorHandler(org.springframework.util.ErrorHandler errorHandler)` Set the `ErrorHandler` to invoke in case an exception is thrown from a listener.
    `void` | `setTaskExecutor(Executor taskExecutor)` Set a custom executor (typically a `TaskExecutor`) to invoke each listener with.

    - ### 从类继承的方法 org.springframework.context.event.AbstractApplicationEventMulticaster

      `addApplicationListener, addApplicationListenerBean, getApplicationListeners, getApplicationListeners, removeAllListeners, removeApplicationListener, removeApplicationListenerBean, setBeanClassLoader, setBeanFactory, supportsEvent, supportsEvent`

    - ### 从类继承的方法 java.lang.Object

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

- - ### 构造器详细资料

    - #### SimpleApplicationEventMulticaster

          public SimpleApplicationEventMulticaster()

      Create a new SimpleApplicationEventMulticaster.

    - #### SimpleApplicationEventMulticaster

          public SimpleApplicationEventMulticaster(org.springframework.beans.factory.BeanFactory beanFactory)

      Create a new SimpleApplicationEventMulticaster for the given BeanFactory.

  - ### 方法详细资料

    - #### setTaskExecutor

          public void setTaskExecutor(@Nullable
                                      Executor taskExecutor)

      Set a custom executor (typically a `TaskExecutor`) to invoke each listener with.

      Default is equivalent to `SyncTaskExecutor`, executing all listeners synchronously in the calling thread.

      Consider specifying an asynchronous task executor 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.

      另请参阅:
        `SyncTaskExecutor`, `SimpleAsyncTaskExecutor`

    - #### getTaskExecutor

          @Nullable
          protected Executor getTaskExecutor()

      Return the current task executor for this multicaster.

    - #### setErrorHandler

          public void setErrorHandler(@Nullable
                                      org.springframework.util.ErrorHandler errorHandler)

      Set the `ErrorHandler` to invoke in case an exception is thrown from a listener.

      Default is none, with a listener exception stopping the current multicast and getting propagated to the publisher of the current event. If a task executor is specified, each individual listener exception will get propagated to the executor but won't necessarily stop execution of other listeners.

      Consider setting an `ErrorHandler` implementation that catches and logs exceptions (a la `TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER`) or an implementation that logs exceptions while nevertheless propagating them (e.g. `TaskUtils.LOG_AND_PROPAGATE_ERROR_HANDLER`).

      从以下版本开始:
        4.1

    - #### getErrorHandler

          @Nullable
          protected org.springframework.util.ErrorHandler getErrorHandler()

      Return the current error handler for this multicaster.
      从以下版本开始:
        4.1

    - #### multicastEvent

          public void multicastEvent(ApplicationEvent event)

      从接口复制的说明: `ApplicationEventMulticaster`
      Multicast the given application event to appropriate listeners.

      Consider using `ApplicationEventMulticaster.multicastEvent(ApplicationEvent, ResolvableType)` if possible as it provides a better support for generics-based events.

      参数:
        `event` - the event to multicast

    - #### multicastEvent

          public void multicastEvent(ApplicationEvent event,
                                     @Nullable
                                     org.springframework.core.ResolvableType eventType)

      从接口复制的说明: `ApplicationEventMulticaster`
      Multicast the given application event to appropriate listeners.

      If the `eventType` is `null`, a default type is built based on the `event` instance.

      参数:
        `event` - the event to multicast
        `eventType` - the type of event (can be null)

    - #### invokeListener

          protected void invokeListener(ApplicationListener<?> listener,
                                        ApplicationEvent event)

      Invoke the given listener with the given event.
      参数:
        `listener` - the ApplicationListener to invoke
        `event` - the current event to propagate
      从以下版本开始:
        4.1