/** * Get the MessageChannel to use for sending messages to clients, possibly * a per-session wrapper when {@code preservePublishOrder=true}. * @since 5.1 */ protected MessageChannel getClientOutboundChannelForSession(String sessionId) { return this.preservePublishOrder ? new OrderedMessageSender(getClientOutboundChannel(), logger) : getClientOutboundChannel(); }
@Override protected MultiValueMap<String, String> findSubscriptionsInternal(String destination, Message<?> message) { MultiValueMap<String, String> result = this.destinationCache.getSubscriptions(destination, message); return filterSubscriptions(result, message); }
@Override public void unregisterAllSubscriptions(String sessionId) { SessionSubscriptionInfo info = this.subscriptionRegistry.removeSubscriptions(sessionId); if (info != null) { this.destinationCache.updateAfterRemovedSession(info); } }
@Override protected void removeSubscriptionInternal(String sessionId, String subsId, Message<?> message) { SessionSubscriptionInfo info = this.subscriptionRegistry.getSubscriptions(sessionId); if (info != null) { String destination = info.removeSubscription(subsId); if (destination != null) { this.destinationCache.updateAfterRemovedSubscription(sessionId, subsId); } } }
@Override protected void addSubscriptionInternal( String sessionId, String subsId, String destination, Message<?> message) { Expression expression = getSelectorExpression(message.getHeaders()); this.subscriptionRegistry.addSubscription(sessionId, subsId, destination, expression); this.destinationCache.updateAfterNewSubscription(destination, sessionId, subsId); }
@Override protected boolean removeEldestEntry(Map.Entry<String, LinkedMultiValueMap<String, String>> eldest) { if (size() > getCacheLimit()) { accessCache.remove(eldest.getKey()); return true; } else { return false; } } };
private long initHeartbeatTaskDelay() { if (getHeartbeatValue() == null) { return 0; } else if (getHeartbeatValue()[0] > 0 && getHeartbeatValue()[1] > 0) { return Math.min(getHeartbeatValue()[0], getHeartbeatValue()[1]); } else { return (getHeartbeatValue()[0] > 0 ? getHeartbeatValue()[0] : getHeartbeatValue()[1]); } }
@Test(expected = IllegalArgumentException.class) public void startWithHeartbeatValueWithoutTaskScheduler() { this.messageHandler.setHeartbeatValue(new long[] {10000, 10000}); this.messageHandler.start(); }
private void initSelectorHeaderNameToUse() { if (this.subscriptionRegistry instanceof DefaultSubscriptionRegistry) { ((DefaultSubscriptionRegistry) this.subscriptionRegistry).setSelectorHeaderName(this.selectorHeaderName); } }
private void initCacheLimitToUse() { if (this.cacheLimit != null && this.subscriptionRegistry instanceof DefaultSubscriptionRegistry) { ((DefaultSubscriptionRegistry) this.subscriptionRegistry).setCacheLimit(this.cacheLimit); } }
public boolean send(Message<?> message) { return send(message, -1); }
/** * Whether the client must receive messages in the order of publication. * <p>By default messages sent to the {@code "clientOutboundChannel"} may * not be processed in the same order because the channel is backed by a * ThreadPoolExecutor that in turn does not guarantee processing in order. * <p>When this flag is set to {@code true} messages within the same session * will be sent to the {@code "clientOutboundChannel"} one at a time in * order to preserve the order of publication. Enable this only if needed * since there is some performance overhead to keep messages in order. * @param preservePublishOrder whether to publish in order * @since 5.1 */ public void setPreservePublishOrder(boolean preservePublishOrder) { OrderedMessageSender.configureOutboundChannel(this.clientOutboundChannel, preservePublishOrder); this.preservePublishOrder = preservePublishOrder; }
private void initPathMatcherToUse() { if (this.pathMatcher != null && this.subscriptionRegistry instanceof DefaultSubscriptionRegistry) { ((DefaultSubscriptionRegistry) this.subscriptionRegistry).setPathMatcher(this.pathMatcher); } }
/** * Create a SimpleBrokerMessageHandler instance with the given message channels * and destination prefixes. * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients) * @param clientOutboundChannel the channel for sending messages to clients (e.g. WebSocket clients) * @param brokerChannel the channel for the application to send messages to the broker * @param destinationPrefixes prefixes to use to filter out messages */ public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) { super(clientInboundChannel, clientOutboundChannel, brokerChannel, destinationPrefixes); this.subscriptionRegistry = new DefaultSubscriptionRegistry(); }
@Override public String toString() { return "BrokerAvailabilityEvent[available=" + this.brokerAvailable + ", " + getSource() + "]"; }
@Override public boolean send(Message<?> message, long timeout) { this.messages.add(message); trySend(); return true; }
@Override public final void stop(Runnable callback) { synchronized (this.lifecycleMonitor) { stop(); callback.run(); } }
private void initHeaders(SimpMessageHeaderAccessor accessor) { if (getHeaderInitializer() != null) { getHeaderInitializer().initHeaders(accessor); } }
@Override public void publishEvent(ApplicationEvent event) { publishEvent((Object) event); }
private Message<?> subscribeMessage(String sessionId, String subscriptionId, String destination) { return subscribeMessage(sessionId, subscriptionId, destination, null); }