Package org.apache.pulsar.broker.service
Class GracefulExecutorServicesShutdown
- java.lang.Object
-
- org.apache.pulsar.broker.service.GracefulExecutorServicesShutdown
-
public class GracefulExecutorServicesShutdown extends java.lang.ObjectThis a builder like class for providing a fluent API for graceful shutdown Executors are added with theshutdown(ExecutorService...)method. TheExecutorService.shutdown()method is called immediately. Calling thehandle()method returns a future which completes when all executors have been terminated. The executors will waited for completion with theExecutorService.awaitTermination(long, TimeUnit)method. If the shutdown times out or the future is cancelled, all executors will be terminated and the termination timeout value will be used for waiting for termination. The default value for termination timeout is 10% of the shutdown timeout.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Void>handle()Starts the handler for polling frequently for the completed termination of enlisted executors.static GracefulExecutorServicesShutdowninitiate()Initiates a new shutdown for one or manyExecutorServices.GracefulExecutorServicesShutdownshutdown(java.util.concurrent.ExecutorService... executorServices)CallsExecutorService.shutdown()and enlists the executor as part of the shutdown handling.GracefulExecutorServicesShutdownterminationTimeout(java.time.Duration terminationTimeout)Sets the timeout for waiting for executors to complete in forceful termination.GracefulExecutorServicesShutdowntimeout(java.time.Duration timeout)Sets the timeout for graceful shutdown.
-
-
-
Method Detail
-
initiate
public static GracefulExecutorServicesShutdown initiate()
Initiates a new shutdown for one or manyExecutorServices.- Returns:
- a new instance for controlling graceful shutdown
-
shutdown
public GracefulExecutorServicesShutdown shutdown(java.util.concurrent.ExecutorService... executorServices)
CallsExecutorService.shutdown()and enlists the executor as part of the shutdown handling.- Parameters:
executorServices- one or many executors to shutdown- Returns:
- the current instance for controlling graceful shutdown
-
timeout
public GracefulExecutorServicesShutdown timeout(java.time.Duration timeout)
Sets the timeout for graceful shutdown.- Parameters:
timeout- duration for the timeout- Returns:
- the current instance for controlling graceful shutdown
-
terminationTimeout
public GracefulExecutorServicesShutdown terminationTimeout(java.time.Duration terminationTimeout)
Sets the timeout for waiting for executors to complete in forceful termination.- Parameters:
terminationTimeout- duration for the timeout- Returns:
- the current instance for controlling graceful shutdown
-
handle
public java.util.concurrent.CompletableFuture<java.lang.Void> handle()
Starts the handler for polling frequently for the completed termination of enlisted executors. If the termination times out or the future is cancelled, all active executors will be forcefully terminated by callingExecutorService.shutdownNow().- Returns:
- a future which completes when all executors have terminated
-
-