Class Lifecycle
java.lang.Object
org.apache.bookkeeper.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()) {
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanbooleanbooleanclosed()Returns true if the state is closed.booleanReturns true if the state is initialized.booleanbooleanbooleanbooleanstarted()Returns true if the state is started.state()booleanstopped()Returns true if the state is stopped.booleantoString()
-
Constructor Details
-
Lifecycle
public Lifecycle()
-
-
Method Details
-
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
- Throws:
IllegalStateException
-
moveToStarted
- Throws:
IllegalStateException
-
canMoveToStopped
- Throws:
IllegalStateException
-
moveToStopped
- Throws:
IllegalStateException
-
canMoveToClosed
- Throws:
IllegalStateException
-
moveToClosed
- Throws:
IllegalStateException
-
toString
-