Package com.tccc.kos.commons.util.ready
Class ReadyBean
java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
- All Implemented Interfaces:
Ready
,ReadyListener
- Direct Known Subclasses:
AbstractConfigurable
,AbstractService
,CriticalDataSerialNumberProvider
,UdevNode
Abstract convenience base class that incorporates both the
Ready
and ReadListener
interfaces. It is for objects that want to listen to
autowired ready and then trigger their own ready. So if you have a class that
doesn't extend any other class, you can extend ReadyBean
to more easily get
this functionality.
Example
Simplest
public class MyClass extends ReadyBean {
}
Overriding ready callback method
public class MyClass extends ReadyBean {
@Override
public void onDependenciesReady() {
// Do whatever here, followed by setting the ready flag to true.
setReady();
}
}
- Since:
- 1.0
- Version:
- 2022-08-31
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetReady()
Override of theReady
interface.boolean
Override in subclasses to be notified when all dependencies are ready.void
Override of theReadyListener
interface.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Constructor Details
-
ReadyBean
public ReadyBean()
-
-
Method Details
-
getReady
Override of theReady
interface. -
onDependenciesReady
public void onDependenciesReady()Override of theReadyListener
interface. This will callonBeanReady()
and returning true will cause this bean to be marked ready. OverridingonBeanReady
is much safer as it explicitly indicates ready or not whereas overriding this method requires the caller to remember to callsuper.onDependenciesReady()
or explicitly callsetReady()
which is error prone.- Specified by:
onDependenciesReady
in interfaceReadyListener
-
onBeanReady
public boolean onBeanReady()Override in subclasses to be notified when all dependencies are ready. Return true to indicate that this bean is also ready. If the bean needs to callsetReady()
later due to some async processing, return false to preventsetReady()
from being called automatically.It is recommended to override this method rather than
onDependenciesReady()
as a majority of the time it requires callingsuper.onDependneciesReady()
or explicitly callingsetReady()
which defaults to a failure mode.- Returns:
-