Class ReadyBean

java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
All Implemented Interfaces:
Ready, ReadyListener
Direct Known Subclasses:
AbstractConfigurable, AbstractService, CriticalDataSerialNumberProvider, UdevNode

public abstract class ReadyBean extends Object implements Ready, ReadyListener
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 Details

    • ReadyBean

      public ReadyBean()
  • Method Details

    • getReady

      public ReadyIndicator getReady()
      Override of the Ready interface.
      Specified by:
      getReady in interface Ready
      Returns:
      the ReadyIndicator object
    • onDependenciesReady

      public 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

      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 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: