Class LifecycleStatus

java.lang.Object
org.eclipse.hono.util.LifecycleStatus

public final class LifecycleStatus extends Object
Tracks the states that a component goes through during its life cycle.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The state in a component's life cycle.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LifecycleStatus

      public LifecycleStatus()
  • Method Details

    • addOnStartedHandler

      public void addOnStartedHandler(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)
      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

      public 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.

      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 state LifecycleStatus.Status.STOPPED.
    • isStarting

      public boolean isStarting()
      Checks if the component is in the process of starting up.
      Returns:
      true if the current status is LifecycleStatus.Status.STARTING.
    • setStarted

      public boolean setStarted()
      Marks the tracked component as being started up.
      Returns:
      false if the component is neither in state LifecycleStatus.Status.STOPPED nor LifecycleStatus.Status.STARTING.
    • isStarted

      public boolean isStarted()
      Checks if the component is started.
      Returns:
      true if the current status is LifecycleStatus.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 state STARTING nor STARTED.
    • runStopAttempt

      public io.vertx.core.Future<Void> runStopAttempt(Supplier<io.vertx.core.Future<Void>> stopAction)
      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 or LifecycleStatus.Status.STARTED. The future returned by the stop action is then passed in to the setStopped(AsyncResult) method to transition the status to LifecycleStatus.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 is null.
    • isStopping

      public boolean isStopping()
      Checks if the component is in the process of shutting down.
      Returns:
      true if the current status is LifecycleStatus.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 state STOPPED.
    • setStopped

      public boolean setStopped(io.vertx.core.AsyncResult<Void> outcome)
      Marks the tracked component as being shut down.
      Parameters:
      outcome - The outcome of stopping the component. The handlers registered via addOnStoppedHandler(Handler) will be invoked with the given result.
      Returns:
      false if the component is already in state STOPPED.
    • isStopped

      public boolean isStopped()
      Checks if the component is stopped.
      Returns:
      true if the current status is LifecycleStatus.Status.STOPPED.