Class Lifecycle

java.lang.Object
org.apache.bookkeeper.common.component.Lifecycle

public class Lifecycle extends Object
Lifecycle state. Allows the following transitions:
  • INITIALIZED -> STARTED, STOPPED, CLOSED
  • STARTED -> STOPPED
  • STOPPED -> STARTED, CLOSED
  • CLOSED ->

Also allows to stay in the same state. For example, when calling stop on a component, the following logic can be applied:

 public void stop() {
  if (!lifecycleState.moveToStopped()) {
      return;
  }
 // continue with stop logic
 }
 

Note, closed is only allowed to be called when stopped, so make sure to stop the component first. Here is how the logic can be applied:

 public void close() {
  if (lifecycleState.started()) {
      stop();
  }
  if (!lifecycleState.moveToClosed()) {
      return;
  }
  // perform close logic here
 }