Package com.tccc.kos.commons.util.ready
Class ReadyIndicator
java.lang.Object
com.tccc.kos.commons.util.ready.ReadyIndicator
Class used by Ready beans to indicate when the bean has become ready.
- Since:
- 1.0
- Version:
- 2022-08-30
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a state object that must be marked ready before the indicator is ready.boolean
isReady()
Indicates if the attached bean is ready or not.boolean
isReady
(ReadyCallback callback) Determines if the given callback is ready to be called or not.void
void
setReady()
Call this method to indicate that the indicator is ready.void
setStateReady
(Object state) Call this method to indicate that the specified state is ready, wherestate
corresponds to aaddState(state)
call.void
Block the caller until ready.void
whenReady
(ReadyCallback callback) Calls the specified callback when ready.
-
Constructor Details
-
ReadyIndicator
public ReadyIndicator()
-
-
Method Details
-
addState
Add a state object that must be marked ready before the indicator is ready. Every specified state object must have a corresponding call tosetStateReady(state)
, in addition to the standard call tosetReady()
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 fromBeanContext
when all dependencies are ready, in addition to some internal initialization process completes, which callssetStateReady(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 callingaddState()
then the indicator will be marked ready which will:- Set the ready flag to
true
- Call the
onReady()
method on each callback object - Clear the list of callbacks
setReady()
has been called. - Set the ready flag to
-
setStateReady
Call this method to indicate that the specified state is ready, wherestate
corresponds to aaddState(state)
call. This will remove the state from the pending list of states for this indicator. If this is the last state andsetReady()
has already been called, the indicator will be marked ready which will:- Set the ready flag to
true
- Call the
onReady()
method on each callback object - Clear the list of callbacks
setReady()
has not been called, this will simply return after removing the state from the pending list. - Set the ready flag to
-
processReady
public void processReady() -
isReady
public boolean isReady()Indicates if the attached bean is ready or not.- Returns:
true
if this bean is ready, otherwisefalse
-
isReady
Determines if the given callback is ready to be called or not.- Returns:
true
if ready; if not, add the givencallback
to the list
-
whenReady
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.
-