public abstract class AbstractExecutionServiceController extends Object implements ServiceController, com.google.common.util.concurrent.Service
ServiceController
that deal with Service state transition and
listener callback.ServiceController.TerminationStatus
Modifier | Constructor and Description |
---|---|
protected |
AbstractExecutionServiceController(RunId runId) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(com.google.common.util.concurrent.Service.Listener listener,
Executor executor) |
void |
awaitTerminated()
Waits for termination of the remote service.
|
void |
awaitTerminated(long timeout,
TimeUnit timeoutUnit)
Waits for termination of the remote service for no more than the given timeout limit.
|
protected Executor |
executor(com.google.common.util.concurrent.Service.State state) |
RunId |
getRunId()
Returns the
RunId of the running application. |
ServiceController.TerminationStatus |
getTerminationStatus()
Gets the termination status of the application represented by this controller.
|
boolean |
isRunning() |
void |
onRunning(Runnable runnable,
Executor executor)
Attaches a
Runnable that will get executed when the service is running. |
void |
onTerminated(Runnable runnable,
Executor executor)
Attaches a
Runnable that will get executed when the serivce is terminated. |
protected void |
setTerminationStatus(ServiceController.TerminationStatus status) |
protected abstract void |
shutDown() |
com.google.common.util.concurrent.ListenableFuture<com.google.common.util.concurrent.Service.State> |
start() |
com.google.common.util.concurrent.Service.State |
startAndWait() |
protected abstract void |
startUp() |
com.google.common.util.concurrent.Service.State |
state() |
com.google.common.util.concurrent.ListenableFuture<com.google.common.util.concurrent.Service.State> |
stop() |
com.google.common.util.concurrent.Service.State |
stopAndWait() |
Future<? extends ServiceController> |
terminate()
Requests to terminate the running service.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
kill, sendCommand, sendCommand
protected AbstractExecutionServiceController(RunId runId)
protected abstract void startUp()
protected abstract void shutDown()
public final RunId getRunId()
ServiceController
RunId
of the running application.getRunId
in interface ServiceController
public Future<? extends ServiceController> terminate()
ServiceController
Future
representing the termination state
will be returned.terminate
in interface ServiceController
Future
that represents the termination of the service. The future result will be
this ServiceController
. If the service terminated with a ServiceController.TerminationStatus.FAILED
status,
calling the Future.get()
on the returning future will throw ExecutionException
.@Nullable public ServiceController.TerminationStatus getTerminationStatus()
ServiceController
getTerminationStatus
in interface ServiceController
null
if the application is still runningpublic void onRunning(Runnable runnable, Executor executor)
ServiceController
Runnable
that will get executed when the service is running.onRunning
in interface ServiceController
runnable
- the Runnable
to be executed when the service is running.executor
- the executor in which the runnable will be executed with.public void onTerminated(Runnable runnable, Executor executor)
ServiceController
Runnable
that will get executed when the serivce is terminated.onTerminated
in interface ServiceController
runnable
- the Runnable
to be executed when the service is terminated.executor
- the executor in which the runnable will be executed with.public void awaitTerminated() throws ExecutionException
ServiceController
awaitTerminated
in interface com.google.common.util.concurrent.Service
awaitTerminated
in interface ServiceController
ExecutionException
- if the service terminated due to exception.public void awaitTerminated(long timeout, TimeUnit timeoutUnit) throws TimeoutException, ExecutionException
ServiceController
awaitTerminated
in interface com.google.common.util.concurrent.Service
awaitTerminated
in interface ServiceController
timeout
- the maximum time to waittimeoutUnit
- the time unit of the timeoutTimeoutException
- if the service is not terminated within the given time.ExecutionException
- if the service terminated due to exception.public final void addListener(com.google.common.util.concurrent.Service.Listener listener, Executor executor)
addListener
in interface com.google.common.util.concurrent.Service
public final com.google.common.util.concurrent.ListenableFuture<com.google.common.util.concurrent.Service.State> start()
start
in interface com.google.common.util.concurrent.Service
public final com.google.common.util.concurrent.Service.State startAndWait()
startAndWait
in interface com.google.common.util.concurrent.Service
public final boolean isRunning()
isRunning
in interface com.google.common.util.concurrent.Service
public final com.google.common.util.concurrent.Service.State state()
state
in interface com.google.common.util.concurrent.Service
public final com.google.common.util.concurrent.Service.State stopAndWait()
stopAndWait
in interface com.google.common.util.concurrent.Service
public final com.google.common.util.concurrent.ListenableFuture<com.google.common.util.concurrent.Service.State> stop()
stop
in interface com.google.common.util.concurrent.Service
protected Executor executor(com.google.common.util.concurrent.Service.State state)
protected final void setTerminationStatus(ServiceController.TerminationStatus status)
Copyright © 2013-2020 The Apache Software Foundation. All rights reserved.