sealed trait LifeCycleManager extends HasSynchronizeWithClosing
Ensures orderly shutdown for a set of LifeCycleManager.ManagedResources and dependent LifeCycleManagers. This creates a shutdown hierarchy.
When a LifeCycleManager is closed with LifeCycleManager.closeAsync, the following shutdown procedure is applied:
- Close signal propagation: The LifeCycleManager and all its dependent LifeCycleManagers are notified that closing is in progress. Thereafter, their HasRunOnClosing.isClosing returns true. Transitive dependents are also notified, but this need not be synchronized with the next step.
- Run on closing: The RunOnClosing tasks registered with the LifeCycleManager. Exceptions from the RunOnClosing tasks are logged and then discarded. The dependent LifeCycleManagers also start running their RunOnClosing tasks.
- Synchronize with closing: The LifeCycleManager waits until all its HasSynchronizeWithClosing.synchronizeWithClosing computations have finished or until LifeCycleManager.synchronizeWithClosingPatience has elapsed.
- Release: The LifeCycleManager releases all its LifeCycleManager.ManagedResources and instructs dependent LifeCycleManagers to do so in ascending priority order. Within the same priority, releasing is unordered and possibly in parallel. When a dependent LifeCycleManager is instructed, it waits until step 2 has finished and then performs steps 3 and 4 of this procedure.
Exceptions thrown in the last step "release" are propagated as a ShutdownFailedException with proper exception chaining. If the third step completes because the patience has elapsed and some HasSynchronizeWithClosing.synchronizeWithClosing computations are still running at the end of the last step, a ShutdownFailedException signals such a synchronization failure.
Rationale for this exception handling policy:
- When an exception happens in the last step, it is unknown whether all dependencies have successfully finished all their business. So we must signal to the caller that the unexpected happened.
- When some HasSynchronizeWithClosing.synchronizeWithClosing is still running after everything has been released, we cannot guarantee that all side effects guarded by this shutdown hierarchy are over. We signal this to the caller via an exception.
- In contrast, RunOnClosing tasks are meant to quickly clean up stuff upon closing. They are not synchronized with closing, and therefore we merely log exceptions, but do not propagate them.
- Self Type
- LifeCycleManager
- Alphabetic
- By Inheritance
- LifeCycleManager
- HasSynchronizeWithClosing
- HasRunOnClosing
- HasUnlessClosing
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def closeAsync()(implicit traceContext: TraceContext): Future[Unit]
Closes the LifeCycleManager and alls its registered LifeCycleManager.ManagedResources.
Closes the LifeCycleManager and alls its registered LifeCycleManager.ManagedResources.
May be called multiple times, but subsequent calls merely return the same future as the first call.
- abstract def isClosing: Boolean
Returns whether the component is closing or has already been closed
Returns whether the component is closing or has already been closed
- Definition Classes
- HasUnlessClosing
- abstract def name: String
- abstract def register(task: LifeCycleManagerTask, priority: Int): Either[TraceContext, LifeCycleRegistrationHandle]
Internal implementation method for runOnClose and registerManaged.
Internal implementation method for runOnClose and registerManaged.
- returns
The closing com.digitalasset.canton.tracing.TraceContext if registration fails because the LifeCycleManager is already closing.
- Attributes
- protected
- abstract def runTaskUnlessDone(task: RunOnClosing)(implicit traceContext: TraceContext): Unit
- Attributes
- protected[this]
- Definition Classes
- HasRunOnClosing
- abstract def synchronizeWithClosingF[F[_], A](name: String)(f: => F[A])(implicit traceContext: TraceContext, F: Thereafter[F]): UnlessShutdown[F[A]]
Runs the computation
f
only if the component is not yet closing.Runs the computation
f
only if the component is not yet closing. If so, the component will delay releasing its resources untilf
has completed (as defined by the com.digitalasset.canton.util.Thereafter instance) or the LifeCycleManager.synchronizeWithClosingPatience has elapsed.- returns
com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if
f
has not run. Otherwise the result of runningf
.
- Definition Classes
- HasSynchronizeWithClosing
- See also
HasRunOnClosing.isClosing
- abstract def synchronizeWithClosingPatience: FiniteDuration
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- def registerManaged(managed: ManagedResource, priority: Short = 0): UnlessShutdown[LifeCycleRegistrationHandle]
Registers a LifeCycleManager.ManagedResource with this LifeCycleManager so that it will be released as part of the last step of the shutdown procedure, as part of the given priority group.
Registers a LifeCycleManager.ManagedResource with this LifeCycleManager so that it will be released as part of the last step of the shutdown procedure, as part of the given priority group.
- returns
com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if the LifeCycleManager has already been closed and therefore it will not close the LifeCycleManager.ManagedResource. Otherwise, the returned LifeCycleRegistrationHandle allows to deregister the resource again.
- final def runOnClose(task: RunOnClosing): UnlessShutdown[LifeCycleRegistrationHandle]
If a token is returned, the task will have run before the LifeCycleManager's
closeAsync
method returns.If a token is returned, the task will have run before the LifeCycleManager's
closeAsync
method returns.- returns
An com.digitalasset.canton.lifecycle.UnlessShutdown.Outcome indicates that the task will have been run when the
LifeCycleManager
'scloseAsync
method completes or whenAutoCloseable
'sclose
method returns, unless the returnedLifeCycleRegistrationHandle
was used to cancel the task or the task has been done beforehand. com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if the task is not run due to closing. This always happens if isClosing returns true.
- Definition Classes
- LifeCycleManager → HasRunOnClosing
- def runOnOrAfterClose(task: RunOnClosing)(implicit traceContext: TraceContext): LifeCycleRegistrationHandle
Register a task to run when closing is initiated, or run it immediately if closing is already ongoing.
Register a task to run when closing is initiated, or run it immediately if closing is already ongoing. Unlike runOnClose, this method does not guarantee that this task will have run by the time the
LifeCycleManager
'scloseAsync
method completes orAutoCloseable
'sclose
returns. This is because the task is run immediately if the component has already been closed.- Definition Classes
- HasRunOnClosing
- final def runOnOrAfterClose_(task: RunOnClosing)(implicit traceContext: TraceContext): Unit
Variant of runOnOrAfterClose that does not return a com.digitalasset.canton.lifecycle.LifeCycleRegistrationHandle.
Variant of runOnOrAfterClose that does not return a com.digitalasset.canton.lifecycle.LifeCycleRegistrationHandle.
- Definition Classes
- HasRunOnClosing
- def synchronizeWithClosing[A](name: String)(f: => A)(implicit traceContext: TraceContext): UnlessShutdown[A]
Runs the computation
f
only if the component is not yet closing.Runs the computation
f
only if the component is not yet closing. If so, the component will delay releasing its resources untilf
has finished or the LifeCycleManager.synchronizeWithClosingPatience has elapsed.- returns
com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if
f
has not run.
- Definition Classes
- HasSynchronizeWithClosing
- Annotations
- @SuppressWarnings()
- See also
HasRunOnClosing.isClosing
- def synchronizeWithClosingUSF[F[_], A](name: String)(f: => F[A])(implicit traceContext: TraceContext, F: Thereafter[F], A: CanAbortDueToShutdown[F]): F[A]
Runs the computation
f
only if the component is not yet closing.Runs the computation
f
only if the component is not yet closing. If so, the component will delay releasing its resources untilf
has completed (as defined by the com.digitalasset.canton.util.Thereafter instance) or the LifeCycleManager.synchronizeWithClosingPatience has elapsed.- returns
The computation completes with com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if
f
has not run. Otherwise it is the result of runningf
.
- Definition Classes
- HasSynchronizeWithClosing
- See also
HasRunOnClosing.isClosing
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def unlessClosing[F[_], A](fa: => F[A])(implicit F: CanAbortDueToShutdown[F]): F[A]
Runs the computation
fa
unless isClosing returns true.Runs the computation
fa
unless isClosing returns true.This method does not delay the closing while
fa
is running, unlike the methods inHasSynchronizeWithClosing
. Accordingly, this method is useful for intermittent checks whether the result of the computation is still relevant.- returns
The result of
fa
or com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if isClosing is true
- Definition Classes
- HasUnlessClosing
- Annotations
- @inline()
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])