Skip to content

Commit

Permalink
Deprecate 1-arg overload of ServiceManager.addListener.
Browse files Browse the repository at this point in the history
It default to directExecutor(). directExecutor() is often useful, but it should be an explicit choice, as some usages are dangerous:
https://guava.dev/releases/snapshot-jre/api/docs/com/google/common/util/concurrent/ListenableFuture.html#addListener-java.lang.Runnable-java.util.concurrent.Executor-

#3418

RELNOTES=`util.concurrent`: Deprecated the 1-arg overload of `ServiceManager.addListener`.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=303500936
  • Loading branch information
cpovirk authored and nick-someone committed Mar 30, 2020
1 parent ce37aee commit 86e3620
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -243,8 +243,9 @@ public ServiceManager(Iterable<? extends Service> services) {
* during {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
* logged.
*
* <p>For fast, lightweight listeners that would be safe to execute in any thread, consider
* calling {@link #addListener(Listener)}.
* <p>When selecting an executor, note that {@code directExecutor} is dangerous in some cases. See
* the discussion in the {@link ListenableFuture#addListener ListenableFuture.addListener}
* documentation.
*
* @param listener the listener to run when the manager changes state
* @param executor the executor in which the listeners callback methods will be run.
Expand All @@ -269,7 +270,14 @@ public void addListener(Listener listener, Executor executor) {
*
* @param listener the listener to run when the manager changes state
* @since 15.0
* @deprecated Use {@linkplain #addListener(Listener, Executor) the overload that accepts an
* executor}. For equivalent behavior, pass {@link MoreExecutors#directExecutor}. However,
* consider whether another executor would be more appropriate, as discussed in the docs for
* {@link ListenableFuture#addListener ListenableFuture.addListener}. This method is scheduled
* for deletion in October 2020.
*/
@Beta // currently redundant, but ensures we keep this @Beta when we gradate the class!
@Deprecated
public void addListener(Listener listener) {
state.addListener(listener, directExecutor());
}
Expand Down
12 changes: 10 additions & 2 deletions guava/src/com/google/common/util/concurrent/ServiceManager.java
Expand Up @@ -245,8 +245,9 @@ public ServiceManager(Iterable<? extends Service> services) {
* during {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
* logged.
*
* <p>For fast, lightweight listeners that would be safe to execute in any thread, consider
* calling {@link #addListener(Listener)}.
* <p>When selecting an executor, note that {@code directExecutor} is dangerous in some cases. See
* the discussion in the {@link ListenableFuture#addListener ListenableFuture.addListener}
* documentation.
*
* @param listener the listener to run when the manager changes state
* @param executor the executor in which the listeners callback methods will be run.
Expand All @@ -271,7 +272,14 @@ public void addListener(Listener listener, Executor executor) {
*
* @param listener the listener to run when the manager changes state
* @since 15.0
* @deprecated Use {@linkplain #addListener(Listener, Executor) the overload that accepts an
* executor}. For equivalent behavior, pass {@link MoreExecutors#directExecutor}. However,
* consider whether another executor would be more appropriate, as discussed in the docs for
* {@link ListenableFuture#addListener ListenableFuture.addListener}. This method is scheduled
* for deletion in October 2020.
*/
@Beta // currently redundant, but ensures we keep this @Beta when we gradate the class!
@Deprecated
public void addListener(Listener listener) {
state.addListener(listener, directExecutor());
}
Expand Down

0 comments on commit 86e3620

Please sign in to comment.