Package

de.sebbraun.lifecycle

simple

Permalink

package simple

Visibility
  1. Public
  2. All

Type Members

  1. class ComponentSpec[Starter <: State, Stopper <: State] extends AnyRef

    Permalink

    A specification of the relevant information to guide component creation.

    A specification of the relevant information to guide component creation.

    Starter

    A phantom type parameter to mark whether the start action has been specified.

    Stopper

    A phantom type parameter to mark whether the stop action has been specified.

    See also

    LifecycleManager.component

  2. final class LifecycleComponent extends AnyRef

    Permalink

    A handle to the life cycle of a user-defined component.

    A handle to the life cycle of a user-defined component.

    Instances have no user-facing methods and can only be used to declare dependencies.

    LifecycleComponents are managed by a LifecycleManager. See LifecycleManager.component for how to create them.

  3. class LifecycleManager extends AnyRef

    Permalink

    Manages the startup and shutdown process of a complex system.

    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.

Value Members

  1. object ComponentSpec

    Permalink
  2. object LifecycleComponent

    Permalink
  3. object LifecycleManager

    Permalink

Ungrouped