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

public interface ReadyAndReadyListener extends Ready, ReadyListener
Interface that combines 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 Type
    Method
    Description
    default boolean
    Override in subclasses to be notified when all dependencies are ready.
    default void
    Override of the ReadyListener interface.

    Methods inherited from interface com.tccc.kos.commons.util.ready.Ready

    getReady, isReady, setReady

    Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener

    onDependenciesGroupReady
  • Method Details

    • onDependenciesReady

      default void onDependenciesReady()
      Override of the ReadyListener interface. This will call onBeanReady() and returning true will cause this bean to be marked ready. Overriding onBeanReady is much safer as it explicitly indicates ready or not whereas overriding this method requires the caller to remember to call super.onDependenciesReady() or explicitly call setReady() which is error prone.
      Specified by:
      onDependenciesReady in interface ReadyListener
    • 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 call setReady() later due to some async processing, return false to prevent setReady() from being called automatically.

      It is recommended to override this method rather than onDependenciesReady() as a majority of the time it requires calling super.onDependneciesReady() or explicitly calling setReady() which defaults to a failure mode.

      Returns:
      true if this object is now ready