Class ManifestNodeCache<T>

java.lang.Object
com.kosdev.kos.core.service.manifest.ManifestNodeCache<T>

public class ManifestNodeCache<T> extends Object
Simple cache for node related data. This is commonly used by IfaceAwareNodeService to populate per-node data for the underlying service.

This is essentially a map of nodeId / data, where the data is created by an instance of NodeDataFactory when there is a cache miss. In the event of a cache miss, the nodeId will be validated against the list of nodes defined in the current manifest. If the nodeId isn't defined, no data will be added to the cache. This effectively ensures that we only gather cache data for nodes that are well defined by the currently running manifest.

Since:
9
Version:
9
  • Constructor Details

    • ManifestNodeCache

      public ManifestNodeCache(ManifestNodeCache.NodeDataFactory<T> factory)
      Create a new cache with the specified factory to allocate a new node when required.
      Parameters:
      factory - factory to create new nodes
      Since:
      9
  • Method Details

    • get

      public T get(NodeId nodeId)
      Return the data for the specified nodeId.
      Parameters:
      nodeId - the nodeId to query
      Returns:
      the associated node data or null
      Since:
      9
    • getOrCreate

      public T getOrCreate(NodeId nodeId)
      Return the data for the specified nodeId, creating a new data object using the associated factory if the nodeId isn't in the cache. Returns null if the specified nodeId isn't defined in the currently running manifest.
      Parameters:
      nodeId - the nodeId to query
      Returns:
      the associated data or null
      Since:
      9
    • getNodes

      public Collection<T> getNodes()
      Return the list of nodes from the cache.