Packages

class LifecycleManager extends AnyRef

Manages the startup and shutdown process of a complex system.

A LifecycleManager manages instances of LifecycleComponent. The lifecycle defined by this class is very simple and not sophisticated at all:

Usage example

val lifeCycleManager = new LifecycleManager
val component1 = lifeCycleManager.component("component1")( spec =>
  spec
    .toStart({
      println("Component1 started")
    })
    .toStop({
      println("Component1 stopped")
    })
)
val component2 = lifeCycleManager.component("component2")( spec =>
  spec
    .depend(component1)
    .toStart({
      println("Component2 started")
    })
    .toStop({
      println("Component2 stopped")
    })
)
lifeCycleManager.startAndWait()
lifeCycleManager.stopAndWait()

should output:

Component1 started
Component2 started
Component2 stopped
Component1 stopped

Rules

The following rules apply:

  • All startup and shutdown operations are run asynchronously, in a user-specified scala.concurrent.ExecutionContext.
  • When no dependency is defined between two components, their startup and shutdown hooks may run concurrently.
  • When component A depends on component B, then A's startup hook will run before B's startup hook
  • When component A depends on component B, then A's shutdown hook will not run until B's shutdown hook has finished,
  • Unless the dependency was specified as LifecycleComponent.Component2DependencyOps.noKeepAlive, in which case the A's shutdown hook may run concurrently to B's shutdown hook.
Linear Supertypes
AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. LifecycleManager
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LifecycleManager()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from LifecycleManager to any2stringadd[LifecycleManager] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (LifecycleManager, B)
    Implicit
    This member is added by an implicit conversion from LifecycleManager to ArrowAssoc[LifecycleManager] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. val afterStart: Future[Unit]

    Will resolve asynchronously after all startup actions are done.

  7. val afterStop: Future[Unit]

    Will resolve asynchronously after all shutdown actions are done.

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def component(name: String)(specification: (ComponentSpec[Unspecified, Unspecified]) ⇒ ComponentSpec[Specified, Specified]): LifecycleComponent

    Create a new de.sebbraun.lifecycle.simple.LifecycleComponent that will be managed by this Manager.

    Create a new de.sebbraun.lifecycle.simple.LifecycleComponent that will be managed by this Manager.

    Usage example

    val lifeCycleManager = new LifecycleManager()
    val component = lifeCycleManager.component(<NAME>) {
      _.depend(<DEPENDENCY1>, <DEPENDENCY2>...)
       .toStart(<ACTION>)
       .toStopAsync(implicit ec => <ASYNC-ACTION>)
    }
    name

    The name of the LifecycleComponent to create.

    specification

    A function that specified dependencies and actions for this component. Only functions that specify both a start action and a stop action are accepted.

    returns

    A representation of the new component that may be used to express dependencies in other components.

    See also

    ComponentSpec

  11. def ensuring(cond: (LifecycleManager) ⇒ Boolean, msg: ⇒ Any): LifecycleManager
    Implicit
    This member is added by an implicit conversion from LifecycleManager to Ensuring[LifecycleManager] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: (LifecycleManager) ⇒ Boolean): LifecycleManager
    Implicit
    This member is added by an implicit conversion from LifecycleManager to Ensuring[LifecycleManager] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean, msg: ⇒ Any): LifecycleManager
    Implicit
    This member is added by an implicit conversion from LifecycleManager to Ensuring[LifecycleManager] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean): LifecycleManager
    Implicit
    This member is added by an implicit conversion from LifecycleManager to Ensuring[LifecycleManager] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from LifecycleManager to StringFormat[LifecycleManager] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  19. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  20. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  25. def start()(implicit ec: ExecutionContext): Future[Seq[StartupResult]]

    Triggers the startup of the LifecycleManager and of all the LifecycleComponents it manages.

    Triggers the startup of the LifecycleManager and of all the LifecycleComponents it manages.

    ec

    A user-supplied scala.concurrent.ExecutionContext in which all startup actions will run

    returns

    A Future that resolves when all components have started up. The value of the future will be an appropriate LifecycleComponent.StartupResult for every managed component.

  26. def startAndWait(timeout: Duration = Duration.Inf)(implicit ec: ExecutionContext): Seq[StartupResult]

    Triggers the startup of the LifecycleManager and waits for all startup actions to complete.

    Triggers the startup of the LifecycleManager and waits for all startup actions to complete.

    timeout

    How long to wait for the startup to finish.

    ec

    A user-supplied scala.concurrent.ExecutionContext in which all startup actions will run

    returns

    An appropriate LifecycleComponent.StartupResult for every managed component.

    See also

    LifecycleManager.start

  27. def stop()(implicit ec: ExecutionContext): Future[Seq[StopResult]]

    Triggers the shutdown of the LifecycleManager and all of the LifecycleComponents it manages.

    Triggers the shutdown of the LifecycleManager and all of the LifecycleComponents it manages.

    ec

    A user-supplied scala.concurrent.ExecutionContext in which all shutdown actions will run

    returns

    An appropriate LifecycleComponent.StopResult for every managed component.

  28. def stopAndWait(timeout: Duration = Duration.Inf)(implicit ec: ExecutionContext): Seq[StopResult]

    Triggers the shutdown of the LifecycleManager and wait for all shutdown actions to finish.

    Triggers the shutdown of the LifecycleManager and wait for all shutdown actions to finish.

    timeout

    How long to wait for shutdown to finish.

    ec

    A user-supplied scala.concurrent.ExecutionContext in which all shutdown actions will run

    returns

    An appropriate LifecycleComponent.StopResult for every managed component.

    See also

    LifecycleManager.stop

  29. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  30. def toString(): String
    Definition Classes
    AnyRef → Any
  31. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. def [B](y: B): (LifecycleManager, B)
    Implicit
    This member is added by an implicit conversion from LifecycleManager to ArrowAssoc[LifecycleManager] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from LifecycleManager to any2stringadd[LifecycleManager]

Inherited by implicit conversion StringFormat from LifecycleManager to StringFormat[LifecycleManager]

Inherited by implicit conversion Ensuring from LifecycleManager to Ensuring[LifecycleManager]

Inherited by implicit conversion ArrowAssoc from LifecycleManager to ArrowAssoc[LifecycleManager]

Component Creation

Hooks for asynchronous notification about lifecycle events

Starting and stopping the system lifecycle

Ungrouped