Skip to content

Commit 86e3620

Browse files
cpovirknick-someone
authored andcommitted
Deprecate 1-arg overload of ServiceManager.addListener.
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
1 parent ce37aee commit 86e3620

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ public ServiceManager(Iterable<? extends Service> services) {
243243
* during {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
244244
* logged.
245245
*
246-
* <p>For fast, lightweight listeners that would be safe to execute in any thread, consider
247-
* calling {@link #addListener(Listener)}.
246+
* <p>When selecting an executor, note that {@code directExecutor} is dangerous in some cases. See
247+
* the discussion in the {@link ListenableFuture#addListener ListenableFuture.addListener}
248+
* documentation.
248249
*
249250
* @param listener the listener to run when the manager changes state
250251
* @param executor the executor in which the listeners callback methods will be run.
@@ -269,7 +270,14 @@ public void addListener(Listener listener, Executor executor) {
269270
*
270271
* @param listener the listener to run when the manager changes state
271272
* @since 15.0
273+
* @deprecated Use {@linkplain #addListener(Listener, Executor) the overload that accepts an
274+
* executor}. For equivalent behavior, pass {@link MoreExecutors#directExecutor}. However,
275+
* consider whether another executor would be more appropriate, as discussed in the docs for
276+
* {@link ListenableFuture#addListener ListenableFuture.addListener}. This method is scheduled
277+
* for deletion in October 2020.
272278
*/
279+
@Beta // currently redundant, but ensures we keep this @Beta when we gradate the class!
280+
@Deprecated
273281
public void addListener(Listener listener) {
274282
state.addListener(listener, directExecutor());
275283
}

guava/src/com/google/common/util/concurrent/ServiceManager.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ public ServiceManager(Iterable<? extends Service> services) {
245245
* during {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
246246
* logged.
247247
*
248-
* <p>For fast, lightweight listeners that would be safe to execute in any thread, consider
249-
* calling {@link #addListener(Listener)}.
248+
* <p>When selecting an executor, note that {@code directExecutor} is dangerous in some cases. See
249+
* the discussion in the {@link ListenableFuture#addListener ListenableFuture.addListener}
250+
* documentation.
250251
*
251252
* @param listener the listener to run when the manager changes state
252253
* @param executor the executor in which the listeners callback methods will be run.
@@ -271,7 +272,14 @@ public void addListener(Listener listener, Executor executor) {
271272
*
272273
* @param listener the listener to run when the manager changes state
273274
* @since 15.0
275+
* @deprecated Use {@linkplain #addListener(Listener, Executor) the overload that accepts an
276+
* executor}. For equivalent behavior, pass {@link MoreExecutors#directExecutor}. However,
277+
* consider whether another executor would be more appropriate, as discussed in the docs for
278+
* {@link ListenableFuture#addListener ListenableFuture.addListener}. This method is scheduled
279+
* for deletion in October 2020.
274280
*/
281+
@Beta // currently redundant, but ensures we keep this @Beta when we gradate the class!
282+
@Deprecated
275283
public void addListener(Listener listener) {
276284
state.addListener(listener, directExecutor());
277285
}

0 commit comments

Comments
 (0)