Package org.somda.sdc.common.util
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.AbstractIdleServiceWraps 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.
-
-
Constructor Summary
Constructors Constructor Description ExecutorWrapperService(Callable<T> serviceCreator)Creates a wrapper around an ExecutorService.ExecutorWrapperService(Callable<T> serviceCreator, String serviceName)Creates a wrapper around an ExecutorService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Gets the ExecutorService instance when service is running.protected voidshutDown()protected voidstartUp()-
Methods inherited from class com.google.common.util.concurrent.AbstractIdleService
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync, toString
-
-
-
-
Constructor Detail
-
ExecutorWrapperService
public ExecutorWrapperService(Callable<T> serviceCreator)
Creates a wrapper around an ExecutorService.- Parameters:
serviceCreator- Callable which returns an ExecutorService.
-
ExecutorWrapperService
public ExecutorWrapperService(Callable<T> serviceCreator, String serviceName)
Creates a wrapper around an ExecutorService.- Parameters:
serviceCreator- Callable which returns an ExecutorService.serviceName- name for the service, used in logging.
-
-
Method Detail
-
startUp
protected void startUp() throws Exception- Specified by:
startUpin classcom.google.common.util.concurrent.AbstractIdleService- Throws:
Exception
-
shutDown
protected void shutDown() throws Exception- Specified by:
shutDownin classcom.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.
-
-