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.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
ConstructorsConstructorDescriptionExecutorWrapperService(Callable<T> serviceCreator, String serviceName, String frameworkIdentifier) Creates a wrapper around an ExecutorService. -
Method Summary
Methods inherited from class com.google.common.util.concurrent.AbstractIdleService
addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync
-
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
- Specified by:
startUpin classcom.google.common.util.concurrent.AbstractIdleService- Throws:
Exception
-
shutDown
- Specified by:
shutDownin classcom.google.common.util.concurrent.AbstractIdleService- Throws:
Exception
-
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
- Overrides:
toStringin classcom.google.common.util.concurrent.AbstractIdleService
-