Class ReadyIndicator

java.lang.Object
com.tccc.kos.commons.util.ready.ReadyIndicator

public class ReadyIndicator extends Object
Class used by Ready beans to indicate when the bean has become ready.
Since:
1.0
Version:
2022-08-30
See Also:
  • Constructor Details

    • ReadyIndicator

      public ReadyIndicator()
  • Method Details

    • addState

      public void addState(Object state)
      Add a state object that must be marked ready before the indicator is ready. Every specified state object must have a corresponding call to setStateReady(state) , in addition to the standard call to setReady() for this indicator to become ready.

      This is useful for objects that should only become ready when their normal setReady() call has been made, such as when called from BeanContext when all dependencies are ready, in addition to some internal initialization process completes, which calls setStateReady(state) . This allows any number of states to be defines before the object becomes ready.

      Calls to addState() must occur before the indicator is ready to have any effect.

    • setReady

      public void setReady()
      Call this method to indicate that the indicator is ready. If there are no pending states from calling addState() then the indicator will be marked ready which will:
      1. Set the ready flag to true
      2. Call the onReady() method on each callback object
      3. Clear the list of callbacks
      If any states are still waiting to be marked ready, this will simply return after tracking that setReady() has been called.
    • setStateReady

      public void setStateReady(Object state)
      Call this method to indicate that the specified state is ready, where state corresponds to a addState(state) call. This will remove the state from the pending list of states for this indicator. If this is the last state and setReady() has already been called, the indicator will be marked ready which will:
      1. Set the ready flag to true
      2. Call the onReady() method on each callback object
      3. Clear the list of callbacks
      If any states are still waiting to be marked ready, or setReady() has not been called, this will simply return after removing the state from the pending list.
    • processReady

      public void processReady()
    • isReady

      public boolean isReady()
      Indicates if the attached bean is ready or not.
      Returns:
      true if this bean is ready, otherwise false
    • isReady

      public boolean isReady(ReadyCallback callback)
      Determines if the given callback is ready to be called or not.
      Returns:
      true if ready; if not, add the given callback to the list
    • whenReady

      public void whenReady(ReadyCallback callback)
      Calls the specified callback when ready. If already ready, then the callback is called immediately, otherwise it will be called when the indicator becomes ready.
    • waitUntilReady

      public void waitUntilReady()
      Block the caller until ready.