aboutsummaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/util/concurrent/AbstractIdleService.java')
-rw-r--r--guava/src/com/google/common/util/concurrent/AbstractIdleService.java40
1 files changed, 10 insertions, 30 deletions
diff --git a/guava/src/com/google/common/util/concurrent/AbstractIdleService.java b/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
index 96a6ff3..504a6bc 100644
--- a/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
+++ b/guava/src/com/google/common/util/concurrent/AbstractIdleService.java
@@ -37,7 +37,7 @@ public abstract class AbstractIdleService implements Service {
/* use AbstractService for state management */
private final Service delegate = new AbstractService() {
@Override protected final void doStart() {
- executor().execute(new Runnable() {
+ executor(State.STARTING).execute(new Runnable() {
@Override public void run() {
try {
startUp();
@@ -51,7 +51,7 @@ public abstract class AbstractIdleService implements Service {
}
@Override protected final void doStop() {
- executor().execute(new Runnable() {
+ executor(State.STOPPING).execute(new Runnable() {
@Override public void run() {
try {
shutDown();
@@ -65,9 +65,6 @@ public abstract class AbstractIdleService implements Service {
}
};
- /** Constructor for use by subclasses. */
- protected AbstractIdleService() {}
-
/** Start the service. */
protected abstract void startUp() throws Exception;
@@ -81,19 +78,22 @@ public abstract class AbstractIdleService implements Service {
* priority. The returned executor's {@link Executor#execute(Runnable)
* execute()} method is called when this service is started and stopped,
* and should return promptly.
+ *
+ * @param state {@link Service.State#STARTING} or
+ * {@link Service.State#STOPPING}, used by the default implementation for
+ * naming the thread
*/
- protected Executor executor() {
- final State state = state();
+ protected Executor executor(final State state) {
return new Executor() {
@Override
public void execute(Runnable command) {
- MoreExecutors.newThread(serviceName() + " " + state, command).start();
+ new Thread(command, getServiceName() + " " + state).start();
}
};
}
@Override public String toString() {
- return serviceName() + " [" + state() + "]";
+ return getServiceName() + " [" + state() + "]";
}
// We override instead of using ForwardingService so that these can be final.
@@ -122,27 +122,7 @@ public abstract class AbstractIdleService implements Service {
return delegate.stopAndWait();
}
- /**
- * @since 13.0
- */
- @Override public final void addListener(Listener listener, Executor executor) {
- delegate.addListener(listener, executor);
- }
-
- /**
- * @since 14.0
- */
- @Override public final Throwable failureCause() {
- return delegate.failureCause();
- }
-
- /**
- * Returns the name of this service. {@link AbstractIdleService} may include the name in debugging
- * output.
- *
- * @since 14.0
- */
- protected String serviceName() {
+ private String getServiceName() {
return getClass().getSimpleName();
}
}