Skip to content

Commit

Permalink
Refine executor description in WebSocketMessageBrokerStats
Browse files Browse the repository at this point in the history
Closes gh-33104
  • Loading branch information
rstoyanchev committed Jul 12, 2024
1 parent bd31e8d commit 007a347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -239,9 +240,15 @@ public String getSockJsTaskSchedulerStatsInfo() {
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";
}

Expand All @@ -250,8 +257,12 @@ private String getExecutorStatsInfo(@Nullable Executor executor) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void inboundAndOutboundChannelsWithMockedTaskExecutor() {
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
Expand All @@ -86,7 +86,7 @@ void sockJsTaskSchedulerWithMockedTaskScheduler() {

stats.setSockJsTaskScheduler(scheduler);

assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("unknown");
assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("thread-per-task");
}

}

0 comments on commit 007a347

Please sign in to comment.