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, ApplicationEventPublisherAware, SmartLifecycle
Abstract base class for aMessageHandlerthat broker messages to registered subscribers.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel)Constructor with no destination prefixes (matches all destinations).AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)Constructor with destination prefixes to match to destinations of messages.
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancheckDestinationPrefix(String destination)ApplicationEventPublishergetApplicationEventPublisher()SubscribableChannelgetBrokerChannel()SubscribableChannelgetClientInboundChannel()MessageChannelgetClientOutboundChannel()Collection<String>getDestinationPrefixes()intgetPhase()Return the phase value of this object.voidhandleMessage(Message<?> message)Handle the given message.protected abstract voidhandleMessageInternal(Message<?> message)booleanisAutoStartup()Returnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.booleanisBrokerAvailable()Whether the message broker is currently available and able to process messages.booleanisRunning()Check whether this message handler is currently running.protected voidpublishBrokerAvailableEvent()protected voidpublishBrokerUnavailableEvent()voidsetApplicationEventPublisher(ApplicationEventPublisher publisher)Set the ApplicationEventPublisher that this object runs in.voidsetAutoStartup(boolean autoStartup)voidstart()Start this component.protected voidstartInternal()voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.voidstop(Runnable callback)Indicates that a Lifecycle component must stop if it is currently running.protected voidstopInternal()
Constructor Detail
AbstractBrokerMessageHandler
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel)
Constructor with no destination prefixes (matches all destinations).- Parameters:
inboundChannel- the channel for receiving messages from clients (e.g. WebSocket clients)outboundChannel- the channel for sending messages to clients (e.g. WebSocket clients)brokerChannel- the channel for the application to send messages to the broker
AbstractBrokerMessageHandler
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)
Constructor with destination prefixes to match to destinations of messages.- Parameters:
inboundChannel- the channel for receiving messages from clients (e.g. WebSocket clients)outboundChannel- the channel for sending messages to clients (e.g. WebSocket clients)brokerChannel- the channel for the application to send messages to the brokerdestinationPrefixes- prefixes to use to filter out messages
Method Detail
getClientInboundChannel
public SubscribableChannel getClientInboundChannel()
getClientOutboundChannel
public MessageChannel getClientOutboundChannel()
getBrokerChannel
public SubscribableChannel getBrokerChannel()
getDestinationPrefixes
public Collection<String> getDestinationPrefixes()
setApplicationEventPublisher
public void setApplicationEventPublisher(ApplicationEventPublisher publisher)
Description copied from interface:ApplicationEventPublisherAwareSet 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:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware- 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:SmartLifecycleReturnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.A value of
falseindicates that the component is intended to be started through an explicitLifecycle.start()call instead, analogous to a plainLifecycleimplementation.- Specified by:
isAutoStartupin interfaceSmartLifecycle- See Also:
Lifecycle.start(),Phased.getPhase(),LifecycleProcessor.onRefresh(),ConfigurableApplicationContext.refresh()
getPhase
public int getPhase()
Description copied from interface:PhasedReturn the phase value of this object.
start
public void start()
Description copied from interface:LifecycleStart 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:
startin interfaceLifecycle- See Also:
SmartLifecycle.isAutoStartup()
startInternal
protected void startInternal()
stop
public void stop()
Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
- Specified by:
stopin interfaceLifecycle- See Also:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stopInternal
protected void stopInternal()
stop
public final void stop(Runnable callback)
Description copied from interface:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The
LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.- Specified by:
stopin interfaceSmartLifecycle- See Also:
Lifecycle.stop(),Phased.getPhase()
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.
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<BrokerAvailabilityEvent>to receive notifications when broker becomes available and unavailable.
handleMessage
public void handleMessage(Message<?> message)
Description copied from interface:MessageHandlerHandle the given message.- Specified by:
handleMessagein interfaceMessageHandler- 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()