public class LifeCycle extends Object
------------------------------------------------- | -------------------------------- | | | ------------------------ | | | | | | | | | | PAUSED <---- PAUSING---- | | | | | | ^ | | | | | | | V | | V V V V NEW --> STARTING --> RUNNING --|--> CLOSING --> [CLOSED] ^ | | | | ^ | | | V V | ------- -------> EXCEPTION -----
| Modifier and Type | Class and Description |
|---|---|
static class |
LifeCycle.State
The states in the life cycle.
|
static class |
LifeCycle.States |
| Modifier and Type | Field and Description |
|---|---|
static org.slf4j.Logger |
LOG |
| Modifier and Type | Method and Description |
|---|---|
<T extends Throwable> |
assertCurrentState(BiFunction<String,LifeCycle.State,T> newThrowable,
Set<LifeCycle.State> expected)
Assert if the current state equals to one of the expected states.
|
void |
assertCurrentState(Set<LifeCycle.State> expected)
Assert if the current state equals to one of the expected states.
|
LifeCycle.State |
checkStateAndClose()
Check the current state and, if applicable, transit to
LifeCycle.State.CLOSING. |
<T extends Throwable> |
checkStateAndClose(CheckedRunnable<T> closeMethod)
Check the current state and, if applicable, run the given close method.
|
boolean |
compareAndTransition(LifeCycle.State from,
LifeCycle.State to)
If the current state is equal to the specified from state,
then transition to the give to state; otherwise, make no change.
|
LifeCycle.State |
getCurrentState() |
void |
setName(String name) |
<T extends Throwable> |
startAndTransition(CheckedRunnable<T> startImpl,
Class<? extends Throwable>... exceptionClasses)
Run the given start method and transition the current state accordingly.
|
String |
toString() |
void |
transition(LifeCycle.State to)
Transition from the current state to the given state.
|
LifeCycle.State |
transition(UnaryOperator<LifeCycle.State> operator)
Transition using the given operator.
|
LifeCycle.State |
transitionAndGet(UnaryOperator<LifeCycle.State> operator)
Transition using the given operator.
|
void |
transitionIfNotEqual(LifeCycle.State to)
Transition from the current state to the given state if the current state is not equal to the given state.
|
boolean |
transitionIfValid(LifeCycle.State to)
Transition from the current state to the given state only if the transition is valid.
|
public LifeCycle(Object name)
public void setName(String name)
public void transition(LifeCycle.State to)
public void transitionIfNotEqual(LifeCycle.State to)
public boolean transitionIfValid(LifeCycle.State to)
public LifeCycle.State transition(UnaryOperator<LifeCycle.State> operator)
public LifeCycle.State transitionAndGet(UnaryOperator<LifeCycle.State> operator)
public boolean compareAndTransition(LifeCycle.State from, LifeCycle.State to)
public LifeCycle.State getCurrentState()
public void assertCurrentState(Set<LifeCycle.State> expected)
public <T extends Throwable> LifeCycle.State assertCurrentState(BiFunction<String,LifeCycle.State,T> newThrowable, Set<LifeCycle.State> expected) throws T extends Throwable
T extends Throwable@SafeVarargs public final <T extends Throwable> void startAndTransition(CheckedRunnable<T> startImpl, Class<? extends Throwable>... exceptionClasses) throws T extends Throwable
T extends Throwablepublic LifeCycle.State checkStateAndClose()
LifeCycle.State.CLOSING.
If this is already in LifeCycle.State.CLOSING or LifeCycle.State.CLOSED,
then invoking this method has no effect.
In other words, this method can be safely called multiple times.public <T extends Throwable> LifeCycle.State checkStateAndClose(CheckedRunnable<T> closeMethod) throws T extends Throwable
LifeCycle.State.CLOSING or LifeCycle.State.CLOSED,
then invoking this method has no effect.
In other words, this method can be safely called multiple times
while the given close method will only be executed at most once.T extends ThrowableCopyright © 2017–2022 The Apache Software Foundation. All rights reserved.