Class 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.AutoCloseable
    Base Service that runs asynchronously using a thread pool.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

        com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.ScheduledExecutorService executor  
      protected java.lang.String traceObjectId  
    • 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
      void close()  
      protected abstract java.util.concurrent.CompletableFuture<java.lang.Void> doRun()
      Main execution of the Service.
      protected void doStart()  
      protected void doStop()  
      protected void errorHandler​(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.Duration getShutdownTimeout()
      Gets a value indicating how much to wait for the service to shut down, before failing it.
      protected java.lang.Throwable getStopException()
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.google.common.util.concurrent.Service

        awaitRunning, awaitTerminated
    • Field Detail

      • traceObjectId

        protected final java.lang.String traceObjectId
      • executor

        protected final java.util.concurrent.ScheduledExecutorService executor
    • 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:
        close in interface java.lang.AutoCloseable
      • doStart

        protected void doStart()
        Specified by:
        doStart in class com.google.common.util.concurrent.AbstractService
      • doStop

        protected void doStop()
        Specified by:
        doStop in class com.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.