Class ExecutorWrapperService<T extends ExecutorService>

  • Type Parameters:
    T - actual type of the ExecutorService.
    All Implemented Interfaces:
    com.google.common.util.concurrent.Service

    public class ExecutorWrapperService<T extends ExecutorService>
    extends com.google.common.util.concurrent.AbstractIdleService
    Wraps an ExecutorService into a guava AbstractIdleService.

    Wrapping ExecutorServices into guava services allows orchestrating thread pool instances, especially shutting them down properly when shutting down a parent service instance.

    • 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
    • Constructor Detail

      • ExecutorWrapperService

        public ExecutorWrapperService​(Callable<T> serviceCreator,
                                      String serviceName,
                                      String frameworkIdentifier)
        Creates a wrapper around an ExecutorService.
        Parameters:
        serviceCreator - Callable which returns an ExecutorService.
        serviceName - name for the service, used in logging.
        frameworkIdentifier - identifier used for logging
    • Method Detail

      • startUp

        protected void startUp()
                        throws Exception
        Specified by:
        startUp in class com.google.common.util.concurrent.AbstractIdleService
        Throws:
        Exception
      • shutDown

        protected void shutDown()
                         throws Exception
        Specified by:
        shutDown in class com.google.common.util.concurrent.AbstractIdleService
        Throws:
        Exception
      • get

        public T get()
        Gets the ExecutorService instance when service is running.

        Only ever access this once the service has been started!

        Returns:
        wrapped ExecutorService instance.
        Throws:
        RuntimeException - when the service isn't running yet.
      • toString

        public String toString()
        Overrides:
        toString in class com.google.common.util.concurrent.AbstractIdleService