Class Device<T extends BaseDeviceConfig>

java.lang.Object
com.tccc.kos.core.service.device.Device<T>
All Implemented Interfaces:
ConfigAware<T>, HandleAware, JsonDescriptorAware

public abstract class Device<T extends BaseDeviceConfig> extends Object implements ConfigAware<T>, JsonDescriptorAware
A representation of the device. This is generally used as a view for external systems to discover key data about the device without needing to query multiple endpoints and stitching the data together. This is not a required aspect of kOS but is a very useful pattern that is facilitated by this class.

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 Details

    • Device

      public Device()
  • Method Details

    • getName

      public String getName()
      Return the device name from the config bean.
      Specified by:
      getName in interface HandleAware
      Returns:
      this handle's name
    • setName

      public void setName(String name)
      Set the device name. Shortcut for updating the config bean.
      Parameters:
      name - the new device name
    • getSerialNumber

      public String getSerialNumber()
      Return the serial number of the device.
    • getNodeId

      public String 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 an Assembly 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

      public void loadDescriptor(File file) throws IOException
      Load the descriptor from the specified file.
      Parameters:
      file - the file containing the descriptor json
      Throws:
      IOException
    • loadDescriptor

      public void loadDescriptor(InputStream is) throws IOException
      Load the descriptor from the specified input stream.
      Parameters:
      is - the input stream containing the descriptor json
      Throws:
      IOException
    • 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
    • getConfig

      public T getConfig()
      Description copied from interface: ConfigAware
      Gets the current config bean so that it can be updated.
      Specified by:
      getConfig in interface ConfigAware<T extends BaseDeviceConfig>
      Returns:
      the config bean
    • setConfig

      public void setConfig(T config)
      Description copied from interface: ConfigAware
      Sets the initial config bean.
      Specified by:
      setConfig in interface ConfigAware<T extends BaseDeviceConfig>
    • getDescriptor

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

      public void setDescriptor(JsonDescriptor descriptor)