Skip to content

Commit 87d87f5

Browse files
cpovirkronshapiro
authored andcommitted
Remove Futures methods that implicitly use directExecutor().
RELNOTES=Removed the `Futures` methods that implicitly use `directExecutor()`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=205408078
1 parent 148688a commit 87d87f5

File tree

2 files changed

+0
-594
lines changed

2 files changed

+0
-594
lines changed

android/guava/src/com/google/common/util/concurrent/Futures.java

Lines changed: 0 additions & 297 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulCheckedFuture;
3434
import com.google.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulFuture;
3535
import com.google.errorprone.annotations.CanIgnoreReturnValue;
36-
import com.google.errorprone.annotations.DoNotCall;
3736
import java.util.Collection;
3837
import java.util.List;
3938
import java.util.concurrent.Callable;
@@ -280,58 +279,6 @@ public void run() {
280279
return task;
281280
}
282281

283-
/**
284-
* Returns a {@code Future} whose result is taken from the given primary {@code input} or, if the
285-
* primary input fails with the given {@code exceptionType}, from the result provided by the
286-
* {@code fallback}. {@link Function#apply} is not invoked until the primary input has failed, so
287-
* if the primary input succeeds, it is never invoked. If, during the invocation of {@code
288-
* fallback}, an exception is thrown, this exception is used as the result of the output {@code
289-
* Future}.
290-
*
291-
* <p>Usage example:
292-
*
293-
* <pre>{@code
294-
* ListenableFuture<Integer> fetchCounterFuture = ...;
295-
*
296-
* // Falling back to a zero counter in case an exception happens when
297-
* // processing the RPC to fetch counters.
298-
* ListenableFuture<Integer> faultTolerantFuture = Futures.catching(
299-
* fetchCounterFuture, FetchException.class, x -> 0);
300-
* }</pre>
301-
*
302-
* <p>This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous
303-
* choice in some cases. See the discussion in the {@link ListenableFuture#addListener
304-
* ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are
305-
* also applicable to heavyweight functions passed to this method.
306-
*
307-
* @param input the primary input {@code Future}
308-
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception
309-
* type is matched against the input's exception. "The input's exception" means the cause of
310-
* the {@link ExecutionException} thrown by {@code input.get()} or, if {@code get()} throws a
311-
* different kind of exception, that exception itself. To avoid hiding bugs and other
312-
* unrecoverable errors, callers should prefer more specific types, avoiding {@code
313-
* Throwable.class} in particular.
314-
* @param fallback the {@link Function} to be called if {@code input} fails with the expected
315-
* exception type. The function's argument is the input's exception. "The input's exception"
316-
* means the cause of the {@link ExecutionException} thrown by {@code input.get()} or, if
317-
* {@code get()} throws a different kind of exception, that exception itself.
318-
* @since 19.0
319-
* @deprecated Use {@linkplain #catching(ListenableFuture, Class, Function, Executor) the overload
320-
* that requires an executor}. For identical behavior, pass {@link
321-
* MoreExecutors#directExecutor}, but consider whether another executor would be safer, as
322-
* discussed in the {@link ListenableFuture#addListener ListenableFuture.addListener}
323-
* documentation. This method is scheduled to be removed in July 2018.
324-
*/
325-
@Deprecated
326-
@DoNotCall
327-
@Partially.GwtIncompatible("AVAILABLE but requires exceptionType to be Throwable.class")
328-
public static <V, X extends Throwable> ListenableFuture<V> catching(
329-
ListenableFuture<? extends V> input,
330-
Class<X> exceptionType,
331-
Function<? super X, ? extends V> fallback) {
332-
return AbstractCatchingFuture.create(input, exceptionType, fallback, directExecutor());
333-
}
334-
335282
/**
336283
* Returns a {@code Future} whose result is taken from the given primary {@code input} or, if the
337284
* primary input fails with the given {@code exceptionType}, from the result provided by the
@@ -379,80 +326,6 @@ public static <V, X extends Throwable> ListenableFuture<V> catching(
379326
return AbstractCatchingFuture.create(input, exceptionType, fallback, executor);
380327
}
381328

382-
/**
383-
* Returns a {@code Future} whose result is taken from the given primary {@code input} or, if the
384-
* primary input fails with the given {@code exceptionType}, from the result provided by the
385-
* {@code fallback}. {@link AsyncFunction#apply} is not invoked until the primary input has
386-
* failed, so if the primary input succeeds, it is never invoked. If, during the invocation of
387-
* {@code fallback}, an exception is thrown, this exception is used as the result of the output
388-
* {@code Future}.
389-
*
390-
* <p>Usage examples:
391-
*
392-
* <pre>{@code
393-
* ListenableFuture<Integer> fetchCounterFuture = ...;
394-
*
395-
* // Falling back to a zero counter in case an exception happens when
396-
* // processing the RPC to fetch counters.
397-
* ListenableFuture<Integer> faultTolerantFuture = Futures.catchingAsync(
398-
* fetchCounterFuture, FetchException.class, x -> immediateFuture(0));
399-
* }</pre>
400-
*
401-
* <p>The fallback can also choose to propagate the original exception when desired:
402-
*
403-
* <pre>{@code
404-
* ListenableFuture<Integer> fetchCounterFuture = ...;
405-
*
406-
* // Falling back to a zero counter only in case the exception was a
407-
* // TimeoutException.
408-
* ListenableFuture<Integer> faultTolerantFuture = Futures.catchingAsync(
409-
* fetchCounterFuture,
410-
* FetchException.class,
411-
* e -> {
412-
* if (omitDataOnFetchFailure) {
413-
* return immediateFuture(0);
414-
* }
415-
* throw e;
416-
* });
417-
* }</pre>
418-
*
419-
* <p>This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous
420-
* choice in some cases. See the discussion in the {@link ListenableFuture#addListener
421-
* ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are
422-
* also applicable to heavyweight functions passed to this method. (Specifically, {@code
423-
* directExecutor} functions should avoid heavyweight operations inside {@code
424-
* AsyncFunction.apply}. Any heavyweight operations should occur in other threads responsible for
425-
* completing the returned {@code Future}.)
426-
*
427-
* @param input the primary input {@code Future}
428-
* @param exceptionType the exception type that triggers use of {@code fallback}. The exception
429-
* type is matched against the input's exception. "The input's exception" means the cause of
430-
* the {@link ExecutionException} thrown by {@code input.get()} or, if {@code get()} throws a
431-
* different kind of exception, that exception itself. To avoid hiding bugs and other
432-
* unrecoverable errors, callers should prefer more specific types, avoiding {@code
433-
* Throwable.class} in particular.
434-
* @param fallback the {@link AsyncFunction} to be called if {@code input} fails with the expected
435-
* exception type. The function's argument is the input's exception. "The input's exception"
436-
* means the cause of the {@link ExecutionException} thrown by {@code input.get()} or, if
437-
* {@code get()} throws a different kind of exception, that exception itself.
438-
* @since 19.0 (similar functionality in 14.0 as {@code withFallback})
439-
* @deprecated Use {@linkplain #catchingAsync(ListenableFuture, Class, AsyncFunction, Executor)
440-
* the overload that requires an executor}. For identical behavior, pass {@link
441-
* MoreExecutors#directExecutor}, but consider whether another executor would be safer, as
442-
* discussed in the {@link ListenableFuture#addListener ListenableFuture.addListener}
443-
* documentation. This method is scheduled to be removed in July 2018.
444-
*/
445-
@CanIgnoreReturnValue // TODO(kak): @CheckReturnValue
446-
@Deprecated
447-
@DoNotCall
448-
@Partially.GwtIncompatible("AVAILABLE but requires exceptionType to be Throwable.class")
449-
public static <V, X extends Throwable> ListenableFuture<V> catchingAsync(
450-
ListenableFuture<? extends V> input,
451-
Class<X> exceptionType,
452-
AsyncFunction<? super X, ? extends V> fallback) {
453-
return AbstractCatchingFuture.create(input, exceptionType, fallback, directExecutor());
454-
}
455-
456329
/**
457330
* Returns a {@code Future} whose result is taken from the given primary {@code input} or, if the
458331
* primary input fails with the given {@code exceptionType}, from the result provided by the
@@ -543,54 +416,6 @@ public static <V> ListenableFuture<V> withTimeout(
543416
return TimeoutFuture.create(delegate, time, unit, scheduledExecutor);
544417
}
545418

546-
/**
547-
* Returns a new {@code Future} whose result is asynchronously derived from the result of the
548-
* given {@code Future}. If the given {@code Future} fails, the returned {@code Future} fails with
549-
* the same exception (and the function is not invoked).
550-
*
551-
* <p>More precisely, the returned {@code Future} takes its result from a {@code Future} produced
552-
* by applying the given {@code AsyncFunction} to the result of the original {@code Future}.
553-
* Example usage:
554-
*
555-
* <pre>{@code
556-
* ListenableFuture<RowKey> rowKeyFuture = indexService.lookUp(query);
557-
* ListenableFuture<QueryResult> queryFuture =
558-
* transformAsync(rowKeyFuture, dataService::readFuture);
559-
* }</pre>
560-
*
561-
* <p>This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous
562-
* choice in some cases. See the discussion in the {@link ListenableFuture#addListener
563-
* ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are
564-
* also applicable to heavyweight functions passed to this method. (Specifically, {@code
565-
* directExecutor} functions should avoid heavyweight operations inside {@code
566-
* AsyncFunction.apply}. Any heavyweight operations should occur in other threads responsible for
567-
* completing the returned {@code Future}.)
568-
*
569-
* <p>The returned {@code Future} attempts to keep its cancellation state in sync with that of the
570-
* input future and that of the future returned by the function. That is, if the returned {@code
571-
* Future} is cancelled, it will attempt to cancel the other two, and if either of the other two
572-
* is cancelled, the returned {@code Future} will receive a callback in which it will attempt to
573-
* cancel itself.
574-
*
575-
* @param input The future to transform
576-
* @param function A function to transform the result of the input future to the result of the
577-
* output future
578-
* @return A future that holds result of the function (if the input succeeded) or the original
579-
* input's failure (if not)
580-
* @since 19.0 (in 11.0 as {@code transform})
581-
* @deprecated Use {@linkplain #transformAsync(ListenableFuture, AsyncFunction, Executor) the
582-
* overload that requires an executor}. For identical behavior, pass {@link
583-
* MoreExecutors#directExecutor}, but consider whether another executor would be safer, as
584-
* discussed in the {@link ListenableFuture#addListener ListenableFuture.addListener}
585-
* documentation. This method is scheduled to be removed in July 2018.
586-
*/
587-
@Deprecated
588-
@DoNotCall
589-
public static <I, O> ListenableFuture<O> transformAsync(
590-
ListenableFuture<I> input, AsyncFunction<? super I, ? extends O> function) {
591-
return AbstractTransformFuture.create(input, function, directExecutor());
592-
}
593-
594419
/**
595420
* Returns a new {@code Future} whose result is asynchronously derived from the result of the
596421
* given {@code Future}. If the given {@code Future} fails, the returned {@code Future} fails with
@@ -634,48 +459,6 @@ public static <I, O> ListenableFuture<O> transformAsync(
634459
return AbstractTransformFuture.create(input, function, executor);
635460
}
636461

637-
/**
638-
* Returns a new {@code Future} whose result is derived from the result of the given {@code
639-
* Future}. If {@code input} fails, the returned {@code Future} fails with the same exception (and
640-
* the function is not invoked). Example usage:
641-
*
642-
* <pre>{@code
643-
* ListenableFuture<QueryResult> queryFuture = ...;
644-
* ListenableFuture<List<Row>> rowsFuture =
645-
* transform(queryFuture, QueryResult::getRows);
646-
* }</pre>
647-
*
648-
* <p>This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous
649-
* choice in some cases. See the discussion in the {@link ListenableFuture#addListener
650-
* ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are
651-
* also applicable to heavyweight functions passed to this method.
652-
*
653-
* <p>The returned {@code Future} attempts to keep its cancellation state in sync with that of the
654-
* input future. That is, if the returned {@code Future} is cancelled, it will attempt to cancel
655-
* the input, and if the input is cancelled, the returned {@code Future} will receive a callback
656-
* in which it will attempt to cancel itself.
657-
*
658-
* <p>An example use of this method is to convert a serializable object returned from an RPC into
659-
* a POJO.
660-
*
661-
* @param input The future to transform
662-
* @param function A Function to transform the results of the provided future to the results of
663-
* the returned future. This will be run in the thread that notifies input it is complete.
664-
* @return A future that holds result of the transformation.
665-
* @since 9.0 (in 1.0 as {@code compose})
666-
* @deprecated Use {@linkplain #transform(ListenableFuture, Function, Executor) the overload that
667-
* requires an executor}. For identical behavior, pass {@link MoreExecutors#directExecutor},
668-
* but consider whether another executor would be safer, as discussed in the {@link
669-
* ListenableFuture#addListener ListenableFuture.addListener} documentation. This method is
670-
* scheduled to be removed in July 2018.
671-
*/
672-
@Deprecated
673-
@DoNotCall
674-
public static <I, O> ListenableFuture<O> transform(
675-
ListenableFuture<I> input, Function<? super I, ? extends O> function) {
676-
return AbstractTransformFuture.create(input, function, directExecutor());
677-
}
678-
679462
/**
680463
* Returns a new {@code Future} whose result is derived from the result of the given {@code
681464
* Future}. If {@code input} fails, the returned {@code Future} fails with the same exception (and
@@ -917,22 +700,6 @@ public <C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner, Executor exe
917700
return new CombinedFuture<C>(futures, allMustSucceed, executor, combiner);
918701
}
919702

920-
/**
921-
* Like {@link #callAsync(AsyncCallable, Executor)} but using {@linkplain
922-
* MoreExecutors#directExecutor direct executor}.
923-
*
924-
* @deprecated Use {@linkplain #callAsync(AsyncCallable, Executor) the overload that requires an
925-
* executor}. For identical behavior, pass {@link MoreExecutors#directExecutor}, but
926-
* consider whether another executor would be safer, as discussed in the {@link
927-
* ListenableFuture#addListener ListenableFuture.addListener} documentation. This method is
928-
* scheduled to be removed in July 2018.
929-
*/
930-
@Deprecated
931-
@DoNotCall
932-
public <C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner) {
933-
return callAsync(combiner, directExecutor());
934-
}
935-
936703
/**
937704
* Creates the {@link ListenableFuture} which will return the result of calling {@link
938705
* Callable#call} in {@code combiner} when all futures complete, using the specified {@code
@@ -952,23 +719,6 @@ public <C> ListenableFuture<C> call(Callable<C> combiner, Executor executor) {
952719
return new CombinedFuture<C>(futures, allMustSucceed, executor, combiner);
953720
}
954721

955-
/**
956-
* Like {@link #call(Callable, Executor)} but using {@linkplain MoreExecutors#directExecutor
957-
* direct executor}.
958-
*
959-
* @deprecated Use {@linkplain #call(Callable, Executor) the overload that requires an
960-
* executor}. For identical behavior, pass {@link MoreExecutors#directExecutor}, but
961-
* consider whether another executor would be safer, as discussed in the {@link
962-
* ListenableFuture#addListener ListenableFuture.addListener} documentation. This method is
963-
* scheduled to be removed in July 2018.
964-
*/
965-
@CanIgnoreReturnValue // TODO(cpovirk): Remove this
966-
@Deprecated
967-
@DoNotCall
968-
public <C> ListenableFuture<C> call(Callable<C> combiner) {
969-
return call(combiner, directExecutor());
970-
}
971-
972722
/**
973723
* Creates the {@link ListenableFuture} which will return the result of running {@code combiner}
974724
* when all Futures complete. {@code combiner} will run using {@code executor}.
@@ -1237,53 +987,6 @@ private void recordCompletion() {
1237987
}
1238988
}
1239989

1240-
/**
1241-
* Registers separate success and failure callbacks to be run when the {@code Future}'s
1242-
* computation is {@linkplain java.util.concurrent.Future#isDone() complete} or, if the
1243-
* computation is already complete, immediately.
1244-
*
1245-
* <p>There is no guaranteed ordering of execution of callbacks, but any callback added through
1246-
* this method is guaranteed to be called once the computation is complete.
1247-
*
1248-
* <p>Example:
1249-
*
1250-
* <pre>{@code
1251-
* ListenableFuture<QueryResult> future = ...;
1252-
* addCallback(future,
1253-
* new FutureCallback<QueryResult>() {
1254-
* public void onSuccess(QueryResult result) {
1255-
* storeInCache(result);
1256-
* }
1257-
* public void onFailure(Throwable t) {
1258-
* reportError(t);
1259-
* }
1260-
* });
1261-
* }</pre>
1262-
*
1263-
* <p>This overload, which does not accept an executor, uses {@code directExecutor}, a dangerous
1264-
* choice in some cases. See the discussion in the {@link ListenableFuture#addListener
1265-
* ListenableFuture.addListener} documentation. All its warnings about heavyweight listeners are
1266-
* also applicable to heavyweight callbacks passed to this method.
1267-
*
1268-
* <p>For a more general interface to attach a completion listener to a {@code Future}, see {@link
1269-
* ListenableFuture#addListener addListener}.
1270-
*
1271-
* @param future The future attach the callback to.
1272-
* @param callback The callback to invoke when {@code future} is completed.
1273-
* @since 10.0
1274-
* @deprecated Use {@linkplain #addCallback(ListenableFuture, FutureCallback, Executor) the
1275-
* overload that requires an executor}. For identical behavior, pass {@link
1276-
* MoreExecutors#directExecutor}, but consider whether another executor would be safer, as
1277-
* discussed in the {@link ListenableFuture#addListener ListenableFuture.addListener}
1278-
* documentation. This method is scheduled to be removed in July 2018.
1279-
*/
1280-
@Deprecated
1281-
@DoNotCall
1282-
public static <V> void addCallback(
1283-
ListenableFuture<V> future, FutureCallback<? super V> callback) {
1284-
addCallback(future, callback, directExecutor());
1285-
}
1286-
1287990
/**
1288991
* Registers separate success and failure callbacks to be run when the {@code Future}'s
1289992
* computation is {@linkplain java.util.concurrent.Future#isDone() complete} or, if the

0 commit comments

Comments
 (0)