Interface Loadable

All Known Implementing Classes:
Application, Assembly, SystemApplication

public interface Loadable
Interface for beans that are dynamically loaded and have require lifecycles to prepare them. This provides a standardized set of lifecycles for these types of beans so that developers have standard patterns to follow. A Loadable bean is always associated with a service that manages the bean. The service is responsible for calling the lifecycle events and is free to implement any required policy during the lifecycle, but should generally adhere to the standard semantics outlined below:

The general start lifecycle flow is as follows:

  • bean constructor : A new bean instance is created, but there are no expectations about what operations are performed in the constructor.
  • service registration : The bean is registered with the service in some way. The service should prepare the bean instance for use, such as autowiring the bean if applicable.
  • bean.load() : Allow the bean to create any additional resources. Since the bean has already been prepared by the service, it may have access to external services that are not available from the constructor. This phase allows the bean to create internal resources that can then be prepared for use by the service. For example, this phase may create objects that require autowiring or configuration before they are usable. Rather than force the bean developer to perform all of these operations within the bean, the service can provide these services before calling start().
  • service prepare bean resources: Autowire / configure / etc... the bean contents as applicable for the service use case. The intention is that any bean resources are usable before calling start().
  • bean.start() : Allow the bean to use the resources from install() to finish setup of the bean. The semantics of start() is that the bean ready for use by the time start() returns. That is, this bean is prepared to interact with external code without suffering from any initialization related failures.
  • service enables bean : With the bean fully configured and usable, the service can make the bean externally visible and/or available for standard service related operations. For example, if the bean exposes endpoints, the endpoints can be enabled for use.
  • bean.started() : Notify the bean that all service related operations are complete and the bean is fully integrated into the running system. This allows the bean to initiate any operations that require service integration to be complete.

The general stop lifecycle flow is as follows:

  • service stop : Service is notified that the bean should be stopped. The service should isolate the bean so that no future interactions can reach the bean. For example, if the bean has endpoints, they should be disabled. If the bean is returned in a list, it should be removed from the list.
  • bean.stop() : Notify the bean that it is being stopped so it can cleanup any processes that interact with external components. This may be removing listeners, shutting down threads / timers, and so on. The bean should be isolated so it doesn't receive any external input and doesn't generate any outbound operations. Depending on the service needs, a stopped bean may be started again so the developer may need to handle this use case.
  • service unregister : If unloading the bean (vs. stopping with the intent to restart), the service should perform any additional actions that are beyond stopping the bean.
  • bean.unload() : The bean should cleanup all resources it currently owns in preparation for garbage collection.
service release : Any final service cleanup is performed and the bean is left for garbage collection.
Since:
1.0
Version:
2023-11-11
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called by the associated service to notify the bean that is should create any additional internal resources that will be prepared by the service (autowired, configured, etc...).
    void
    Called by the associated service to notify the bean that the bean resources have been prepared and the bean can use them to continue initialization.
    default void
    Called after the associated service has finished processing the start event for the bean.
    void
    Called to stop the bean.
    void
    Called when the bean is to be unloaded from memory.
  • Method Details

    • load

      void load() throws Exception
      Called by the associated service to notify the bean that is should create any additional internal resources that will be prepared by the service (autowired, configured, etc...).
      Throws:
      Exception
    • start

      void start() throws Exception
      Called by the associated service to notify the bean that the bean resources have been prepared and the bean can use them to continue initialization. When this method returns, the bean should be ready for use.
      Throws:
      Exception
    • started

      default void started() throws Exception
      Called after the associated service has finished processing the start event for the bean. This notifies the bean that it is free to start an processes that require full integration into the controlling service.
      Throws:
      Exception
    • stop

      void stop() throws Exception
      Called to stop the bean. Depending on the associated service, this may be followed by a call to start() or unload() . This should shutdown the bean such that it no longer generates any interactions with external code.
      Throws:
      Exception
    • unload

      void unload() throws Exception
      Called when the bean is to be unloaded from memory. All internal resources that will not be cleaned up via simple garbage collection must be freed.
      Throws:
      Exception