Class ShutdownLatch
java.lang.Object
org.axonframework.common.lifecycle.ShutdownLatch
A latch implementation to be used in shutdown scenarios. Activities to wait for can be added by invoking
registerActivity(). A registered activity should always shutdown through the returned ShutdownLatch.ActivityHandle's
ShutdownLatch.ActivityHandle.end() method once it has completed. Otherwise initiateShutdown() will block
indefinitely. If the latch is waited on through initiateShutdown(), new operations can no longer be
registered.- Since:
- 4.3
- Author:
- Steven van Beelen
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidifShuttingDown(String exceptionMessage) Check whether thisShutdownLatchis shutting down.voidifShuttingDown(Supplier<RuntimeException> exceptionSupplier) Check whether thisShutdownLatchis shutting down.voidInitialize thisShutdownLatch.Initiate the shutdown of this latch.booleanCheck whether thisShutdownLatchis shutting down.Add an activity this latch should wait on before opening up.
-
Constructor Details
-
ShutdownLatch
public ShutdownLatch()
-
-
Method Details
-
initialize
public void initialize()Initialize thisShutdownLatch. If the latch was already closed throughinitiateShutdown(), then that operation will be canceled. -
registerActivity
Add an activity this latch should wait on before opening up. If this operation is invoked whilstinitiateShutdown()has already been called aShutdownInProgressExceptionwill be thrown.- Returns:
- an
ShutdownLatch.ActivityHandletoShutdownLatch.ActivityHandle.end()the registered activity once it is done - Throws:
ShutdownInProgressException- ifinitiateShutdown()has been called prior to invoking this method
-
ifShuttingDown
Check whether thisShutdownLatchis shutting down. The givenexceptionMessageis used in the thrownShutdownInProgressException, if this latch is shutting down.- Parameters:
exceptionMessage- the message used for theShutdownInProgressExceptionto throw if this latch is shutting down
-
ifShuttingDown
Check whether thisShutdownLatchis shutting down. The exception retrieved from theexceptionSupplierwill be thrown if this latch is shutting down.- Parameters:
exceptionSupplier- aSupplierof aRuntimeExceptionto throw if this latch is waited on
-
isShuttingDown
public boolean isShuttingDown()Check whether thisShutdownLatchis shutting down.- Returns:
trueif the latch is waited on,falseotherwise
-
initiateShutdown
Initiate the shutdown of this latch. The returnedCompletableFuturewill complete once all activities have been ended or complete immediately if no activities are active.- Returns:
- a
CompletableFuturewhich completes once all activities are done
-