Class DeferredApplicationEventPublisher

java.lang.Object
io.microsphere.spring.context.event.DeferredApplicationEventPublisher
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationEventPublisher, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>

public class DeferredApplicationEventPublisher extends Object implements org.springframework.context.ApplicationEventPublisher, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
Before Spring Framework 4.2, AbstractApplicationContext is an implementation of ApplicationEventPublisher can't handle the early event that is published before ApplicationEventMulticaster's initialization, in this scenario, DeferredApplicationEventPublisher is introduced and used to resolve publishEvent(ApplicationEvent) too early to publish ApplicationEvent when Spring ApplicationContexts' ApplicationEventMulticaster is not ready. First, DeferredApplicationEventPublisher stores these early events temporarily, and then re-publish them on Application context is ready.

In contrast, If current runtime is based on Spring Framework that supports early application events, DeferredApplicationEventPublisher only delegates the Application Context that was injected by constructor.

Since:
1.0.0
Author:
Mercy
  • Constructor Details

    • DeferredApplicationEventPublisher

      public DeferredApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher delegate)
      Parameters:
      delegate - ApplicationEventPublisher
  • Method Details

    • supportsPublishEventMethod

      protected boolean supportsPublishEventMethod()
    • publishEvent

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

      public void publishEvent(Object event)
      Current method will not be invoked before Spring 4.2
      Specified by:
      publishEvent in interface org.springframework.context.ApplicationEventPublisher
      Parameters:
      event - the ApplicationEvent or the payload of event
    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>