Browse Source

Add SimpLogging and use o.s.messaging.simp classes

Issue: SPR-17012
pull/1920/head
Rossen Stoyanchev 6 years ago
parent
commit
833aee9b2d
  1. 25
      spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java
  2. 31
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java
  3. 23
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java
  4. 3
      spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java
  5. 68
      spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java
  6. 14
      spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java
  7. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java
  8. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java
  9. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java
  10. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java
  11. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
  12. 11
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java
  13. 19
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java
  14. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java
  15. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
  16. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java
  17. 4
      spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java
  18. 19
      spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java
  19. 22
      spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

25
spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java

@ -50,8 +50,11 @@ import org.springframework.util.ClassUtils;
*/ */
public class HandlerMethod { public class HandlerMethod {
/** Logger that is available to subclasses. */ /** Public for wrapping with fallback logger. */
protected final Log logger = LogFactory.getLog(getClass()); public static final Log defaultLogger = LogFactory.getLog(HandlerMethod.class);
protected Log logger = defaultLogger;
private final Object bean; private final Object bean;
@ -161,6 +164,24 @@ public class HandlerMethod {
return result; return result;
} }
/**
* Set an alternative logger to use than the one based on the class name.
* @param logger the logger to use
* @since 5.1
*/
public void setLogger(Log logger) {
this.logger = logger;
}
/**
* Return the currently configured Logger.
* @since 5.1
*/
public Log getLogger() {
return logger;
}
/** /**
* Return the bean for this handler method. * Return the bean for this handler method.
*/ */

31
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

@ -85,6 +85,10 @@ public abstract class AbstractMethodMessageHandler<T>
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private Log handlerMethodLogger;
private final List<String> destinationPrefixes = new ArrayList<>(); private final List<String> destinationPrefixes = new ArrayList<>();
private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<>(4); private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<>(4);
@ -232,6 +236,12 @@ public abstract class AbstractMethodMessageHandler<T>
if (this.returnValueHandlers.getReturnValueHandlers().isEmpty()) { if (this.returnValueHandlers.getReturnValueHandlers().isEmpty()) {
this.returnValueHandlers.addHandlers(initReturnValueHandlers()); this.returnValueHandlers.addHandlers(initReturnValueHandlers());
} }
Log returnValueLogger = getReturnValueHandlerLogger();
if (returnValueLogger != null) {
this.returnValueHandlers.setLogger(returnValueLogger);
}
this.handlerMethodLogger = getHandlerMethodLogger();
ApplicationContext context = getApplicationContext(); ApplicationContext context = getApplicationContext();
if (context == null) { if (context == null) {
@ -367,6 +377,24 @@ public abstract class AbstractMethodMessageHandler<T>
*/ */
protected abstract Set<String> getDirectLookupDestinations(T mapping); protected abstract Set<String> getDirectLookupDestinations(T mapping);
/**
* Return a logger to set on {@link HandlerMethodReturnValueHandlerComposite}.
* @since 5.1
*/
@Nullable
protected Log getReturnValueHandlerLogger() {
return null;
}
/**
* Return a logger to set on {@link InvocableHandlerMethod}.
* @since 5.1
*/
@Nullable
protected Log getHandlerMethodLogger() {
return null;
}
/** /**
* Subclasses can invoke this method to populate the MessagingAdviceBean cache * Subclasses can invoke this method to populate the MessagingAdviceBean cache
* (e.g. to support "global" {@code @MessageExceptionHandler}). * (e.g. to support "global" {@code @MessageExceptionHandler}).
@ -514,6 +542,9 @@ public abstract class AbstractMethodMessageHandler<T>
} }
handlerMethod = handlerMethod.createWithResolvedBean(); handlerMethod = handlerMethod.createWithResolvedBean();
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod); InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
if (this.handlerMethodLogger != null) {
invocable.setLogger(this.handlerMethodLogger);
}
invocable.setMessageMethodArgumentResolvers(this.argumentResolvers); invocable.setMessageMethodArgumentResolvers(this.argumentResolvers);
try { try {
Object returnValue = invocable.invoke(message); Object returnValue = invocable.invoke(message);

23
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java

@ -37,11 +37,32 @@ import org.springframework.util.concurrent.ListenableFuture;
*/ */
public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMethodReturnValueHandler { public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMethodReturnValueHandler {
private static final Log logger = LogFactory.getLog(HandlerMethodReturnValueHandlerComposite.class); /** Public for wrapping with fallback logger. */
public static final Log defaultLogger = LogFactory.getLog(HandlerMethodReturnValueHandlerComposite.class);
private Log logger = defaultLogger;
private final List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>(); private final List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
/**
* Set an alternative logger to use than the one based on the class name.
* @param logger the logger to use
* @since 5.1
*/
public void setLogger(Log logger) {
this.logger = logger;
}
/**
* Return the currently configured Logger.
* @since 5.1
*/
public Log getLogger() {
return logger;
}
/** /**
* Return a read-only list with the configured handlers. * Return a read-only list with the configured handlers.
*/ */

3
spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java

@ -19,7 +19,6 @@ package org.springframework.messaging.simp;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
@ -46,7 +45,7 @@ public class SimpAttributes {
public static final String DESTRUCTION_CALLBACK_NAME_PREFIX = public static final String DESTRUCTION_CALLBACK_NAME_PREFIX =
SimpAttributes.class.getName() + ".DESTRUCTION_CALLBACK."; SimpAttributes.class.getName() + ".DESTRUCTION_CALLBACK.";
private static final Log logger = LogFactory.getLog(SimpAttributes.class); private static final Log logger = SimpLogging.forLogName(SimpAttributes.class);
private final String sessionId; private final String sessionId;

68
spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java

@ -0,0 +1,68 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.simp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.log.LogUtils;
/**
* Holds the shared logger named "org.springframework.web.SimpLogging" to use
* for STOMP over WebSocket messaging when logging for
* "org.springframework.messaging.simp" is off but logging for
* "org.springframework.web" is on.
*
* <p>This makes it possible to enable all web related logging via
* "org.springframework.web" including logging from lower-level packages such as
* "org.springframework.messaging.simp".
*
* <p>To see logging from the primary classes where log messages originate from,
* simply enable logging for "org.springframework.messaging".
*
* @author Rossen Stoyanchev
* @since 5.1
*/
public abstract class SimpLogging {
private static final Log fallbackLogger =
LogFactory.getLog("org.springframework.web." + SimpLogging.class.getSimpleName());
/**
* Create a primary logger for the given class and wrap it with a composite
* that delegates to it or to the fallback logger named
* "org.springframework.web.SimpLogging", if the primary is not enabled.
* @param primaryLoggerClass the class for the name of the primary logger
* @return the resulting composite logger
*/
public static Log forLogName(Class<?> primaryLoggerClass) {
Log primaryLogger = LogFactory.getLog(primaryLoggerClass);
return forLog(primaryLogger);
}
/**
* Wrap the given primary logger with a composite logger that delegates to
* either the primary or to the shared fallback logger
* "org.springframework.web.HttpLogging", if the primary is not enabled.
* @param primaryLogger the primary logger to use
* @return the resulting composite logger
*/
public static Log forLog(Log primaryLogger) {
return LogUtils.getCompositeLog(primaryLogger, fallbackLogger);
}
}

14
spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java

@ -25,6 +25,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@ -56,8 +58,10 @@ import org.springframework.messaging.handler.invocation.AbstractMethodMessageHan
import org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler; import org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite;
import org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler; import org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler;
import org.springframework.messaging.simp.SimpAttributesContextHolder; import org.springframework.messaging.simp.SimpAttributesContextHolder;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageMappingInfo; import org.springframework.messaging.simp.SimpMessageMappingInfo;
import org.springframework.messaging.simp.SimpMessageSendingOperations; import org.springframework.messaging.simp.SimpMessageSendingOperations;
@ -357,6 +361,16 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
return handlers; return handlers;
} }
@Override
protected Log getReturnValueHandlerLogger() {
return SimpLogging.forLog(HandlerMethodReturnValueHandlerComposite.defaultLogger);
}
@Override
protected Log getHandlerMethodLogger() {
return SimpLogging.forLog(HandlerMethod.defaultLogger);
}
@Override @Override
protected boolean isHandler(Class<?> beanType) { protected boolean isHandler(Class<?> beanType) {

4
spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java

@ -17,7 +17,6 @@
package org.springframework.messaging.simp.annotation.support; package org.springframework.messaging.simp.annotation.support;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -26,6 +25,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.messaging.core.MessageSendingOperations;
import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.SimpMessagingTemplate;
@ -58,7 +58,7 @@ import org.springframework.util.Assert;
*/ */
public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturnValueHandler { public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
private static final Log logger = LogFactory.getLog(SubscriptionMethodReturnValueHandler.class); private static final Log logger = SimpLogging.forLogName(SubscriptionMethodReturnValueHandler.class);
private final MessageSendingOperations<String> messagingTemplate; private final MessageSendingOperations<String> messagingTemplate;

4
spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java

@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
@ -31,6 +30,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.messaging.support.ChannelInterceptor;
@ -48,7 +48,7 @@ import org.springframework.util.CollectionUtils;
public abstract class AbstractBrokerMessageHandler public abstract class AbstractBrokerMessageHandler
implements MessageHandler, ApplicationEventPublisherAware, SmartLifecycle { implements MessageHandler, ApplicationEventPublisherAware, SmartLifecycle {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = SimpLogging.forLogName(getClass());
private final SubscribableChannel clientInboundChannel; private final SubscribableChannel clientInboundChannel;

4
spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java

@ -17,10 +17,10 @@
package org.springframework.messaging.simp.broker; package org.springframework.messaging.simp.broker;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -40,7 +40,7 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
private static final MultiValueMap<String, String> EMPTY_MAP = private static final MultiValueMap<String, String> EMPTY_MAP =
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0)); CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0));
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = SimpLogging.forLogName(getClass());
@Override @Override

4
spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java

@ -37,6 +37,7 @@ import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.StringMessageConverter; import org.springframework.messaging.converter.StringMessageConverter;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler; import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
@ -125,6 +126,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Bean @Bean
public AbstractSubscribableChannel clientInboundChannel() { public AbstractSubscribableChannel clientInboundChannel() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor()); ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor());
channel.setLogger(SimpLogging.forLog(channel.getLogger()));
ChannelRegistration reg = getClientInboundChannelRegistration(); ChannelRegistration reg = getClientInboundChannelRegistration();
if (reg.hasInterceptors()) { if (reg.hasInterceptors()) {
channel.setInterceptors(reg.getInterceptors()); channel.setInterceptors(reg.getInterceptors());
@ -160,6 +162,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
@Bean @Bean
public AbstractSubscribableChannel clientOutboundChannel() { public AbstractSubscribableChannel clientOutboundChannel() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor()); ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor());
channel.setLogger(SimpLogging.forLog(channel.getLogger()));
ChannelRegistration reg = getClientOutboundChannelRegistration(); ChannelRegistration reg = getClientOutboundChannelRegistration();
if (reg.hasInterceptors()) { if (reg.hasInterceptors()) {
channel.setInterceptors(reg.getInterceptors()); channel.setInterceptors(reg.getInterceptors());
@ -198,6 +201,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
ExecutorSubscribableChannel channel = (reg.hasTaskExecutor() ? ExecutorSubscribableChannel channel = (reg.hasTaskExecutor() ?
new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel()); new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel());
reg.interceptors(new ImmutableMessageChannelInterceptor()); reg.interceptors(new ImmutableMessageChannelInterceptor());
channel.setLogger(SimpLogging.forLog(channel.getLogger()));
channel.setInterceptors(reg.getInterceptors()); channel.setInterceptors(reg.getInterceptors());
return channel; return channel;
} }

4
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java

@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -38,6 +37,7 @@ import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.converter.SimpleMessageConverter; import org.springframework.messaging.converter.SimpleMessageConverter;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.messaging.tcp.TcpConnection; import org.springframework.messaging.tcp.TcpConnection;
@ -58,7 +58,7 @@ import org.springframework.util.concurrent.SettableListenableFuture;
*/ */
public class DefaultStompSession implements ConnectionHandlingStompSession { public class DefaultStompSession implements ConnectionHandlingStompSession {
private static final Log logger = LogFactory.getLog(DefaultStompSession.class); private static final Log logger = SimpLogging.forLogName(DefaultStompSession.class);
private static final IdGenerator idGenerator = new AlternativeJdkIdGenerator(); private static final IdGenerator idGenerator = new AlternativeJdkIdGenerator();

11
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java

@ -17,6 +17,7 @@
package org.springframework.messaging.simp.stomp; package org.springframework.messaging.simp.stomp;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.tcp.TcpOperations; import org.springframework.messaging.tcp.TcpOperations;
import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient; import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -46,7 +47,7 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
* @param port the port * @param port the port
*/ */
public ReactorNettyTcpStompClient(String host, int port) { public ReactorNettyTcpStompClient(String host, int port) {
this.tcpClient = new ReactorNettyTcpClient<>(host, port, new StompReactorNettyCodec()); this.tcpClient = initTcpClient(host, port);
} }
/** /**
@ -58,6 +59,13 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
this.tcpClient = tcpClient; this.tcpClient = tcpClient;
} }
private static ReactorNettyTcpClient<byte[]> initTcpClient(String host, int port) {
ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(host, port, new StompReactorNettyCodec());
client.setLogger(SimpLogging.forLog(client.getLogger()));
return client;
}
/** /**
* Connect and notify the given {@link StompSessionHandler} when connected * Connect and notify the given {@link StompSessionHandler} when connected
* on the STOMP level. * on the STOMP level.
@ -68,7 +76,6 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
return connect(null, handler); return connect(null, handler);
} }
/** /**
* An overloaded version of {@link #connect(StompSessionHandler)} that * An overloaded version of {@link #connect(StompSessionHandler)} that
* accepts headers to use for the STOMP CONNECT frame. * accepts headers to use for the STOMP CONNECT frame.

19
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java

@ -32,6 +32,7 @@ import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
@ -397,12 +398,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
@Override @Override
protected void startInternal() { protected void startInternal() {
if (this.tcpClient == null) { if (this.tcpClient == null) {
StompDecoder decoder = new StompDecoder(); this.tcpClient = initTcpClient();
if (this.headerInitializer != null) {
decoder.setHeaderInitializer(this.headerInitializer);
}
ReactorNettyCodec<byte[]> codec = new StompReactorNettyCodec(decoder);
this.tcpClient = new ReactorNettyTcpClient<>(this.relayHost, this.relayPort, codec);
} }
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
@ -430,6 +426,17 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
this.tcpClient.connect(handler, new FixedIntervalReconnectStrategy(5000)); this.tcpClient.connect(handler, new FixedIntervalReconnectStrategy(5000));
} }
private ReactorNettyTcpClient<byte[]> initTcpClient() {
StompDecoder decoder = new StompDecoder();
if (this.headerInitializer != null) {
decoder.setHeaderInitializer(this.headerInitializer);
}
ReactorNettyCodec<byte[]> codec = new StompReactorNettyCodec(decoder);
ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(this.relayHost, this.relayPort, codec);
client.setLogger(SimpLogging.forLog(client.getLogger()));
return client;
}
@Override @Override
protected void stopInternal() { protected void stopInternal() {
publishBrokerUnavailableEvent(); publishBrokerUnavailableEvent();

4
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

@ -24,10 +24,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.MessageHeaderInitializer; import org.springframework.messaging.support.MessageHeaderInitializer;
import org.springframework.messaging.support.NativeMessageHeaderAccessor; import org.springframework.messaging.support.NativeMessageHeaderAccessor;
@ -51,7 +51,7 @@ public class StompDecoder {
static final byte[] HEARTBEAT_PAYLOAD = new byte[] {'\n'}; static final byte[] HEARTBEAT_PAYLOAD = new byte[] {'\n'};
private static final Log logger = LogFactory.getLog(StompDecoder.class); private static final Log logger = SimpLogging.forLogName(StompDecoder.class);
@Nullable @Nullable
private MessageHeaderInitializer headerInitializer; private MessageHeaderInitializer headerInitializer;

4
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

@ -28,10 +28,10 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.NativeMessageHeaderAccessor; import org.springframework.messaging.support.NativeMessageHeaderAccessor;
@ -51,7 +51,7 @@ public class StompEncoder {
private static final byte COLON = ':'; private static final byte COLON = ':';
private static final Log logger = LogFactory.getLog(StompEncoder.class); private static final Log logger = SimpLogging.forLogName(StompEncoder.class);
private static final int HEADER_KEY_CACHE_LIMIT = 32; private static final int HEADER_KEY_CACHE_LIMIT = 32;

4
spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java

@ -22,11 +22,11 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -52,7 +52,7 @@ import org.springframework.util.StringUtils;
*/ */
public class DefaultUserDestinationResolver implements UserDestinationResolver { public class DefaultUserDestinationResolver implements UserDestinationResolver {
private static final Log logger = LogFactory.getLog(DefaultUserDestinationResolver.class); private static final Log logger = SimpLogging.forLogName(DefaultUserDestinationResolver.class);
private final SimpUserRegistry userRegistry; private final SimpUserRegistry userRegistry;

4
spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java

@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -30,6 +29,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException; import org.springframework.messaging.MessagingException;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.messaging.core.MessageSendingOperations;
import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.SimpMessagingTemplate;
@ -50,7 +50,7 @@ import org.springframework.util.StringUtils;
*/ */
public class UserDestinationMessageHandler implements MessageHandler, SmartLifecycle { public class UserDestinationMessageHandler implements MessageHandler, SmartLifecycle {
private static final Log logger = LogFactory.getLog(UserDestinationMessageHandler.class); private static final Log logger = SimpLogging.forLogName(UserDestinationMessageHandler.class);
private final SubscribableChannel clientInboundChannel; private final SubscribableChannel clientInboundChannel;

19
spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java

@ -40,7 +40,7 @@ import org.springframework.util.ObjectUtils;
*/ */
public abstract class AbstractMessageChannel implements MessageChannel, InterceptableChannel, BeanNameAware { public abstract class AbstractMessageChannel implements MessageChannel, InterceptableChannel, BeanNameAware {
protected final Log logger = LogFactory.getLog(getClass()); protected Log logger = LogFactory.getLog(getClass());
private final List<ChannelInterceptor> interceptors = new ArrayList<>(5); private final List<ChannelInterceptor> interceptors = new ArrayList<>(5);
@ -52,6 +52,23 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
} }
/**
* Set an alternative logger to use than the one based on the class name.
* @param logger the logger to use
* @since 5.1
*/
public void setLogger(Log logger) {
this.logger = logger;
}
/**
* Return the currently configured Logger.
* @since 5.1
*/
public Log getLogger() {
return logger;
}
/** /**
* A message channel uses the bean name primarily for logging purposes. * A message channel uses the bean name primarily for logging purposes.
*/ */

22
spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

@ -67,10 +67,10 @@ import org.springframework.util.concurrent.SettableListenableFuture;
*/ */
public class ReactorNettyTcpClient<P> implements TcpOperations<P> { public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
private static Log logger = LogFactory.getLog(ReactorNettyTcpClient.class);
private static final int PUBLISH_ON_BUFFER_SIZE = 16; private static final int PUBLISH_ON_BUFFER_SIZE = 16;
private Log logger = LogFactory.getLog(ReactorNettyTcpClient.class);
private final TcpClient tcpClient; private final TcpClient tcpClient;
@ -138,6 +138,24 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
} }
/**
* Set an alternative logger to use than the one based on the class name.
* @param logger the logger to use
* @since 5.1
*/
public void setLogger(Log logger) {
this.logger = logger;
}
/**
* Return the currently configured Logger.
* @since 5.1
*/
public Log getLogger() {
return logger;
}
@Override @Override
public ListenableFuture<Void> connect(final TcpConnectionHandler<P> handler) { public ListenableFuture<Void> connect(final TcpConnectionHandler<P> handler) {
Assert.notNull(handler, "TcpConnectionHandler is required"); Assert.notNull(handler, "TcpConnectionHandler is required");

Loading…
Cancel
Save