Interface IfaceAwareNodeService<T extends BinaryMsgIface,N>

All Superinterfaces:
BinaryMsgIfaceFactory

public interface IfaceAwareNodeService<T extends BinaryMsgIface,N> extends BinaryMsgIfaceFactory
Interface that can be applied to a service that handles service-level adapters running on one or more nodes in a KOS device. A service-level adapter is something like spanwer, fuseMounter, nodeMgr and so on. These are adapters that are singletons on a given node but in multi-node configurations may point to the primary node. For example, consider a device with two boards running KOS. One is the primary and runs java, browser, etc... The other is a secondary that does not run java, but can run native adapters to make resources on the board accessible from the primary node. In this configuration, the adapters on the secondary node are configured to point to the primary. In this case the primary node will have connections from both nodes. This interface exists to make it easy to create services that can easily support multiple nodes.

Instead of a service creating a IfaceClient for the adapter connection, it defines a node object, where one node object can be created for each node in the device. The IfaceCilent is then placed in the node object and accessed by the nodeId of the node to operate on.

Management of the node cache is as simple as creating a class to represent a node and then adding a ManifestNodeCache in the service that will hold the nodes. This must be accessible via getNodeCache() to work with this interface. Once in place, any requests for a node via a nodeId will pass through this cache. The cache will perform validation on the nodeId, ensuring invalid nodeId's are ignored and creating a new node instance for the cache when needed.

The getIfaceName() method should return the name of the iface to bind to. As adapters connect, this name will be used to automatically discover matching ifaces and route them to this service where they will automatically create a matching node in the cache and call createIface(). This method simply creates an instance of the iface, passing the IfaceClient from the node to the iface to bind them together.

Since:
9
Version:
9
  • Method Summary

    Modifier and Type
    Method
    Description
    createIface(BinaryMsgSession session, N node)
    Return an instance of the custom iface for the specified node.
    default T
    Implementation of BinaryMsgIfaceFactory that will forward the create request to the specific node object.
    Return the name of the iface for this service.
    default N
    getNode(NodeId nodeId)
    Return a node instance for the specified nodeId but only if the instance already exists.
    Return an instance of ManifestNodeCache to hold the node data.
    default N
    Given a nodeId, return a node instance for the id, creating a new node if needed.
  • Method Details

    • getNodeCache

      ManifestNodeCache<N> getNodeCache()
      Return an instance of ManifestNodeCache to hold the node data.
      Since:
      9
    • getIfaceName

      String getIfaceName()
      Return the name of the iface for this service.
      Since:
      9
    • getOrCreateNode

      default N getOrCreateNode(NodeId nodeId)
      Given a nodeId, return a node instance for the id, creating a new node if needed. Given that node creation is backed by ManifestNodeCache which valiates nodeId's against the list of possible nodes defined in the device manifest, this may still return null if an invalid nodeId is specified.
      Parameters:
      nodeId - id of the node to bind an iface to
      Since:
      9
    • getNode

      default N getNode(NodeId nodeId)
      Return a node instance for the specified nodeId but only if the instance already exists. This can be used in normal use cases where checking the existence of an instance shouldn't cause the instance to be created.
      Parameters:
      nodeId - the nodeId to return an instance for
      Since:
      9
    • createIface

      default T createIface(String name, BinaryMsgSession session)
      Implementation of BinaryMsgIfaceFactory that will forward the create request to the specific node object.
      Specified by:
      createIface in interface BinaryMsgIfaceFactory
      Parameters:
      name - the name of the interface
      session - the session to back the interface
      Returns:
      the iface or null
      Since:
      9
    • createIface

      T createIface(BinaryMsgSession session, N node)
      Return an instance of the custom iface for the specified node. This is called when the adapter for the service connects to java. This will be called every time the adapter connects to the service to bind a new iface.
      Since:
      9