Skip to content

Commit

Permalink
Remove deprecated 1-arg ServiceManager.addListener.
Browse files Browse the repository at this point in the history
[]

RELNOTES=`util.concurrent`: Removed the deprecated 1-arg `ServiceManager.addListener(Listener)`. Use the 2-arg `addListener(Listener, Executor)` overload, setting the executor to `directExecutor()` for equivalent behavior.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=337538866
  • Loading branch information
cpovirk committed Oct 16, 2020
1 parent cf9bab3 commit dfb0001
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 76 deletions.
Expand Up @@ -17,6 +17,7 @@
package com.google.common.util.concurrent;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.SECONDS;

Expand Down Expand Up @@ -171,7 +172,7 @@ public void testServiceStartStop() {
Service b = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b);
assertFalse(manager.isHealthy());
manager.startAsync().awaitHealthy();
Expand All @@ -195,7 +196,7 @@ public void testFailStart() throws Exception {
Service e = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b, c, d, e));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b, c, d, e);
try {
manager.startAsync().awaitHealthy();
Expand All @@ -219,7 +220,7 @@ public void testFailRun() throws Exception {
Service b = new FailRunService();
ServiceManager manager = new ServiceManager(asList(a, b));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b);
try {
manager.startAsync().awaitHealthy();
Expand All @@ -242,7 +243,7 @@ public void testFailStop() throws Exception {
Service c = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b, c));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());

manager.startAsync().awaitHealthy();
assertTrue(listener.healthyCalled);
Expand Down Expand Up @@ -292,7 +293,7 @@ public void testSingleFailedServiceCallsStopped() {
Service a = new FailStartService();
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
try {
manager.startAsync().awaitHealthy();
fail();
Expand All @@ -309,7 +310,7 @@ public void testFailStart_singleServiceCallsHealthy() {
Service a = new FailStartService();
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
try {
manager.startAsync().awaitHealthy();
fail();
Expand All @@ -334,7 +335,8 @@ public void testFailStart_stopOthers() throws TimeoutException {
public void failure(Service service) {
manager.stopAsync();
}
});
},
directExecutor());
manager.startAsync();
manager.awaitStopped(10, TimeUnit.MILLISECONDS);
}
Expand Down Expand Up @@ -408,7 +410,7 @@ public void testEmptyServiceManager() {
logger.addHandler(logHandler);
ServiceManager manager = new ServiceManager(Arrays.<Service>asList());
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
manager.startAsync().awaitHealthy();
assertTrue(manager.isHealthy());
assertTrue(listener.healthyCalled);
Expand Down Expand Up @@ -476,7 +478,8 @@ public void failure(Service service) {
// block until after the service manager is shutdown
Uninterruptibles.awaitUninterruptibly(failLeave);
}
});
},
directExecutor());
manager.startAsync();
afterStarted.countDown();
// We do not call awaitHealthy because, due to races, that method may throw an exception. But
Expand Down
Expand Up @@ -30,7 +30,6 @@
import static com.google.common.util.concurrent.Service.State.TERMINATED;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -251,34 +250,6 @@ public void addListener(Listener listener, Executor executor) {
state.addListener(listener, executor);
}

/**
* Registers a {@link Listener} to be run when this {@link ServiceManager} changes state. The
* listener will not have previous state changes replayed, so it is suggested that listeners are
* added before any of the managed services are {@linkplain Service#startAsync started}.
*
* <p>{@code addListener} guarantees execution ordering across calls to a given listener but not
* across calls to multiple listeners. Specifically, a given listener will have its callbacks
* invoked in the same order as the underlying service enters those states. Additionally, at most
* one of the listener's callbacks will execute at once. However, multiple listeners' callbacks
* may execute concurrently, and listeners may execute in an order different from the one in which
* they were registered.
*
* <p>RuntimeExceptions thrown by a listener will be caught and logged.
*
* @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
@Deprecated
public void addListener(Listener listener) {
state.addListener(listener, directExecutor());
}

/**
* Initiates service {@linkplain Service#startAsync startup} on all the services being managed. It
* is only valid to call this method if all of the services are {@linkplain State#NEW new}.
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.google.common.util.concurrent;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.SECONDS;

Expand Down Expand Up @@ -171,7 +172,7 @@ public void testServiceStartStop() {
Service b = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b);
assertFalse(manager.isHealthy());
manager.startAsync().awaitHealthy();
Expand All @@ -195,7 +196,7 @@ public void testFailStart() throws Exception {
Service e = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b, c, d, e));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b, c, d, e);
try {
manager.startAsync().awaitHealthy();
Expand All @@ -219,7 +220,7 @@ public void testFailRun() throws Exception {
Service b = new FailRunService();
ServiceManager manager = new ServiceManager(asList(a, b));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
assertState(manager, Service.State.NEW, a, b);
try {
manager.startAsync().awaitHealthy();
Expand All @@ -242,7 +243,7 @@ public void testFailStop() throws Exception {
Service c = new NoOpService();
ServiceManager manager = new ServiceManager(asList(a, b, c));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());

manager.startAsync().awaitHealthy();
assertTrue(listener.healthyCalled);
Expand Down Expand Up @@ -292,7 +293,7 @@ public void testSingleFailedServiceCallsStopped() {
Service a = new FailStartService();
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
try {
manager.startAsync().awaitHealthy();
fail();
Expand All @@ -309,7 +310,7 @@ public void testFailStart_singleServiceCallsHealthy() {
Service a = new FailStartService();
ServiceManager manager = new ServiceManager(asList(a));
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
try {
manager.startAsync().awaitHealthy();
fail();
Expand All @@ -334,7 +335,8 @@ public void testFailStart_stopOthers() throws TimeoutException {
public void failure(Service service) {
manager.stopAsync();
}
});
},
directExecutor());
manager.startAsync();
manager.awaitStopped(10, TimeUnit.MILLISECONDS);
}
Expand Down Expand Up @@ -408,7 +410,7 @@ public void testEmptyServiceManager() {
logger.addHandler(logHandler);
ServiceManager manager = new ServiceManager(Arrays.<Service>asList());
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.addListener(listener, directExecutor());
manager.startAsync().awaitHealthy();
assertTrue(manager.isHealthy());
assertTrue(listener.healthyCalled);
Expand Down Expand Up @@ -476,7 +478,8 @@ public void failure(Service service) {
// block until after the service manager is shutdown
Uninterruptibles.awaitUninterruptibly(failLeave);
}
});
},
directExecutor());
manager.startAsync();
afterStarted.countDown();
// We do not call awaitHealthy because, due to races, that method may throw an exception. But
Expand Down
29 changes: 0 additions & 29 deletions guava/src/com/google/common/util/concurrent/ServiceManager.java
Expand Up @@ -31,7 +31,6 @@
import static com.google.common.util.concurrent.Service.State.TERMINATED;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -253,34 +252,6 @@ public void addListener(Listener listener, Executor executor) {
state.addListener(listener, executor);
}

/**
* Registers a {@link Listener} to be run when this {@link ServiceManager} changes state. The
* listener will not have previous state changes replayed, so it is suggested that listeners are
* added before any of the managed services are {@linkplain Service#startAsync started}.
*
* <p>{@code addListener} guarantees execution ordering across calls to a given listener but not
* across calls to multiple listeners. Specifically, a given listener will have its callbacks
* invoked in the same order as the underlying service enters those states. Additionally, at most
* one of the listener's callbacks will execute at once. However, multiple listeners' callbacks
* may execute concurrently, and listeners may execute in an order different from the one in which
* they were registered.
*
* <p>RuntimeExceptions thrown by a listener will be caught and logged.
*
* @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
@Deprecated
public void addListener(Listener listener) {
state.addListener(listener, directExecutor());
}

/**
* Initiates service {@linkplain Service#startAsync startup} on all the services being managed. It
* is only valid to call this method if all of the services are {@linkplain State#NEW new}.
Expand Down

0 comments on commit dfb0001

Please sign in to comment.