WebSocketMessageBrokerStats implements SmartInitializingSingleton
Closes gh-26536
This commit is contained in:
parent
e6ab8a6d61
commit
8ffbecc7c3
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
||||
|
|
@ -53,7 +54,7 @@ import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
|||
* @author Sam Brannen
|
||||
* @since 4.1
|
||||
*/
|
||||
public class WebSocketMessageBrokerStats {
|
||||
public class WebSocketMessageBrokerStats implements SmartInitializingSingleton {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebSocketMessageBrokerStats.class);
|
||||
|
||||
|
|
@ -84,7 +85,49 @@ public class WebSocketMessageBrokerStats {
|
|||
|
||||
public void setSubProtocolWebSocketHandler(SubProtocolWebSocketHandler webSocketHandler) {
|
||||
this.webSocketHandler = webSocketHandler;
|
||||
}
|
||||
|
||||
public void setStompBrokerRelay(StompBrokerRelayMessageHandler stompBrokerRelay) {
|
||||
this.stompBrokerRelay = stompBrokerRelay;
|
||||
}
|
||||
|
||||
public void setInboundChannelExecutor(TaskExecutor inboundChannelExecutor) {
|
||||
this.inboundChannelExecutor = inboundChannelExecutor;
|
||||
}
|
||||
|
||||
public void setOutboundChannelExecutor(TaskExecutor outboundChannelExecutor) {
|
||||
this.outboundChannelExecutor = outboundChannelExecutor;
|
||||
}
|
||||
|
||||
public void setSockJsTaskScheduler(TaskScheduler sockJsTaskScheduler) {
|
||||
this.sockJsTaskScheduler = sockJsTaskScheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frequency for logging information at INFO level in milliseconds.
|
||||
* If set 0 or less than 0, the logging task is cancelled.
|
||||
* <p>By default this property is set to 30 minutes (30 * 60 * 1000).
|
||||
*/
|
||||
public void setLoggingPeriod(long period) {
|
||||
this.loggingPeriod = period;
|
||||
if (this.loggingTask != null) {
|
||||
this.loggingTask.cancel(true);
|
||||
this.loggingTask = initLoggingTask(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured logging period frequency in milliseconds.
|
||||
*/
|
||||
public long getLoggingPeriod() {
|
||||
return this.loggingPeriod;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
this.stompSubProtocolHandler = initStompSubProtocolHandler();
|
||||
this.loggingTask = initLoggingTask(TimeUnit.MINUTES.toMillis(1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -104,23 +147,6 @@ public class WebSocketMessageBrokerStats {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void setStompBrokerRelay(StompBrokerRelayMessageHandler stompBrokerRelay) {
|
||||
this.stompBrokerRelay = stompBrokerRelay;
|
||||
}
|
||||
|
||||
public void setInboundChannelExecutor(TaskExecutor inboundChannelExecutor) {
|
||||
this.inboundChannelExecutor = inboundChannelExecutor;
|
||||
}
|
||||
|
||||
public void setOutboundChannelExecutor(TaskExecutor outboundChannelExecutor) {
|
||||
this.outboundChannelExecutor = outboundChannelExecutor;
|
||||
}
|
||||
|
||||
public void setSockJsTaskScheduler(TaskScheduler sockJsTaskScheduler) {
|
||||
this.sockJsTaskScheduler = sockJsTaskScheduler;
|
||||
this.loggingTask = initLoggingTask(TimeUnit.MINUTES.toMillis(1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ScheduledFuture<?> initLoggingTask(long initialDelay) {
|
||||
if (this.sockJsTaskScheduler != null && this.loggingPeriod > 0 && logger.isInfoEnabled()) {
|
||||
|
|
@ -131,25 +157,6 @@ public class WebSocketMessageBrokerStats {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frequency for logging information at INFO level in milliseconds.
|
||||
* If set 0 or less than 0, the logging task is cancelled.
|
||||
* <p>By default this property is set to 30 minutes (30 * 60 * 1000).
|
||||
*/
|
||||
public void setLoggingPeriod(long period) {
|
||||
if (this.loggingTask != null) {
|
||||
this.loggingTask.cancel(true);
|
||||
}
|
||||
this.loggingPeriod = period;
|
||||
this.loggingTask = initLoggingTask(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured logging period frequency in milliseconds.
|
||||
*/
|
||||
public long getLoggingPeriod() {
|
||||
return this.loggingPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stats about WebSocket sessions.
|
||||
|
|
|
|||
Loading…
Reference in New Issue