diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java index b985f7504517..c9ff255498c7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java @@ -21,7 +21,6 @@ import java.util.List; import org.springframework.lang.Nullable; -import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -58,23 +57,6 @@ public abstract class AbstractWebSocketHandlerRegistration implements WebSock @Nullable private SockJsServiceRegistration sockJsServiceRegistration; - @Nullable - private TaskScheduler scheduler; - - - public AbstractWebSocketHandlerRegistration() { - } - - /** - * Deprecated constructor with a TaskScheduler. - * @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until - * it is obvious that it is needed, see {@link #getSockJsServiceRegistration()}. - */ - @Deprecated - public AbstractWebSocketHandlerRegistration(TaskScheduler defaultTaskScheduler) { - this.scheduler = defaultTaskScheduler; - } - @Override public WebSocketHandlerRegistration addHandler(WebSocketHandler handler, String... paths) { @@ -115,9 +97,6 @@ public WebSocketHandlerRegistration setAllowedOrigins(String... allowedOrigins) @Override public SockJsServiceRegistration withSockJS() { this.sockJsServiceRegistration = new SockJsServiceRegistration(); - if (this.scheduler != null) { - this.sockJsServiceRegistration.setTaskScheduler(this.scheduler); - } HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.sockJsServiceRegistration.setInterceptors(interceptors); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java index 00a46a5644e7..f4f5fbca1626 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.java @@ -30,7 +30,7 @@ * * @author Rossen Stoyanchev * @since 4.0.1 - * @deprecated in favor of simply using {@link WebSocketMessageBrokerConfigurer} + * @deprecated as of 5.0 in favor of simply using {@link WebSocketMessageBrokerConfigurer} * which has default methods, made possible by a Java 8 baseline. */ @Deprecated diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java index b21934b43b3b..66c011a5cd1b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * 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. @@ -18,7 +18,6 @@ import java.util.Arrays; -import org.springframework.scheduling.TaskScheduler; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -41,22 +40,6 @@ public class ServletWebSocketHandlerRegistration extends AbstractWebSocketHandlerRegistration> { - public ServletWebSocketHandlerRegistration() { - } - - /** - * Deprecated constructor with a TaskScheduler for SockJS use. - * - * @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until - * it is obvious that it is needed, see {@link #getSockJsServiceRegistration()}. - */ - @Deprecated - @SuppressWarnings("deprecated") - public ServletWebSocketHandlerRegistration(TaskScheduler scheduler) { - super(scheduler); - } - - @Override protected MultiValueMap createMappings() { return new LinkedMultiValueMap<>(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java index ac5dba662358..0918d8604107 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java @@ -20,10 +20,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.MultiValueMap; import org.springframework.web.HttpRequestHandler; import org.springframework.web.servlet.handler.AbstractHandlerMapping; @@ -33,8 +33,8 @@ import org.springframework.web.util.UrlPathHelper; /** - * A {@link WebSocketHandlerRegistry} that maps {@link WebSocketHandler WebSocketHandlerRegistry} that maps {@link WebSocketHandlers} to URLs for use - * in a Servlet container. + * {@link WebSocketHandlerRegistry} with Spring MVC handler mappings for the + * handshake requests. * * @author Rossen Stoyanchev * @since 4.0 @@ -43,9 +43,6 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry private final List registrations = new ArrayList<>(4); - @Nullable - private TaskScheduler scheduler; - private int order = 1; @Nullable @@ -55,17 +52,6 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry public ServletWebSocketHandlerRegistry() { } - /** - * Deprecated constructor with a TaskScheduler for SockJS use. - * @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until - * it is obvious that it is needed, see {@link #requiresTaskScheduler()} and - * {@link #setTaskScheduler}. - */ - @Deprecated - public ServletWebSocketHandlerRegistry(ThreadPoolTaskScheduler scheduler) { - this.scheduler = scheduler; - } - @Override public WebSocketHandlerRegistration addHandler(WebSocketHandler handler, String... paths) { @@ -114,18 +100,21 @@ protected boolean requiresTaskScheduler() { } /** - * Configure a TaskScheduler for SockJS endpoints. This should be configured - * before calling {@link #getHandlerMapping()} after checking if - * {@link #requiresTaskScheduler()} returns {@code true}. + * Set a TaskScheduler is set on each SockJS registration that hasn't had one + * registered explicitly. This method needs to be invoked prior to calling + * {@link #getHandlerMapping()}. */ protected void setTaskScheduler(TaskScheduler scheduler) { - this.scheduler = scheduler; + this.registrations.stream() + .map(ServletWebSocketHandlerRegistration::getSockJsServiceRegistration) + .filter(Objects::nonNull) + .filter(r -> r.getTaskScheduler() == null) + .forEach(r -> r.setTaskScheduler(scheduler)); } public AbstractHandlerMapping getHandlerMapping() { Map urlMap = new LinkedHashMap<>(); for (ServletWebSocketHandlerRegistration registration : this.registrations) { - updateTaskScheduler(registration); MultiValueMap mappings = registration.getMappings(); mappings.forEach((httpHandler, patterns) -> { for (String pattern : patterns) { @@ -142,11 +131,4 @@ public AbstractHandlerMapping getHandlerMapping() { return hm; } - private void updateTaskScheduler(ServletWebSocketHandlerRegistration registration) { - SockJsServiceRegistration sockJsRegistration = registration.getSockJsServiceRegistration(); - if (sockJsRegistration != null && this.scheduler != null && sockJsRegistration.getTaskScheduler() == null) { - sockJsRegistration.setTaskScheduler(this.scheduler); - } - } - } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java index 7296c041e3cd..78691aae4116 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java @@ -83,18 +83,6 @@ public class SockJsServiceRegistration { public SockJsServiceRegistration() { } - /** - * Deprecated constructor with a TaskScheduler. - * @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until - * it is obvious that it is needed; call {@link #getTaskScheduler()} to check - * and then {@link #setTaskScheduler(TaskScheduler)} to set it before a call - * to {@link #createSockJsService()} - */ - @Deprecated - public SockJsServiceRegistration(TaskScheduler defaultTaskScheduler) { - this.scheduler = defaultTaskScheduler; - } - /** * A scheduler instance to use for scheduling SockJS heart-beats.