Class ExecutorWrapperService<T extends ExecutorService>

java.lang.Object
com.google.common.util.concurrent.AbstractIdleService
org.somda.sdc.common.util.ExecutorWrapperService<T>
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 Summary

    Constructors
    Constructor
    Description
    ExecutorWrapperService(Callable<T> serviceCreator, String serviceName, String frameworkIdentifier)
    Creates a wrapper around an ExecutorService.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Gets the ExecutorService instance when service is running.
    protected void
     
    protected void
     
     

    Methods inherited from class com.google.common.util.concurrent.AbstractIdleService

    addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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