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 java.lang.Integer |
cacheLimit |
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,
Message<?> origMessage) |
protected void |
handleMessageInternal(Message<?> message) |
private void |
initCacheLimitToUse() |
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 |
setCacheLimit(java.lang.Integer cacheLimit)
When configured, the specified cache limit is passed down to the
underlying SubscriptionRegistry, overriding any default there.
|
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 underlying
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
@Nullable private PathMatcher pathMatcher
@Nullable private java.lang.Integer cacheLimit
@Nullable private TaskScheduler taskScheduler
@Nullable private long[] heartbeatValue
@Nullable private java.util.concurrent.ScheduledFuture<?> heartbeatFuture
@Nullable 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.
public SubscriptionRegistry getSubscriptionRegistry()
public void setPathMatcher(@Nullable PathMatcher pathMatcher)
Default is a standard AntPathMatcher
.
private void initPathMatcherToUse()
public void setCacheLimit(@Nullable java.lang.Integer cacheLimit)
With a standard DefaultSubscriptionRegistry
, the default
cache limit is 1024.
private void initCacheLimitToUse()
public void setTaskScheduler(@Nullable 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.
@Nullable public TaskScheduler getTaskScheduler()
public void setHeartbeatValue(@Nullable long[] heartbeat)
By default this is set to "0, 0" unless the taskScheduler
in which case the default becomes "10000,10000"
(in milliseconds).
@Nullable public long[] getHeartbeatValue()
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to apply to the headers
of all messages sent to the client outbound channel.
By default this property is not set.
@Nullable 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(@Nullable java.lang.String sessionId)
private void logMessage(Message<?> message)
private void initHeaders(SimpMessageHeaderAccessor accessor)
private void handleDisconnect(java.lang.String sessionId, @Nullable java.security.Principal user, @Nullable Message<?> origMessage)
protected void sendMessageToSubscribers(@Nullable java.lang.String destination, Message<?> message)
public java.lang.String toString()
toString
in class java.lang.Object