Skip to content

Commit

Permalink
Remove deprecated constructors in WebSocket config
Browse files Browse the repository at this point in the history
In preparation for SPR-16189.
  • Loading branch information
rstoyanchev committed Jul 11, 2018
1 parent c2fbd9f commit 6aa6d91
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,23 +57,6 @@ public abstract class AbstractWebSocketHandlerRegistration<M> 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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -41,22 +40,6 @@ public class ServletWebSocketHandlerRegistration
extends AbstractWebSocketHandlerRegistration<MultiValueMap<HttpRequestHandler, String>> {


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<HttpRequestHandler, String> createMappings() {
return new LinkedMultiValueMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -43,9 +43,6 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry

private final List<ServletWebSocketHandlerRegistration> registrations = new ArrayList<>(4);

@Nullable
private TaskScheduler scheduler;

private int order = 1;

@Nullable
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String, Object> urlMap = new LinkedHashMap<>();
for (ServletWebSocketHandlerRegistration registration : this.registrations) {
updateTaskScheduler(registration);
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
mappings.forEach((httpHandler, patterns) -> {
for (String pattern : patterns) {
Expand All @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6aa6d91

Please sign in to comment.