Interface ReadyAndReadyListener
- All Superinterfaces:
Ready,ReadyListener
- All Known Implementing Classes:
AbstractConfigurable,AbstractConfigurableService,AbstractService,AnalyticsClient,AnalyticsServer,ApiClient,AppService,AssemblyService,BrokerClient,BrowserService,ConfigSerialNumberProvider,ConfigServer,ConfigService,CriticalDataSerialNumberProvider,CriticalDataService,DeviceService,ExtensionService,FirmwareService,FuseService,HandleService,HardwareService,KeyValService,LocalizationService,LogServer,LogService,ManifestService,NetworkService,NodeMgrService,NodeResolverService,OTAService,ReadyBean,RegionService,SerialService,SpawnService,StateService,StorageService,TimeService,TroubleService,UdevNode,UdevService,UpdateService
Ready and ReadyListener to allow an object
to be notified when all dependencies are ready (ReadyListener) and notify
all upstream objects that this object is Ready. When used with
BeanContext, KOS will automatically manage object dependencies based on
readiness. For example, any local properties of this object annotated with
@Autowired or @WhenReady will be considered dependencies relative
to the ReadyListener interface.
This interface also simplifies the combination of Ready and ReadyListener
by chaining them together through onBeanReady(). While onDependenciesReady()
requires the user to explicitly call setReady(), this interface will automatically
chain onDependenciesReady() to setReady() via the onBeanReady()
callback. If not overridden, onBeanReady() simply calls setReady(),
effectively completing the readiness dependency chain by default. Developers can
override onBeanReady() to perform any local initialization and return true
to indicate the object is now ready, or return false and explicitly call setReady()
at a later time when the object is finished initializing.
- Since:
- 1.0
- Version:
- 2022-08-31
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanOverride in subclasses to be notified when all dependencies are ready.default voidOverride of theReadyListenerinterface.Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Method Details
-
onDependenciesReady
default void onDependenciesReady()Override of theReadyListenerinterface. This will callonBeanReady()and returning true will cause this bean to be marked ready. OverridingonBeanReadyis 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:
onDependenciesReadyin interfaceReadyListener
-
onBeanReady
default 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:
- true if this object is now ready
-