java.lang.Object
org.elasticsearch.common.component.Lifecycle
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() == false) {
      return;
  }
 // continue with stop logic
 }
 
 NOTE: The Lifecycle class is thread-safe. It is also possible to prevent concurrent state transitions by locking on the Lifecycle object itself. This is typically useful when chaining multiple transitions.
 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. A lock of the lifecycleState object is taken so that
 another thread cannot move the state from STOPPED to STARTED before it has moved to
 CLOSED.
 
 public void close() {
  synchronized (lifecycleState) {
      if (lifecycleState.started()) {
          stop();
      }
      if (lifecycleState.moveToClosed() == false) {
          return;
      }
  }
  // perform close logic here
 }
 - 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanbooleanbooleanbooleanclosed()Returnstrueif the state is closed.booleanReturnstrueif the state is initialized.booleanbooleanbooleanbooleanstarted()Returnstrueif the state is started.state()booleanstopped()Returnstrueif the state is stopped.booleantoString()
- 
Constructor Details- 
Lifecyclepublic Lifecycle()
 
- 
- 
Method Details- 
state
- 
initializedpublic boolean initialized()Returnstrueif the state is initialized.
- 
startedpublic boolean started()Returnstrueif the state is started.
- 
stoppedpublic boolean stopped()Returnstrueif the state is stopped.
- 
closedpublic boolean closed()Returnstrueif the state is closed.
- 
stoppedOrClosedpublic boolean stoppedOrClosed()
- 
canMoveToStarted- Throws:
- IllegalStateException
 
- 
moveToStarted- Throws:
- IllegalStateException
 
- 
canMoveToStopped- Throws:
- IllegalStateException
 
- 
moveToStopped- Throws:
- IllegalStateException
 
- 
canMoveToClosed- Throws:
- IllegalStateException
 
- 
moveToClosed- Throws:
- IllegalStateException
 
- 
toString
 
-