Skip to content

Commit

Permalink
Mark ListenableFuture as deprecated for removal
Browse files Browse the repository at this point in the history
Closes gh-33808
  • Loading branch information
jhoeller committed Oct 29, 2024
1 parent c2c6bb2 commit 9e3371e
Show file tree
Hide file tree
Showing 53 changed files with 209 additions and 218 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 Down Expand Up @@ -281,8 +281,8 @@ protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
* @param returnType the declared return type (potentially a {@link Future} variant)
* @return the execution result (potentially a corresponding {@link Future} handle)
*/
@SuppressWarnings("removal")
@Nullable
@SuppressWarnings("deprecation")
protected Object doSubmit(Callable<Object> task, AsyncTaskExecutor executor, Class<?> returnType) {
if (CompletableFuture.class.isAssignableFrom(returnType)) {
return executor.submitCompletable(task);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 Down Expand Up @@ -47,7 +47,7 @@
* @see org.springframework.core.task.TaskExecutor
* @see SchedulerFactoryBean#setTaskExecutor
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class SimpleThreadPoolTaskExecutor extends SimpleThreadPool
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, InitializingBean, DisposableBean {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected Object[] resolveArguments(ApplicationEvent event) {
return new Object[] {event};
}

@SuppressWarnings({"deprecation", "unchecked"})
@SuppressWarnings({"removal", "unchecked"})
protected void handleResult(Object result) {
if (reactiveStreamsPresent && new ReactiveResultHandler().subscribeToPublisher(result)) {
if (logger.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 Down Expand Up @@ -31,12 +31,10 @@
* A pass-through {@code Future} handle that can be used for method signatures
* which are declared with a {@code Future} return type for asynchronous execution.
*
* <p>As of Spring 4.1, this class implements {@link ListenableFuture}, not just
* <p>As of Spring 4.1, this class implements {@code ListenableFuture}, not just
* plain {@link java.util.concurrent.Future}, along with the corresponding support
* in {@code @Async} processing.
*
* <p>As of Spring 4.2, this class also supports passing execution exceptions back
* to the caller.
* in {@code @Async} processing. As of 7.0, this will be turned back to a plain
* {@code Future} in order to focus on compatibility with existing common usage.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
Expand All @@ -48,6 +46,7 @@
* @deprecated as of 6.0, in favor of {@link CompletableFuture}
*/
@Deprecated(since = "6.0")
@SuppressWarnings("removal")
public class AsyncResult<V> implements ListenableFuture<V> {

@Nullable
Expand Down Expand Up @@ -145,7 +144,7 @@ public CompletableFuture<V> completable() {
* @since 4.2
* @see Future#get()
*/
public static <V> ListenableFuture<V> forValue(V value) {
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forValue(V value) {
return new AsyncResult<>(value, null);
}

Expand All @@ -157,7 +156,7 @@ public static <V> ListenableFuture<V> forValue(V value) {
* @since 4.2
* @see ExecutionException
*/
public static <V> ListenableFuture<V> forExecutionException(Throwable ex) {
public static <V> org.springframework.util.concurrent.ListenableFuture<V> forExecutionException(Throwable ex) {
return new AsyncResult<>(null, ex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* @see DefaultManagedTaskExecutor
* @see ThreadPoolTaskExecutor
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {

private static final Executor STUB_EXECUTOR = (task -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ErrorHandler;
import org.springframework.util.concurrent.ListenableFuture;

/**
* Adapter that takes a {@code java.util.concurrent.ScheduledExecutorService} and
Expand Down Expand Up @@ -219,15 +218,15 @@ public <T> Future<T> submit(Callable<T> task) {
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
}

@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
import org.springframework.util.concurrent.ListenableFuture;

/**
* A simple implementation of Spring's {@link TaskScheduler} interface, using
Expand Down Expand Up @@ -270,15 +269,15 @@ public <T> Future<T> submit(Callable<T> task) {
return super.submit(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
public org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task) {
return super.submitListenable(TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, false));
}

@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
@Override
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task) {
return super.submitListenable(new DelegatingErrorHandlingCallable<>(task, this.errorHandler));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* @see ThreadPoolExecutorFactoryBean
* @see ConcurrentTaskExecutor
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* @see ThreadPoolTaskExecutor
* @see SimpleAsyncTaskScheduler
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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 @@ -16,6 +16,7 @@

package example.scannable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import jakarta.annotation.PostConstruct;
Expand Down Expand Up @@ -51,9 +52,8 @@ public String foo(int id) {
}

@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
return new org.springframework.scheduling.annotation.AsyncResult<>(this.fooDao.findFoo(id));
return CompletableFuture.completedFuture(this.fooDao.findFoo(id));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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,6 +18,7 @@

import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import jakarta.annotation.PostConstruct;
Expand Down Expand Up @@ -91,10 +92,9 @@ public String lookupFoo(int id) {
}

@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
Assert.state(ServiceInvocationCounter.getThreadLocalCount() != null, "Thread-local counter not exposed");
return new org.springframework.scheduling.annotation.AsyncResult<>(fooDao().findFoo(id));
return CompletableFuture.completedFuture(fooDao().findFoo(id));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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 @@ -16,6 +16,7 @@

package example.scannable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import org.springframework.context.annotation.Scope;
Expand All @@ -33,9 +34,8 @@ public String foo(int id) {
}

@Override
@SuppressWarnings("deprecation")
public Future<String> asyncFoo(int id) {
return new org.springframework.scheduling.annotation.AsyncResult<>("bar");
return CompletableFuture.completedFuture("bar");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void collectionReplyNullValue() {
}

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
void listenableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
org.springframework.util.concurrent.SettableListenableFuture<String> future =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class AsyncResultTests {

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithCallbackAndValue() throws Exception {
String value = "val";
final Set<String> values = new HashSet<>(1);
Expand All @@ -54,7 +54,7 @@ public void onFailure(Throwable ex) {
}

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithCallbackAndException() {
IOException ex = new IOException();
final Set<Throwable> values = new HashSet<>(1);
Expand All @@ -79,7 +79,7 @@ public void onFailure(Throwable ex) {
}

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
String value = "val";
final Set<String> values = new HashSet<>(1);
Expand All @@ -92,7 +92,7 @@ public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void asyncResultWithSeparateCallbacksAndException() {
IOException ex = new IOException();
final Set<Throwable> values = new HashSet<>(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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,20 +18,18 @@

import java.util.concurrent.Callable;

import org.springframework.util.concurrent.ListenableFuture;

/**
* Extension of the {@link AsyncTaskExecutor} interface, adding the capability to submit
* tasks for {@link ListenableFuture ListenableFutures}.
* tasks for {@code ListenableFutures}.
*
* @author Arjen Poutsma
* @since 4.0
* @see ListenableFuture
* @deprecated as of 6.0, in favor of
* {@link AsyncTaskExecutor#submitCompletable(Runnable)} and
* {@link AsyncTaskExecutor#submitCompletable(Callable)}
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {

/**
Expand All @@ -42,8 +40,8 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
* @throws TaskRejectedException if the given task was not accepted
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Runnable)}
*/
@Deprecated
ListenableFuture<?> submitListenable(Runnable task);
@Deprecated(since = "6.0", forRemoval = true)
org.springframework.util.concurrent.ListenableFuture<?> submitListenable(Runnable task);

/**
* Submit a {@code Callable} task for execution, receiving a {@code ListenableFuture}
Expand All @@ -54,7 +52,7 @@ public interface AsyncListenableTaskExecutor extends AsyncTaskExecutor {
* @throws TaskRejectedException if the given task was not accepted
* @deprecated in favor of {@link AsyncTaskExecutor#submitCompletable(Callable)}
*/
@Deprecated
<T> ListenableFuture<T> submitListenable(Callable<T> task);
@Deprecated(since = "6.0", forRemoval = true)
<T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(Callable<T> task);

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* @see org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler
* @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
*/
@SuppressWarnings({"serial", "deprecation"})
@SuppressWarnings({"serial", "removal"})
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
implements AsyncListenableTaskExecutor, Serializable, AutoCloseable {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 Down Expand Up @@ -43,7 +43,7 @@
* @see java.util.concurrent.ExecutorService
* @see java.util.concurrent.Executors
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class TaskExecutorAdapter implements AsyncListenableTaskExecutor {

private final Executor concurrentExecutor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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 Down Expand Up @@ -32,7 +32,8 @@
* @param <T> the result type returned by this Future's {@code get} method
* @deprecated as of 6.0, with no concrete replacement
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0", forRemoval = true)
@SuppressWarnings("removal")
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {

private final CompletableFuture<T> completableFuture;
Expand Down
Loading

0 comments on commit 9e3371e

Please sign in to comment.