Class DatumHistory

java.lang.Object
net.solarnetwork.node.runtime.DatumHistory

public class DatumHistory extends Object
Class to help track the history of datum capture, by source ID.

This class maintains a fixed-size history of NodeDatum at various time levels:

raw
Individual datum stored as-is.

Note that no time-based ordering of datum is maintained by this class. They are maintained simply by insertion time, i.e. the time when #add(Datum) is invoked. Concurrent invocation of #add(Datum) is allowed, but the order of the added elements is undefined in that case.

Since:
1.89
Version:
1.1
Author:
matt
  • Field Details

  • Constructor Details

    • DatumHistory

      public DatumHistory(DatumHistory.Configuration config)
      Constructor.

      A default load factory and concurrency level will be used.

      Parameters:
      config - the configuration to use
    • DatumHistory

      public DatumHistory(DatumHistory.Configuration config, float loadFactor, int concurrencyLevel)
      Constructor.
      Parameters:
      config - the configuration to use
      loadFactor - a load factor to use for sizing the internal data structures
      concurrencyLevel - a concurrency level to use for sizing the internal data structures
      Throws:
      IllegalArgumentException - if config is null
    • DatumHistory

      public DatumHistory(DatumHistory.Configuration config, ConcurrentMap<String,Queue<NodeDatum>> raw)
      Constructor.
      Parameters:
      config - the configuration to use
      raw - a map to use for raw datum
      Throws:
      IllegalArgumentException - if config is null
  • Method Details

    • add

      public void add(NodeDatum datum)
      Add a datum.

      If datum is null or does not have a source ID or creation date, nothing will be added.

      Parameters:
      datum - the datum to add
    • latest

      public Iterable<NodeDatum> latest()
      Get an Iterable over the latest available raw datum.

      This is equivalent to calling offset(0).

      Returns:
      the Iterable, never null
      See Also:
    • latest

      public NodeDatum latest(String sourceId)
      Get the latest datum available with a given source ID.

      This is equivalent to calling offset(sourceId, 0).

      Parameters:
      sourceId - the source ID to find
      Returns:
      the datum, or null
      See Also:
    • offset

      public Iterable<NodeDatum> offset(int offset)
      Get an Iterable over an offset from the latest available raw datum.

      An offset of 0 means the latest datum, and 1 means the one before the latest datum, and so on.

      Parameters:
      offset - the offset from the latest, 0 being the latest and 1 the next later, and so on
      Returns:
      the Iterable, never null
      Since:
      1.1
    • offset

      public NodeDatum offset(String sourceId, int offset)
      Get the datum offset from the latest available raw datum for a given source ID.

      An offset of 0 means the latest datum, and 1 means the one before the latest datum, and so on.

      Parameters:
      sourceId - the source ID to find
      offset - the offset from the latest, 0 being the latest and 1 the next later, and so on
      Returns:
      the Iterable, never null
      Since:
      1.1
    • offset

      public Iterable<NodeDatum> offset(Instant timestamp, int offset)
      Get an Iterable over an offset from a datum offset from a given timestamp.

      An offset of 0 means the datum closest before or equal to the given timestamp, and 1 means the next one before that, and so on. Note that no sorting of datum is performed by this method: it assumes elements have been added in ascending timestamp order already.

      Parameters:
      timestamp - the timestamp to offset from
      offset - the offset from timestamp, 0 being the latest and 1 the next later, and so on
      Returns:
      the Iterable, never null
      Since:
      1.1
    • offset

      public NodeDatum offset(String sourceId, Instant timestamp, int offset)
      Get the datum offset from a given timestamp for a given source ID.

      An offset of 0 means the datum closest before or equal to the given timestamp, and 1 means the next one before that, and so on. Note that no sorting of datum is performed by this method: it assumes elements have been added in ascending timestamp order already.

      Parameters:
      sourceId - the source ID to find
      timestamp - the timestamp to offset from
      offset - the offset from the latest, 0 being the latest and 1 the next later, and so on
      Returns:
      the datum, or null if no such datum is available
      Since:
      1.1
    • getConfig

      public DatumHistory.Configuration getConfig()
      Get the configuration.
      Returns:
      the configuration, never null