Class Lifecycle
- java.lang.Object
-
- org.apache.bookkeeper.common.component.Lifecycle
-
public class Lifecycle extends java.lang.ObjectLifecycle 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 }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLifecycle.StateLifecycle State.
-
Constructor Summary
Constructors Constructor Description Lifecycle()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanMoveToClosed()booleancanMoveToStarted()booleancanMoveToStopped()booleanclosed()Returns true if the state is closed.booleaninitialized()Returns true if the state is initialized.booleanmoveToClosed()booleanmoveToStarted()booleanmoveToStopped()booleanstarted()Returns true if the state is started.Lifecycle.Statestate()booleanstopped()Returns true if the state is stopped.booleanstoppedOrClosed()java.lang.StringtoString()
-
-
-
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 java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
moveToStarted
public boolean moveToStarted() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
canMoveToStopped
public boolean canMoveToStopped() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
moveToStopped
public boolean moveToStopped() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
canMoveToClosed
public boolean canMoveToClosed() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
moveToClosed
public boolean moveToClosed() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-