Class DeferredApplicationEventPublisher

  • All Implemented Interfaces:
    java.util.EventListener, org.springframework.context.ApplicationEventPublisher, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>

    public class DeferredApplicationEventPublisher
    extends java.lang.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void onApplicationEvent​(org.springframework.context.event.ContextRefreshedEvent event)  
      void publishEvent​(java.lang.Object event)
      Current method will not be invoked before Spring 4.2
      void publishEvent​(org.springframework.context.ApplicationEvent event)  
      protected boolean supportsPublishEventMethod()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DeferredApplicationEventPublisher

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

      • 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​(java.lang.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>