public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler
SimpMessageType
, keeps track of subscriptions with the help of a
SubscriptionRegistry
and sends messages to subscribers.Modifier and Type | Class and Description |
---|---|
private class |
SimpleBrokerMessageHandler.HeartbeatTask |
private static class |
SimpleBrokerMessageHandler.SessionInfo |
Modifier and Type | Field and Description |
---|---|
private static byte[] |
EMPTY_PAYLOAD |
private MessageHeaderInitializer |
headerInitializer |
private java.util.concurrent.ScheduledFuture<?> |
heartbeatFuture |
private long[] |
heartbeatValue |
private PathMatcher |
pathMatcher |
private java.util.Map<java.lang.String,SimpleBrokerMessageHandler.SessionInfo> |
sessions |
private SubscriptionRegistry |
subscriptionRegistry |
private TaskScheduler |
taskScheduler |
logger
Constructor and Description |
---|
SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel,
SubscribableChannel brokerChannel,
java.util.Collection<java.lang.String> destinationPrefixes)
Create a SimpleBrokerMessageHandler instance with the given message channels
and destination prefixes.
|
Modifier and Type | Method and Description |
---|---|
MessageHeaderInitializer |
getHeaderInitializer()
Return the configured header initializer.
|
long[] |
getHeartbeatValue()
The configured value for the heart-beat settings.
|
SubscriptionRegistry |
getSubscriptionRegistry() |
TaskScheduler |
getTaskScheduler()
Return the configured TaskScheduler.
|
private void |
handleDisconnect(java.lang.String sessionId,
java.security.Principal user) |
protected void |
handleMessageInternal(Message<?> message) |
private void |
initHeaders(SimpMessageHeaderAccessor accessor) |
private long |
initHeartbeatTaskDelay() |
private void |
initPathMatcherToUse() |
private void |
logMessage(Message<?> message) |
protected void |
sendMessageToSubscribers(java.lang.String destination,
Message<?> message) |
void |
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure a
MessageHeaderInitializer to apply to the headers
of all messages sent to the client outbound channel. |
void |
setHeartbeatValue(long[] heartbeat)
Configure the value for the heart-beat settings.
|
void |
setPathMatcher(PathMatcher pathMatcher)
When configured, the given PathMatcher is passed down to the
SubscriptionRegistry to use for matching destination to subscriptions.
|
void |
setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry)
Configure a custom SubscriptionRegistry to use for storing subscriptions.
|
void |
setTaskScheduler(TaskScheduler taskScheduler)
Configure the
TaskScheduler to
use for providing heartbeat support. |
void |
startInternal() |
void |
stopInternal() |
java.lang.String |
toString() |
private void |
updateSessionReadTime(java.lang.String sessionId) |
checkDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getDestinationPrefixes, getPhase, handleMessage, isAutoStartup, isBrokerAvailable, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, start, stop, stop
private static final byte[] EMPTY_PAYLOAD
private final java.util.Map<java.lang.String,SimpleBrokerMessageHandler.SessionInfo> sessions
private SubscriptionRegistry subscriptionRegistry
private PathMatcher pathMatcher
private TaskScheduler taskScheduler
private long[] heartbeatValue
private java.util.concurrent.ScheduledFuture<?> heartbeatFuture
private MessageHeaderInitializer headerInitializer
public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, java.util.Collection<java.lang.String> destinationPrefixes)
clientInboundChannel
- the channel for receiving messages from clients (e.g. WebSocket clients)clientOutboundChannel
- 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 messagespublic void setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry)
Note that when a custom PathMatcher is configured via
setPathMatcher(org.springframework.util.PathMatcher)
, if the custom registry is not an instance of
DefaultSubscriptionRegistry
, the provided PathMatcher is not used
and must be configured directly on the custom registry.
private void initPathMatcherToUse()
public SubscriptionRegistry getSubscriptionRegistry()
public void setPathMatcher(PathMatcher pathMatcher)
public void setTaskScheduler(TaskScheduler taskScheduler)
TaskScheduler
to
use for providing heartbeat support. Setting this property also sets the
heartbeatValue
to "10000, 10000".
By default this is not set.
public TaskScheduler getTaskScheduler()
public void setHeartbeatValue(long[] heartbeat)
By default this is set to "0, 0" unless the taskScheduler
in which case the default becomes "10000,10000"
(in milliseconds).
public long[] getHeartbeatValue()
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to apply to the headers
of all messages sent to the client outbound channel.
By default this property is not set.
public MessageHeaderInitializer getHeaderInitializer()
public void startInternal()
startInternal
in class AbstractBrokerMessageHandler
private long initHeartbeatTaskDelay()
public void stopInternal()
stopInternal
in class AbstractBrokerMessageHandler
protected void handleMessageInternal(Message<?> message)
handleMessageInternal
in class AbstractBrokerMessageHandler
private void updateSessionReadTime(java.lang.String sessionId)
private void logMessage(Message<?> message)
private void initHeaders(SimpMessageHeaderAccessor accessor)
private void handleDisconnect(java.lang.String sessionId, java.security.Principal user)
protected void sendMessageToSubscribers(java.lang.String destination, Message<?> message)
public java.lang.String toString()
toString
in class java.lang.Object