Package org.eclipse.hono.util
Class LifecycleStatus
java.lang.Object
org.eclipse.hono.util.LifecycleStatus
Tracks the states that a component goes through during its life cycle.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The state in a component's life cycle. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOnStartedHandler
(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Adds a handler to be notified once the tracked component has started up.void
addOnStoppedHandler
(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Adds a handler to be notified once the tracked component has shut down.boolean
Checks if the component is started.boolean
Checks if the component is in the process of starting up.boolean
Checks if the component is stopped.boolean
Checks if the component is in the process of shutting down.io.vertx.core.Future<Void>
runStopAttempt
(Supplier<io.vertx.core.Future<Void>> stopAction) Executes an attempt to stop the tracked component.boolean
Marks the tracked component as being started up.boolean
Marks the tracked component as being in the process of starting up.boolean
Marks the tracked component as being shut down.boolean
setStopped
(io.vertx.core.AsyncResult<Void> outcome) Marks the tracked component as being shut down.boolean
Marks the tracked component as being in the process of shutting down.
-
Constructor Details
-
LifecycleStatus
public LifecycleStatus()
-
-
Method Details
-
addOnStartedHandler
Adds a handler to be notified once the tracked component has started up.The handlers will be invoked with a succeeded result when the
setStarted()
method is called.- Parameters:
handler
- The handler.
-
addOnStoppedHandler
Adds a handler to be notified once the tracked component has shut down.The handlers will be invoked with the outcome passed in to the
setStopped(AsyncResult)
method.- Parameters:
handler
- The handler.
-
setStarting
public boolean setStarting()Marks the tracked component as being in the process of starting up.- Returns:
false
if the component is not in stateLifecycleStatus.Status.STOPPED
.
-
isStarting
public boolean isStarting()Checks if the component is in the process of starting up.- Returns:
true
if the current status isLifecycleStatus.Status.STARTING
.
-
setStarted
public boolean setStarted()Marks the tracked component as being started up.- Returns:
false
if the component is neither in stateLifecycleStatus.Status.STOPPED
norLifecycleStatus.Status.STARTING
.
-
isStarted
public boolean isStarted()Checks if the component is started.- Returns:
true
if the current status isLifecycleStatus.Status.STARTED
.
-
setStopping
public boolean setStopping()Marks the tracked component as being in the process of shutting down.- Returns:
false
if the component is neither in stateSTARTING
norSTARTED
.
-
runStopAttempt
Executes an attempt to stop the tracked component.This method will execute the given stop action once if the component is in state
LifecycleStatus.Status.STARTING
orLifecycleStatus.Status.STARTED
. The future returned by the stop action is then passed in to thesetStopped(AsyncResult)
method to transition the status toLifecycleStatus.Status.STOPPED
.Note that if this method is invoked concurrently, then only the first invocation's stop action will be run and its outcome will determine the returned future's completion status.
- Parameters:
stopAction
- The logic implementing the stopping of the component.- Returns:
- A future for conveying the outcome of stopping the component to client code.
The future will be succeeded if the component is already in the
LifecycleStatus.Status.STOPPED
state. Otherwise, the future will be completed with the result returned by the stop action. - Throws:
NullPointerException
- if stop action isnull
.
-
isStopping
public boolean isStopping()Checks if the component is in the process of shutting down.- Returns:
true
if the current status isLifecycleStatus.Status.STOPPING
.
-
setStopped
public boolean setStopped()Marks the tracked component as being shut down.Simply invokes
setStopped(AsyncResult)
with a succeeded future.- Returns:
false
if the component is already in stateSTOPPED
.
-
setStopped
Marks the tracked component as being shut down.- Parameters:
outcome
- The outcome of stopping the component. The handlers registered viaaddOnStoppedHandler(Handler)
will be invoked with the given result.- Returns:
false
if the component is already in stateSTOPPED
.
-
isStopped
public boolean isStopped()Checks if the component is stopped.- Returns:
true
if the current status isLifecycleStatus.Status.STOPPED
.
-