Clean up warnings and polishing

This commit is contained in:
Sam Brannen
2022-07-31 14:14:56 +03:00
parent 9d1e9703ae
commit e4395f2f8b
55 changed files with 412 additions and 396 deletions

View File

@@ -20,13 +20,12 @@ import java.util.concurrent.CompletableFuture;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* An extension of {@link HandlerMethodReturnValueHandler} for handling async,
* Future-like return value types that support success and error callbacks.
* Essentially anything that can be adapted to a {@link ListenableFuture}.
* Essentially anything that can be adapted to a
* {@link org.springframework.util.concurrent.ListenableFuture ListenableFuture}.
*
* <p>Implementations should consider extending the convenient base class
* {@link AbstractAsyncReturnValueHandler}.
@@ -52,8 +51,9 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType);
/**
* Adapt the asynchronous return value to a {@link ListenableFuture}.
* Implementations should consider returning an instance of
* Adapt the asynchronous return value to a
* {@link org.springframework.util.concurrent.ListenableFuture ListenableFuture}.
* <p>Implementations should consider returning an instance of
* {@link org.springframework.util.concurrent.SettableListenableFuture
* SettableListenableFuture}. Return value handling will then continue when
* the ListenableFuture is completed with either success or error.
@@ -69,14 +69,17 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
*/
@Deprecated
@Nullable
default ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType) {
default org.springframework.util.concurrent.ListenableFuture<?> toListenableFuture(
Object returnValue, MethodParameter returnType) {
CompletableFuture<?> result = toCompletableFuture(returnValue, returnType);
return (result != null) ? new CompletableToListenableFutureAdapter<>(result) : null;
return (result != null ?
new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(result) :
null);
}
/**
* Adapt the asynchronous return value to a {@link CompletableFuture}.
* Return value handling will then continue when
* <p>Return value handling will then continue when
* the CompletableFuture is completed with either success or error.
* <p><strong>Note:</strong> this method will only be invoked after
* {@link #supportsReturnType(org.springframework.core.MethodParameter)}

View File

@@ -59,7 +59,6 @@ import org.springframework.messaging.handler.invocation.CompletableFutureReturnV
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite;
import org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler;
import org.springframework.messaging.handler.invocation.ReactiveReturnValueHandler;
import org.springframework.messaging.simp.SimpAttributesContextHolder;
import org.springframework.messaging.simp.SimpLogging;
@@ -326,14 +325,14 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
return resolvers;
}
@SuppressWarnings("deprecation")
@Override
@SuppressWarnings("deprecation")
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
// Single-purpose return value types
handlers.add(new ListenableFutureReturnValueHandler());
handlers.add(new org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler());
handlers.add(new CompletableFutureReturnValueHandler());
if (reactorPresent) {
handlers.add(new ReactiveReturnValueHandler());

View File

@@ -18,9 +18,6 @@ package org.springframework.messaging.simp.stomp;
import java.util.concurrent.CompletableFuture;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* A {@link StompSession} that implements
* {@link org.springframework.messaging.tcp.TcpConnectionHandler
@@ -39,8 +36,9 @@ public interface ConnectionHandlingStompSession extends StompSession, StompTcpCo
* @deprecated as of 6.0, in favor of {@link #getSession()}
*/
@Deprecated
default ListenableFuture<StompSession> getSessionFuture() {
return new CompletableToListenableFutureAdapter<>(getSession());
default org.springframework.util.concurrent.ListenableFuture<StompSession> getSessionFuture() {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
getSession());
}
/**

View File

@@ -23,8 +23,6 @@ import org.springframework.messaging.simp.SimpLogging;
import org.springframework.messaging.tcp.TcpOperations;
import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient;
import org.springframework.util.Assert;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* A STOMP over TCP client that uses {@link ReactorNettyTcpClient}.
@@ -77,15 +75,17 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
* @deprecated as of 6.0, in favor of {@link #connectAsync(StompSessionHandler)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(StompSessionHandler handler) {
return new CompletableToListenableFutureAdapter<>(connectAsync(handler));
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
StompSessionHandler handler) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(handler));
}
/**
* Connect and notify the given {@link StompSessionHandler} when connected
* on the STOMP level.
* @param handler the handler for the STOMP session
* @return a ListenableFuture for access to the session when ready for use
* @return a CompletableFuture for access to the session when ready for use
* @since 6.0
*/
public CompletableFuture<StompSession> connectAsync(StompSessionHandler handler) {
@@ -101,7 +101,8 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
* @deprecated as of 6.0, in favor of {@link #connectAsync(StompHeaders, StompSessionHandler)}
*/
@Deprecated
public ListenableFuture<StompSession> connect(@Nullable StompHeaders connectHeaders, StompSessionHandler handler) {
public org.springframework.util.concurrent.ListenableFuture<StompSession> connect(
@Nullable StompHeaders connectHeaders, StompSessionHandler handler) {
ConnectionHandlingStompSession session = createSession(connectHeaders, handler);
this.tcpClient.connectAsync(session);
return session.getSessionFuture();
@@ -131,4 +132,5 @@ public class ReactorNettyTcpStompClient extends StompClientSupport {
public String toString() {
return "ReactorNettyTcpStompClient[" + this.tcpClient + "]";
}
}

View File

@@ -21,7 +21,6 @@ import java.time.Duration;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@@ -1110,16 +1109,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
}
private static class VoidCallable implements Callable<Void> {
@Override
public Void call() {
return null;
}
}
/**
* Contract for access to session counters.
* @since 5.2

View File

@@ -20,8 +20,6 @@ import java.io.Closeable;
import java.util.concurrent.CompletableFuture;
import org.springframework.messaging.Message;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* A contract for sending messages and managing a TCP connection.
@@ -40,8 +38,9 @@ public interface TcpConnection<P> extends Closeable {
* @deprecated as of 6.0, in favor of {@link #sendAsync(Message)}
*/
@Deprecated
default ListenableFuture<Void> send(Message<P> message) {
return new CompletableToListenableFutureAdapter<>(sendAsync(message));
default org.springframework.util.concurrent.ListenableFuture<Void> send(Message<P> message) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
sendAsync(message));
}
/**

View File

@@ -18,15 +18,12 @@ package org.springframework.messaging.tcp;
import java.util.concurrent.CompletableFuture;
import org.springframework.util.concurrent.CompletableToListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFuture;
/**
* A contract for establishing TCP connections.
*
* @author Rossen Stoyanchev
* @since 4.0
* @param <P> the type of payload for in and outbound messages
* @param <P> the type of payload for inbound and outbound messages
*/
public interface TcpOperations<P> {
@@ -38,8 +35,10 @@ public interface TcpOperations<P> {
* @deprecated as of 6.0, in favor of {@link #connectAsync(TcpConnectionHandler)}
*/
@Deprecated
default ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler) {
return new CompletableToListenableFutureAdapter<>(connectAsync(connectionHandler));
default org.springframework.util.concurrent.ListenableFuture<Void> connect(
TcpConnectionHandler<P> connectionHandler) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(connectionHandler));
}
/**
@@ -60,8 +59,10 @@ public interface TcpOperations<P> {
* @deprecated as of 6.0, in favor of {@link #connectAsync(TcpConnectionHandler, ReconnectStrategy)}
*/
@Deprecated
default ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy reconnectStrategy) {
return new CompletableToListenableFutureAdapter<>(connectAsync(connectionHandler, reconnectStrategy));
default org.springframework.util.concurrent.ListenableFuture<Void> connect(
TcpConnectionHandler<P> connectionHandler, ReconnectStrategy reconnectStrategy) {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
connectAsync(connectionHandler, reconnectStrategy));
}
/**
@@ -81,13 +82,14 @@ public interface TcpOperations<P> {
* @deprecated as of 6.0, in favor of {@link #shutdownAsync()}
*/
@Deprecated
default ListenableFuture<Void> shutdown() {
return new CompletableToListenableFutureAdapter<>(shutdownAsync());
default org.springframework.util.concurrent.ListenableFuture<Void> shutdown() {
return new org.springframework.util.concurrent.CompletableToListenableFutureAdapter<>(
shutdownAsync());
}
/**
* Shut down and close any open connections.
* @return a ListenableFuture that can be used to determine when and if the
* @return a CompletableFuture that can be used to determine when and if the
* connection is successfully closed
* @since 6.0
*/

View File

@@ -61,7 +61,6 @@ import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.concurrent.ListenableFutureTask;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
@@ -538,19 +537,19 @@ public class SimpAnnotationMethodMessageHandlerTests {
@SuppressWarnings("deprecation")
private static class ListenableFutureController {
private ListenableFutureTask<String> future;
private org.springframework.util.concurrent.ListenableFutureTask<String> future;
private boolean exceptionCaught = false;
@MessageMapping("success")
public ListenableFutureTask<String> handleListenableFuture() {
this.future = new ListenableFutureTask<>(() -> "foo");
public org.springframework.util.concurrent.ListenableFutureTask<String> handleListenableFuture() {
this.future = new org.springframework.util.concurrent.ListenableFutureTask<>(() -> "foo");
return this.future;
}
@MessageMapping("failure")
public ListenableFutureTask<String> handleListenableFutureException() {
this.future = new ListenableFutureTask<>(() -> {
public org.springframework.util.concurrent.ListenableFutureTask<String> handleListenableFutureException() {
this.future = new org.springframework.util.concurrent.ListenableFutureTask<>(() -> {
throw new IllegalStateException();
});
return this.future;