Browse Source

Refine executor description in WebSocketMessageBrokerStats

Closes gh-33104
pull/33213/head
rstoyanchev 1 year ago
parent
commit
007a347ade
  1. 19
      spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java
  2. 6
      spring-websocket/src/test/java/org/springframework/web/socket/config/WebSocketMessageBrokerStatsTests.java

19
spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java

@ -30,6 +30,7 @@ import org.springframework.beans.factory.SmartInitializingSingleton; @@ -30,6 +30,7 @@ import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.core.task.TaskExecutor;
import org.springframework.lang.Nullable;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.scheduling.SchedulingTaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@ -239,9 +240,15 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton { @@ -239,9 +240,15 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton {
if (this.sockJsTaskScheduler == null) {
return "null";
}
if (this.sockJsTaskScheduler instanceof ThreadPoolTaskScheduler threadPoolTaskScheduler) {
return getExecutorStatsInfo(threadPoolTaskScheduler.getScheduledThreadPoolExecutor());
if (!(this.sockJsTaskScheduler instanceof SchedulingTaskExecutor)) {
return "thread-per-task";
}
if (this.sockJsTaskScheduler instanceof ThreadPoolTaskScheduler tpts) {
return getExecutorStatsInfo(tpts.getScheduledThreadPoolExecutor());
}
return "unknown";
}
@ -250,8 +257,12 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton { @@ -250,8 +257,12 @@ public class WebSocketMessageBrokerStats implements SmartInitializingSingleton {
return "null";
}
if (executor instanceof ThreadPoolTaskExecutor threadPoolTaskScheduler) {
executor = threadPoolTaskScheduler.getThreadPoolExecutor();
if (!(executor instanceof SchedulingTaskExecutor) && (executor instanceof TaskExecutor)) {
return "thread-per-task";
}
if (executor instanceof ThreadPoolTaskExecutor tpte) {
executor = tpte.getThreadPoolExecutor();
}
if (executor instanceof ThreadPoolExecutor) {

6
spring-websocket/src/test/java/org/springframework/web/socket/config/WebSocketMessageBrokerStatsTests.java

@ -65,8 +65,8 @@ class WebSocketMessageBrokerStatsTests { @@ -65,8 +65,8 @@ class WebSocketMessageBrokerStatsTests {
stats.setInboundChannelExecutor(executor);
stats.setOutboundChannelExecutor(executor);
assertThat(stats.getClientInboundExecutorStatsInfo()).as("inbound channel stats").isEqualTo("unknown");
assertThat(stats.getClientOutboundExecutorStatsInfo()).as("outbound channel stats").isEqualTo("unknown");
assertThat(stats.getClientInboundExecutorStatsInfo()).as("inbound channel stats").isEqualTo("thread-per-task");
assertThat(stats.getClientOutboundExecutorStatsInfo()).as("outbound channel stats").isEqualTo("thread-per-task");
}
@Test
@ -86,7 +86,7 @@ class WebSocketMessageBrokerStatsTests { @@ -86,7 +86,7 @@ class WebSocketMessageBrokerStatsTests {
stats.setSockJsTaskScheduler(scheduler);
assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("unknown");
assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("thread-per-task");
}
}

Loading…
Cancel
Save