org.springframework.messaging.simp.broker

## Class AbstractBrokerMessageHandler

- java.lang.Object
- - org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler

- All Implemented Interfaces:
    Aware, ApplicationEventPublisherAware, Lifecycle, Phased, SmartLifecycle, MessageHandler
  Direct Known Subclasses:
    SimpleBrokerMessageHandler, StompBrokerRelayMessageHandler

      public abstract class AbstractBrokerMessageHandler
      extends Object
      implements MessageHandler, SmartLifecycle, ApplicationEventPublisherAware

  Abstract base class for a `MessageHandler` that broker messages to registered subscribers.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractBrokerMessageHandler()`
    `AbstractBrokerMessageHandler(Collection<String> destinationPrefixes)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `checkDestinationPrefix(String destination)`
    `ApplicationEventPublisher` | `getApplicationEventPublisher()`
    `Collection<String>` | `getDestinationPrefixes()`
    `int` | `getPhase()` Return the phase value of this object.
    `void` | `handleMessage(Message<?> message)` Handle the given message.
    `protected abstract void` | `handleMessageInternal(Message<?> message)`
    `boolean` | `isAutoStartup()` Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed.
    `boolean` | `isBrokerAvailable()` Whether the message broker is currently available and able to process messages.
    `boolean` | `isRunning()` Check whether this message handler is currently running.
    `protected void` | `publishBrokerAvailableEvent()`
    `protected void` | `publishBrokerUnavailableEvent()`
    `void` | `setApplicationEventPublisher(ApplicationEventPublisher publisher)` Set the ApplicationEventPublisher that this object runs in.
    `void` | `setAutoStartup(boolean autoStartup)`
    `void` | `start()` Start this component.
    `protected void` | `startInternal()`
    `void` | `stop()` Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
    `void` | `stop(Runnable callback)` Indicates that a Lifecycle component must stop if it is currently running.
    `protected void` | `stopInternal()`

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

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

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### AbstractBrokerMessageHandler

          public AbstractBrokerMessageHandler()

    - #### AbstractBrokerMessageHandler

          public AbstractBrokerMessageHandler(Collection<String> destinationPrefixes)

  - ### Method Detail

    - #### getDestinationPrefixes

          public Collection<String> getDestinationPrefixes()

    - #### setApplicationEventPublisher

          public void setApplicationEventPublisher(ApplicationEventPublisher publisher)

      Description copied from interface: `ApplicationEventPublisherAware`
      Set the ApplicationEventPublisher that this object runs in.

      Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.

      Specified by:
        `setApplicationEventPublisher` in interface `ApplicationEventPublisherAware`
      Parameters:
        `publisher` - event publisher to be used by this object

    - #### getApplicationEventPublisher

          public ApplicationEventPublisher getApplicationEventPublisher()

    - #### setAutoStartup

          public void setAutoStartup(boolean autoStartup)

    - #### isAutoStartup

          public boolean isAutoStartup()

      Description copied from interface: `SmartLifecycle`
      Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed. A value of "false" indicates that the component is intended to be started manually.
      Specified by:
        `isAutoStartup` in interface `SmartLifecycle`

    - #### getPhase

          public int getPhase()

      Description copied from interface: `Phased`
      Return the phase value of this object.
      Specified by:
        `getPhase` in interface `Phased`

    - #### isRunning

          public final boolean isRunning()

      Check whether this message handler is currently running.

      Note that even when this message handler is running the `isBrokerAvailable()` flag may still independently alternate between being on and off depending on the concrete sub-class implementation.

      Specified by:
        `isRunning` in interface `Lifecycle`
      Returns:
        whether the component is currently running

    - #### isBrokerAvailable

          public boolean isBrokerAvailable()

      Whether the message broker is currently available and able to process messages.

      Note that this is in addition to the `isRunning()` flag, which indicates whether this message handler is running. In other words the message handler must first be running and then the `isBrokerAvailable()` flag may still independently alternate between being on and off depending on the concrete sub-class implementation.

      Application components may implement `org.springframework.context.ApplicationListener>` to receive notifications when broker becomes available and unavailable.

    - #### start

          public final void start()

      Description copied from interface: `Lifecycle`
      Start this component. Should not throw an exception if the component is already running.

      In the case of a container, this will propagate the start signal to all components that apply.

      Specified by:
        `start` in interface `Lifecycle`

    - #### startInternal

          protected void startInternal()

    - #### stop

          public final void stop()

      Description copied from interface: `Lifecycle`
      Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing `SmartLifecycle` and its `stop(Runnable)` variant in cases where asynchronous stop behavior is necessary.

      Should not throw an exception if the component isn't started yet.

      In the case of a container, this will propagate the stop signal to all components that apply.

      Specified by:
        `stop` in interface `Lifecycle`
      See Also:
        `SmartLifecycle.stop(Runnable)`

    - #### stopInternal

          protected void stopInternal()

    - #### stop

          public final void stop(Runnable callback)

      Description copied from interface: `SmartLifecycle`
      Indicates that a Lifecycle component must stop if it is currently running.

      The provided callback is used by the `LifecycleProcessor` to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.

      The `LifecycleProcessor` will call only this variant of the `stop` method; i.e. `Lifecycle.stop()` will not be called for `SmartLifecycle` implementations unless explicitly delegated to within this method.

      Specified by:
        `stop` in interface `SmartLifecycle`

    - #### handleMessage

          public final void handleMessage(Message<?> message)

      Description copied from interface: `MessageHandler`
      Handle the given message.
      Specified by:
        `handleMessage` in interface `MessageHandler`
      Parameters:
        `message` - the message to be handled

    - #### handleMessageInternal

          protected abstract void handleMessageInternal(Message<?> message)

    - #### checkDestinationPrefix

          protected boolean checkDestinationPrefix(String destination)

    - #### publishBrokerAvailableEvent

          protected void publishBrokerAvailableEvent()

    - #### publishBrokerUnavailableEvent

          protected void publishBrokerUnavailableEvent()