Class AppService

All Implemented Interfaces:
CtxEventListener, ContextHandleAware, HandleAware, Ready, ReadyListener

public final class AppService extends AbstractService
Service that manages applications within kOS.
Since:
1.0
Version:
2023-03-06
  • Field Details

  • Method Details

    • onDependenciesReady

      public void onDependenciesReady()
      Description copied from class: ReadyBean
      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
      Overrides:
      onDependenciesReady in class ReadyBean
    • loadApp

      public AppLoader loadApp(KabFile kab, Application<?> parent)
      Attempts to load the specified application. The specified KAB must contain a properly formed kos.app section in the descriptor. Typically applications are packaged in kabs of type "kos.app" but this is not required unless they are part of kos.app.* or kos.autostart.* sections.

      If a parent application is specified, the new application class loader and bean context will use the parent application class loader and bean context as parents. This allows the new application to access classes and beans from the parent application.

      The resulting loader can be used to start the app by calling loader.start() . This allows the application context to be modified before the application is started, which is an effective way to pass data to an application.

      Parameters:
      kab - the application KAB
      parent - optional parent application
      Returns:
      AppLoader used to start the app
    • loadApp

      public AppLoader loadApp(KabFile kab, Application<?> parent, Collection<Object> beans)
      Attempts to load the specified application. The specified KAB must contain a properly formed kos.app section in the descriptor. Typically applications are packaged in kabs of type "kos.app" but this is not required unless they are part of kos.app.* or kos.autostart.* sections.

      If a parent application is specified, the new application class loader and bean context will use the parent application class loader and bean context as parents. This allows the new application to access classes and beans from the parent application.

      The resulting loader can be used to start the app by calling loader.start() . This allows the application context to be modified before the application is started, which is an effective way to pass data to an application.

      This allows a collection of beans to be specified. These beans will be added to the BeanContext of the application before it is configured. This allows passing beans to a an application and by autowiring them within the application.

      Parameters:
      kab - the application KAB
      parent - optional parent application
      beans - optional connection of beans to add to the app context
      Returns:
      AppLoader used to start the app
    • unloadApp

      public void unloadApp(AppLoader loader)
      Unloads the application associated with the given loader.
    • getAutostartAppsReady

      public ReadyIndicator getAutostartAppsReady()
      Return a ReadyIndicator that is ready once all autostart applications are started.
    • getAutostartApps

      public Collection<LoadableApp> getAutostartApps()
      Return the list of auto-started applications from the manifest. These are defined in sections with a "kos.autostart." prefix.
    • getApps

      public Collection<LoadableApp> getApps()
      Return the list of discovered applications in the manifest. These includes every kab of type kos.app , regardless of the section they are in.
    • whenAppStarted

      public void whenAppStarted(String appId, AppStartedCallback callback)
      Call the specified callback when the requested appId is started. If already started, this will be called immediately. This will only be called once. If the application unloads and reloads it will not be called again. This is a convenience method which is a simple alternative to implementing AppListener .