Class Assembly
- All Implemented Interfaces:
HandleAware,JsonDescriptorAware,Loadable
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
- Version:
- 9
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new assembly with the specified name, using the system app as the parent context.Assembly(String name, BeanContext parentCtx) Create a new assembly with the specified name and parent context.Assembly(String name, Application<?> app) Create a new assembly with the specified name, using the specified app as the parent context. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an object to the assembly.voidDeprecated.voidAdds the given bean to the assembly context.voidAutowires the given bean using the context, without actually adding it to the context.<T> List<T>Returns a list of beans from the assembly context of the specified type.Return the boards in the assembly.getCtx()Returns the context for this assembly.Return the associated JsonDescriptor.Returns the handle for this bean.booleanisCore()Returns true if this is the core assembly.booleanbooleanabstract voidload()Callback to load the assembly.voidsetDescriptor(JsonDescriptor descriptor) Set an optional descriptor for the assembly.abstract voidstart()Callback during the installation phase.voidstarted()Called after install completes and the assembly has been added to the device.voidstop()Called when uninstalled from the device.voidunload()Release all resources from the assembly in preparation for garbage collection.voidwhenInstalled(AssemblyInstallCallback callback) Call the specified callback when the assembly is fully installed.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.kosdev.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
-
Constructor Details
-
Assembly
Create a new assembly with the specified name, using the system app as the parent context.- Parameters:
name- name of the assembly- Since:
- 6
-
Assembly
Create a new assembly with the specified name, using the specified app as the parent context.- Parameters:
name- name of the assembly- Since:
- 8
-
Assembly
Create a new assembly with the specified name and parent context.- Parameters:
name- name of the assemblyparentCtx- the parent context for the assembly- Since:
- 8
-
-
Method Details
-
setDescriptor
Set an optional descriptor for the assembly. This allows meta data to be included with the assembly to provide additional application-specific data without needing to extend theAssemblyclass.- Since:
- 1
-
add
Add an object to the assembly. This is a generic add method that operates on any object. Subclasses ofAssemblycan override this (making sure to callsuper.add()and process objects that are of interest to the assembly. This allows certain core classes to take an assembly as a constructor argument and having the constructor calladd(). This eliminates the need for users to know that they have to add objects to the assembly.The base
Assemblyclass tracksBoardobjects and will connect them to the assembly context during the add operation.- Parameters:
obj- the object to add- Since:
- 9
-
addBoard
Deprecated.Add a board to the assembly. This exists for backward compatibility and simply callsadd(board). There is no need to manually add boards as theBoardconstructor takes anAssemblyand adds the board automatically viaadd().- Since:
- 1
-
getBoards
Return the boards in the assembly.- Since:
- 9
-
isCore
public boolean isCore()Returns true if this is the core assembly. -
getCtx
Returns the context for this assembly. This context will have the system application context as a parent.- Since:
- 1
-
addToCtx
Adds the given bean to the assembly context.- Parameters:
bean- the bean to add to the context- Since:
- 1
-
connect
Autowires the given bean using the context, without actually adding it to the context. If this is called duringload()then the connect will be deferred untilstart()is called. This ensures that all autowired dependencies are available before connecting.- Parameters:
bean- the bean to autowire- Since:
- 1
-
getBeans
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.- Since:
- 1
-
whenInstalled
Call the specified callback when the assembly is fully installed. If already installed, this will be called immediately. This will only be called once.- Parameters:
callback- the callback to call when install is complete- Since:
- 9
-
load
Callback to load the assembly. -
start
Callback during the installation phase. Any beans created during the load() callback are configured and have valid handles. -
started
public void started()Called after install completes and the assembly has been added to the device. Override as needed. -
stop
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 inunload(). -
unload
Release all resources from the assembly in preparation for garbage collection. Override as needed. -
getHandle
Description copied from interface:HandleAwareReturns the handle for this bean. This is used by the context to compute the opaque handle for the object.- Specified by:
getHandlein interfaceHandleAware- Returns:
- the handle node for the bean
-
isInstalling
public boolean isInstalling() -
isInstalled
public boolean isInstalled() -
getDescriptor
Description copied from interface:JsonDescriptorAwareReturn the associated JsonDescriptor.- Specified by:
getDescriptorin interfaceJsonDescriptorAware
-