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.
- Grouped
- Alphabetic
- By Inheritance
- LifecycleManager
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
- new LifecycleManager()
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
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
-
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()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
val
afterStart: Future[Unit]
Will resolve asynchronously after all startup actions are done.
-
val
afterStop: Future[Unit]
Will resolve asynchronously after all shutdown actions are done.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
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
-
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
-
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
-
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
-
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
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
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()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
start()(implicit ec: ExecutionContext): Future[Seq[StartupResult]]
Triggers the startup of the
LifecycleManagerand of all the LifecycleComponents it manages.Triggers the startup of the
LifecycleManagerand 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.
-
def
startAndWait(timeout: Duration = Duration.Inf)(implicit ec: ExecutionContext): Seq[StartupResult]
Triggers the startup of the
LifecycleManagerand waits for all startup actions to complete.Triggers the startup of the
LifecycleManagerand 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
-
def
stop()(implicit ec: ExecutionContext): Future[Seq[StopResult]]
Triggers the shutdown of the
LifecycleManagerand all of the LifecycleComponents it manages.Triggers the shutdown of the
LifecycleManagerand 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.
-
def
stopAndWait(timeout: Duration = Duration.Inf)(implicit ec: ExecutionContext): Seq[StopResult]
Triggers the shutdown of the
LifecycleManagerand wait for all shutdown actions to finish.Triggers the shutdown of the
LifecycleManagerand 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
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
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