org.elasticsearch.common.component
Class Lifecycle

java.lang.Object
  extended by org.elasticsearch.common.component.Lifecycle

public class Lifecycle
extends Object

Lifecycle state. Allows the following transitions:

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 (!lifeccycleState.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;
  }
  // perofrm close logic here
 }
 


Nested Class Summary
static class Lifecycle.State
           
 
Constructor Summary
Lifecycle()
           
 
Method Summary
 boolean canMoveToClosed()
           
 boolean canMoveToStarted()
           
 boolean canMoveToStopped()
           
 boolean closed()
          Returns true if the state is closed.
 boolean initialized()
          Returns true if the state is initialized.
 boolean moveToClosed()
           
 boolean moveToStarted()
           
 boolean moveToStopped()
           
 boolean started()
          Returns true if the state is started.
 Lifecycle.State state()
           
 boolean stopped()
          Returns true if the state is stopped.
 boolean stoppedOrClosed()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Lifecycle

public Lifecycle()
Method Detail

state

public Lifecycle.State state()

initialized

public boolean initialized()
Returns true if the state is initialized.


started

public boolean started()
Returns true if the state is started.


stopped

public boolean stopped()
Returns true if the state is stopped.


closed

public boolean closed()
Returns true if the state is closed.


stoppedOrClosed

public boolean stoppedOrClosed()

canMoveToStarted

public boolean canMoveToStarted()
                         throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

moveToStarted

public boolean moveToStarted()
                      throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

canMoveToStopped

public boolean canMoveToStopped()
                         throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

moveToStopped

public boolean moveToStopped()
                      throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

canMoveToClosed

public boolean canMoveToClosed()
                        throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

moveToClosed

public boolean moveToClosed()
                     throws ElasticSearchIllegalStateException
Throws:
ElasticSearchIllegalStateException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2012. All Rights Reserved.