diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java index 8f57cbea4e6..5cc7c3911ab 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -52,6 +52,7 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; * * @author Rossen Stoyanchev * @author Sam Brannen + * @author Brian Clozel * @since 4.1 */ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton { @@ -160,25 +161,63 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton { /** * Get stats about WebSocket sessions. + * @deprecated as of 6.2 in favor of {@link #getWebSocketSessionStats()}. */ + @Deprecated(since = "6.2", forRemoval = true) public String getWebSocketSessionStatsInfo() { return (this.webSocketHandler != null ? this.webSocketHandler.getStatsInfo() : "null"); } /** - * Get stats about STOMP-related WebSocket message processing. + * Get stats about WebSocket sessions. + * Can return {@code null} if no {@link #setSubProtocolWebSocketHandler(SubProtocolWebSocketHandler) WebSocket handler} + * is configured. + * @since 6.2 */ + @Nullable + public SubProtocolWebSocketHandler.Stats getWebSocketSessionStats() { + return (this.webSocketHandler != null ? this.webSocketHandler.getStats() : null); + } + + /** + * Get stats about STOMP-related WebSocket message processing. + * @deprecated as of 6.2 in favor of {@link #getStompSubProtocolStats()}. + */ + @Deprecated(since = "6.2", forRemoval = true) public String getStompSubProtocolStatsInfo() { return (this.stompSubProtocolHandler != null ? this.stompSubProtocolHandler.getStatsInfo() : "null"); } /** - * Get stats about STOMP broker relay (when using a full-featured STOMP broker). + * Get stats about STOMP-related WebSocket message processing. + * Can return {@code null} if no {@link SubProtocolHandler} was found. + * @since 6.2 */ + @Nullable + public StompSubProtocolHandler.Stats getStompSubProtocolStats() { + return (this.stompSubProtocolHandler != null ? this.stompSubProtocolHandler.getStats() : null); + } + + /** + * Get stats about STOMP broker relay (when using a full-featured STOMP broker). + * @deprecated as of 6.2 in favor of {@link #getStompBrokerRelayStats()}. + */ + @Deprecated(since = "6.2", forRemoval = true) public String getStompBrokerRelayStatsInfo() { return (this.stompBrokerRelay != null ? this.stompBrokerRelay.getStatsInfo() : "null"); } + /** + * Get stats about STOMP broker relay (when using a full-featured STOMP broker). + * Can return {@code null} if no {@link #setStompBrokerRelay(StompBrokerRelayMessageHandler) STOMP broker relay} + * is configured. + * @since 6.2 + */ + @Nullable + public StompBrokerRelayMessageHandler.Stats getStompBrokerRelayStats() { + return (this.stompBrokerRelay != null ? this.stompBrokerRelay.getStats() : null); + } + /** * Get stats about the executor processing incoming messages from WebSocket clients. */ @@ -231,6 +270,7 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton { } @Override + @SuppressWarnings("removal") public String toString() { return "WebSocketSession[" + getWebSocketSessionStatsInfo() + "]" + ", stompSubProtocol[" + getStompSubProtocolStatsInfo() + "]" +