Interface ApplicationEventPublisher<T>

Type Parameters:
T - The event type
All Known Subinterfaces:
ApplicationContext, BeanContext, InitializableBeanContext
All Known Implementing Classes:
DefaultApplicationContext, DefaultBeanContext

public interface ApplicationEventPublisher<T>

Interface for classes that publish events received by ApplicationEventListener instances.

Note that this interface is designed for application level, non-blocking synchronous events for decoupling code and is not a replacement for a messaging system

Since:
1.0
Author:
Graeme Rocher
  • Field Details

  • Method Details

    • noOp

      static <K> ApplicationEventPublisher<K> noOp()
      Returns a no-op instance of ApplicationEventPublisher.
      Type Parameters:
      K - The event type
      Returns:
      an instance of ApplicationEventPublisher
    • publishEvent

      void publishEvent(@NonNull T event)
      Publish the given event. The event will be published synchronously and only return once all listeners have consumed the event.
      Parameters:
      event - The event to publish
    • publishEventAsync

      @NonNull default @NonNull Future<Void> publishEventAsync(@NonNull T event)
      Publish the given event. The event will be published asynchronously. A future is returned that can be used to check whether the event completed successfully or not.
      Parameters:
      event - The event to publish
      Returns:
      A future that completes when the event is published
      Since:
      1.3.5
    • isEmpty

      default boolean isEmpty()
      Check whether this publisher is empty (i.e. has no listeners). If this method returns true, publishEvent(Object) does not need to be called.
      Returns:
      true iff there are no subscribers
      Since:
      4.0.0