|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.util.concurrent.AbstractService
@Beta public abstract class AbstractService
Base class for implementing services that can handle doStart() and
doStop() requests, responding to them with notifyStarted()
and notifyStopped() callbacks. Its subclasses must manage threads
manually; consider AbstractExecutionThreadService if you need only a
single execution thread.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.google.common.base.Service |
|---|
Service.State |
| Constructor Summary | |
|---|---|
AbstractService()
|
|
| Method Summary | |
|---|---|
protected abstract void |
doStart()
This method is called by start() to initiate service startup. |
protected abstract void |
doStop()
This method should be used to initiate service shutdown. |
boolean |
isRunning()
|
protected void |
notifyFailed(java.lang.Throwable cause)
Invoke this method to transition the service to the Service.State.FAILED. |
protected void |
notifyStarted()
Implementing classes should invoke this method once their service has started. |
protected void |
notifyStopped()
Implementing classes should invoke this method once their service has stopped. |
java.util.concurrent.Future<Service.State> |
start()
|
Service.State |
startAndWait()
|
Service.State |
state()
|
java.util.concurrent.Future<Service.State> |
stop()
|
Service.State |
stopAndWait()
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractService()
| Method Detail |
|---|
protected abstract void doStart()
start() to initiate service startup. The
invocation of this method should cause a call to notifyStarted(),
either during this method's run, or after it has returned. If startup
fails, the invocation should cause a call to notifyFailed(Throwable) instead.
This method should return promptly; prefer to do work on a different
thread where it is convenient. It is invoked exactly once on service
startup, even when start() is called multiple times.
protected abstract void doStop()
notifyStopped(), either
during this method's run, or after it has returned. If shutdown fails, the
invocation should cause a call to notifyFailed(Throwable) instead.
This method should return promptly; prefer to do work on a different
thread where it is convenient. It is invoked exactly once on service
shutdown, even when stop() is called multiple times.
public final java.util.concurrent.Future<Service.State> start()
start in interface Servicepublic final java.util.concurrent.Future<Service.State> stop()
stop in interface Servicepublic Service.State startAndWait()
startAndWait in interface Servicepublic Service.State stopAndWait()
stopAndWait in interface Serviceprotected final void notifyStarted()
Service.State.STARTING to Service.State.RUNNING.
java.lang.IllegalStateException - if the service is not
Service.State.STARTING.protected final void notifyStopped()
Service.State.STOPPING to Service.State.TERMINATED.
java.lang.IllegalStateException - if the service is neither Service.State.STOPPING nor Service.State.RUNNING.protected final void notifyFailed(java.lang.Throwable cause)
Service.State.FAILED. The service will not be stopped if it
is running. Invoke this method when a service has failed critically or
otherwise cannot be started nor stopped.
public final boolean isRunning()
isRunning in interface Servicepublic final Service.State state()
state in interface Servicepublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||