Package io.pravega.common.concurrent
Class AbstractThreadPoolService
- java.lang.Object
-
- com.google.common.util.concurrent.AbstractService
-
- io.pravega.common.concurrent.AbstractThreadPoolService
-
- All Implemented Interfaces:
com.google.common.util.concurrent.Service,java.lang.AutoCloseable
public abstract class AbstractThreadPoolService extends com.google.common.util.concurrent.AbstractService implements java.lang.AutoCloseableBase Service that runs asynchronously using a thread pool.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ScheduledExecutorServiceexecutorprotected java.lang.StringtraceObjectId
-
Constructor Summary
Constructors Constructor Description AbstractThreadPoolService(java.lang.String traceObjectId, java.util.concurrent.ScheduledExecutorService executor)Creates a new instance of the AbstractThreadPoolService class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract java.util.concurrent.CompletableFuture<java.lang.Void>doRun()Main execution of the Service.protected voiddoStart()protected voiddoStop()protected voiderrorHandler(java.lang.Throwable ex)When overridden in a derived class, handles an exception that is caught by the execution of run().protected abstract java.time.DurationgetShutdownTimeout()Gets a value indicating how much to wait for the service to shut down, before failing it.protected java.lang.ThrowablegetStopException()Gets a pointer to the current Stop Exception, if any is set.-
Methods inherited from class com.google.common.util.concurrent.AbstractService
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, doCancelStart, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync, toString
-
-
-
-
Constructor Detail
-
AbstractThreadPoolService
public AbstractThreadPoolService(java.lang.String traceObjectId, java.util.concurrent.ScheduledExecutorService executor)Creates a new instance of the AbstractThreadPoolService class.- Parameters:
traceObjectId- An identifier to use for logging purposes. This will be included at the beginning of all log calls initiated by this Service.executor- The Executor to use for async callbacks and operations.
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
doStart
protected void doStart()
- Specified by:
doStartin classcom.google.common.util.concurrent.AbstractService
-
doStop
protected void doStop()
- Specified by:
doStopin classcom.google.common.util.concurrent.AbstractService
-
getShutdownTimeout
protected abstract java.time.Duration getShutdownTimeout()
Gets a value indicating how much to wait for the service to shut down, before failing it.- Returns:
- The Duration.
-
doRun
protected abstract java.util.concurrent.CompletableFuture<java.lang.Void> doRun()
Main execution of the Service. When this Future completes, the service auto-shuts down.- Returns:
- A CompletableFuture that, when completed, indicates the service is terminated. If the Future completed exceptionally, the Service will shut down with failure, otherwise it will terminate normally.
-
getStopException
protected java.lang.Throwable getStopException()
Gets a pointer to the current Stop Exception, if any is set.- Returns:
- The result.
-
errorHandler
protected void errorHandler(java.lang.Throwable ex)
When overridden in a derived class, handles an exception that is caught by the execution of run(). The default implementation simply records the exception in the stopException field, which will then be used to fail the service when it shuts down.- Parameters:
ex- The Exception.
-
-