Class Device<T extends BaseDeviceConfig>
- All Implemented Interfaces:
ConfigAware<T>
,HandleAware
,JsonDescriptorAware
System applications typically subclass Device
and set the device into
kOS using setDevice()
. The device typically contain all the data
required to bootstrap an external system such as an admin interface. This
object is typically accessed using the DeviceView
json view, and many
core kOS objects are annotated accordingly.
There are various subclasses of Device
which provide higher level
starting points for defining a device. Any of these can be extended to achieve
the desired definition of a device.
- Since:
- 1.0
- Version:
- 2023-11-13
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the current config bean so that it can be updated.Return the associated JsonDescriptor.Returns the handle for this bean.getName()
Return the device name from the config bean.Return the nodeId of the node this is running on.Return the serial number of the device.void
loadDescriptor
(File file) Load the descriptor from the specified file.void
Load the descriptor from the specified input stream.void
Called when the device has been changed and any listeners should be informed.void
Sets the initial config bean.void
setDescriptor
(JsonDescriptor descriptor) void
Set the device name.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.service.config.ConfigAware
onConfigChanged, onConfigSet
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getPath
-
Constructor Details
-
Device
public Device()
-
-
Method Details
-
getName
Return the device name from the config bean.- Specified by:
getName
in interfaceHandleAware
- Returns:
- this handle's name
-
setName
Set the device name. Shortcut for updating the config bean.- Parameters:
name
- the new device name
-
getSerialNumber
Return the serial number of the device. -
getNodeId
Return the nodeId of the node this is running on. -
notifyListeners
public void notifyListeners()Called when the device has been changed and any listeners should be informed. This is called automatically when anAssembly
is added or removed. User code can call this any time listeners need to react to a change in the device.This typically results in external system rebuilding their state to match the new device data.
Device
objects should not be used to store state that can regularly change. It is reasonable to have the device return data that may contain runtime state as a means of establishing a baseline of data, but there should then be other data streams that allow external systems to remain in sync via deltas. -
loadDescriptor
Load the descriptor from the specified file.- Parameters:
file
- the file containing the descriptor json- Throws:
IOException
-
loadDescriptor
Load the descriptor from the specified input stream.- Parameters:
is
- the input stream containing the descriptor json- Throws:
IOException
-
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 interfaceHandleAware
- Returns:
- the handle node for the bean
-
getConfig
Description copied from interface:ConfigAware
Gets the current config bean so that it can be updated.- Specified by:
getConfig
in interfaceConfigAware<T extends BaseDeviceConfig>
- Returns:
- the config bean
-
setConfig
Description copied from interface:ConfigAware
Sets the initial config bean.- Specified by:
setConfig
in interfaceConfigAware<T extends BaseDeviceConfig>
-
getDescriptor
Description copied from interface:JsonDescriptorAware
Return the associated JsonDescriptor.- Specified by:
getDescriptor
in interfaceJsonDescriptorAware
-
setDescriptor
-