Class ExecutorShutdownController
java.lang.Object
ch.raffael.meldioc.library.base.lifecycle.ExecutorShutdownController
- All Implemented Interfaces:
ShutdownController,ShutdownController.Actuator
public class ExecutorShutdownController extends java.lang.Object implements ShutdownController, ShutdownController.Actuator
A shutdown controller that allows to parallelize the shutdown.
The prepare and perform callbacks are called in parallel, but not overlapping (i.e. peform callbacks will only be called after all prepare callbacks are finished.
The finalize callback will be called serially the thread initiating the shutdown (finalizing the shutdown usually includes to destroying the work thread pool).
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.raffael.meldioc.library.base.lifecycle.ShutdownController
ShutdownController.Actuator, ShutdownController.IllegalShutdownStateException, ShutdownController.State, ShutdownController.Wrapper -
Constructor Summary
Constructors Constructor Description ExecutorShutdownController(java.util.function.Supplier<? extends java.util.concurrent.Executor> executor) -
Method Summary
Modifier and Type Method Description ExecutorShutdownControlleractuator()voidannounceShutdown()ShutdownControllercontroller()<T> TgetPreventingShutdown(java.util.function.Supplier<T> supplier)Run an action that prevents a shutdown being performed while running.protected voidonDoShutdown()voidonFinalize(io.vavr.CheckedRunnable callback)voidonPerform(io.vavr.CheckedRunnable callback)voidonPrepare(io.vavr.CheckedRunnable callback)protected voidonShutdownComplete(io.vavr.collection.Seq<java.lang.Throwable> exceptions)io.vavr.collection.Seq<java.lang.Throwable>performShutdown()ShutdownController.Statestate()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.raffael.meldioc.library.base.lifecycle.ShutdownController.Actuator
runPreventingShutdown
-
Constructor Details
-
ExecutorShutdownController
public ExecutorShutdownController(java.util.function.Supplier<? extends java.util.concurrent.Executor> executor)
-
-
Method Details
-
onPrepare
public void onPrepare(io.vavr.CheckedRunnable callback)- Specified by:
onPreparein interfaceShutdownController
-
onPerform
public void onPerform(io.vavr.CheckedRunnable callback)- Specified by:
onPerformin interfaceShutdownController
-
onFinalize
public void onFinalize(io.vavr.CheckedRunnable callback)- Specified by:
onFinalizein interfaceShutdownController
-
controller
- Specified by:
controllerin interfaceShutdownController.Actuator
-
state
- Specified by:
statein interfaceShutdownController- Specified by:
statein interfaceShutdownController.Actuator
-
actuator
-
getPreventingShutdown
public <T> T getPreventingShutdown(java.util.function.Supplier<T> supplier)Description copied from interface:ShutdownController.ActuatorRun an action that prevents a shutdown being performed while running.- Specified by:
getPreventingShutdownin interfaceShutdownController.Actuator
-
announceShutdown
public void announceShutdown()- Specified by:
announceShutdownin interfaceShutdownController.Actuator
-
performShutdown
public io.vavr.collection.Seq<java.lang.Throwable> performShutdown() throws java.lang.InterruptedException- Specified by:
performShutdownin interfaceShutdownController.Actuator- Throws:
java.lang.InterruptedException
-
onShutdownComplete
protected void onShutdownComplete(io.vavr.collection.Seq<java.lang.Throwable> exceptions) -
onDoShutdown
protected void onDoShutdown()
-