Class Assembly

java.lang.Object
com.tccc.kos.core.service.assembly.Assembly
All Implemented Interfaces:
HandleAware, JsonDescriptorAware, Loadable

public abstract class Assembly extends Object implements Loadable, HandleAware, JsonDescriptorAware
An assembly is used to describe a collection of hardware that can be added or removed as an atomic unit within kOS. This provides an atomic way to process hardware changes, which reduces race conditions and provides a pluggable system for adding new elements to an assembly.

Typically, an assembly includes all the hardware in a particular device and the system application adds the assembly as part of the startup process. This allows a single system app to define multiple supported device models by simply defining multiple assemblies and only installing the one that matches the actual hardware.

Assemblies are also intended for use in supporting optional expansion hardware. If a device supports another collection of hardware as an add-on or expansion kit, a corresponding assembly can be added for that expansion and removed if the kit is removed.

An assembly has a series of lifecycle callbacks that facilitate installation and removal of the assembly. The constructor is expected to create all the core objects in the assembly. When passed to AssemblyService to be installed, the handles for all objects in the context are set and any ConfigAware objects are configured before calling the assembly install() method. This allows the install() method to operate on all the objects that have already been autowired and configured.

Since:
1.0
Version:
2023-01-19
  • Constructor Details

    • Assembly

      public Assembly(String name, JsonDescriptor descriptor)
      Create a new assembly with the specified name.
      Parameters:
      name - name of the assembly
  • Method Details

    • addBoard

      public void addBoard(Board board)
      Add a board to the assembly
    • isCore

      public boolean isCore()
      Returns true if this is the core assembly.
    • getCtx

      public BeanContext getCtx()
      Returns the context for this assembly. This context will have the system application context as a parent.
    • addToCtx

      public void addToCtx(Object bean)
      Adds the given bean to the assembly context.
      Parameters:
      bean - the bean to add to the context
    • connect

      public void connect(Object bean)
      Autowires the given bean using the context, without actually adding it to the context. If this is called during load() then the connect will be deferred until start() is called. This ensures that all autowired dependencies are available before connecting.
      Parameters:
      bean - the bean to autowire
    • getBeans

      public <T> List<T> getBeans(Class<T> clazz)
      Returns a list of beans from the assembly context of the specified type. This only searches the assembly context. This allows quick access to beans in the assembly without having to track them as object properties.
    • load

      public abstract void load() throws Exception
      Callback to load the assembly.
      Specified by:
      load in interface Loadable
      Throws:
      Exception
    • start

      public abstract void start() throws Exception
      Callback during the installation phase. Any beans created during the load() callback are configured and have valid handles.
      Specified by:
      start in interface Loadable
      Throws:
      Exception
    • started

      public void started()
      Called after install completes and the assembly has been added to the device. Override as needed.
      Specified by:
      started in interface Loadable
    • stop

      public void stop() throws Exception
      Called when uninstalled from the device. Cleanup all the resources for the assembly. This will be called before any listener callbacks. Any resources that need to exist for these callbacks can be cleaned up in unload() .
      Specified by:
      stop in interface Loadable
      Throws:
      Exception
    • unload

      public void unload() throws Exception
      Release all resources from the assembly in preparation for garbage collection. Override as needed.
      Specified by:
      unload in interface Loadable
      Throws:
      Exception
    • getHandle

      public Handle getHandle()
      Description copied from interface: HandleAware
      Returns the handle for this bean. This is used by the context to compute the opaque handle for the object.
      Specified by:
      getHandle in interface HandleAware
      Returns:
      the handle node for the bean
    • isInstalling

      public boolean isInstalling()
    • getDescriptor

      public JsonDescriptor getDescriptor()
      Description copied from interface: JsonDescriptorAware
      Return the associated JsonDescriptor.
      Specified by:
      getDescriptor in interface JsonDescriptorAware
    • getBoards

      public List<Board> getBoards()