Class DefaultDatumService

java.lang.Object
net.solarnetwork.node.runtime.DefaultDatumService
All Implemented Interfaces:
Consumer<NodeDatum>, InstructionHandler, DatumService, org.osgi.service.event.EventHandler

public class DefaultDatumService extends Object implements DatumService, org.osgi.service.event.EventHandler, InstructionHandler, Consumer<NodeDatum>
Default implementation of DatumService.

This service listens for DatumDataSource.EVENT_TOPIC_DATUM_CAPTURED events to track datum.

Version:
2.2
Author:
matt
  • Field Details

    • SETUP_SERVICE_LATEST_DATUM

      public static final String SETUP_SERVICE_LATEST_DATUM
      The service name to retrieve the latest datum.
      See Also:
    • DEFAFULT_HISTORY_RAW_COUNT

      public static final int DEFAFULT_HISTORY_RAW_COUNT
      The default history raw count.
      See Also:
  • Constructor Details

    • DefaultDatumService

      public DefaultDatumService(org.springframework.util.PathMatcher pathMatcher, com.fasterxml.jackson.databind.ObjectMapper objectMapper, net.solarnetwork.service.OptionalService<DatumMetadataService> datumMetadataService)
      Constructor.
      Parameters:
      pathMatcher - the path matcher to use
      objectMapper - the object mapper to use
      datumMetadataService - the datum metadata service to use
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • latest

      public <T extends NodeDatum> Collection<T> latest(Set<String> sourceIdFilter, Class<T> type)
      Description copied from interface: DatumService
      Get the latest available datum of a given type, optionally filtered by source IDs.

      This is equivalent to calling offset(sourceIdFilter, 0, type).

      Specified by:
      latest in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceIdFilter - an optional set of Ant-style source ID patterns to filter by
      type - the type of datum
      Returns:
      the matching datum, never null
      See Also:
    • latest

      public <T extends NodeDatum> T latest(String sourceId, Class<T> type)
      Description copied from interface: DatumService
      Get the latest available datum of a given type, optionally filtered by source IDs.

      This is equivalent to calling offset(sourceIdFilter, 0, type).

      Specified by:
      latest in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceId - the source ID to find
      type - the type of datum
      Returns:
      the matching datum, never null
      See Also:
    • offset

      public <T extends NodeDatum> T offset(String sourceId, int offset, Class<T> type)
      Description copied from interface: DatumService
      Get an offset from the latest available datum of a given type, optionally filtered by source IDs.
      Specified by:
      offset in interface DatumService
      Type Parameters:
      T - the type of datum to get
      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
      type - the type of datum
      Returns:
      the matching datum, never null
    • offset

      public <T extends NodeDatum> Collection<T> offset(Set<String> sourceIdFilter, int offset, Class<T> type)
      Description copied from interface: DatumService
      Get an offset from the latest available datum of a given type, optionally filtered by source IDs.
      Specified by:
      offset in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceIdFilter - an optional set of Ant-style source ID patterns to filter by; use null or an empty set to return all available sources
      offset - the offset from the latest, 0 being the latest and 1 the next later, and so on
      type - the type of datum
      Returns:
      the matching datum, never null
    • offset

      public <T extends NodeDatum> Collection<T> offset(Set<String> sourceIdFilter, Instant timestamp, int offset, Class<T> type)
      Description copied from interface: DatumService
      Get datum offset from a given timestamp, optionally filtered by source IDs.
      Specified by:
      offset in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceIdFilter - an optional set of Ant-style source ID patterns to filter by; use null or an empty set to return all available sources
      timestamp - the timestamp to reference
      offset - the offset from timestamp, 0 being the latest and 1 the next later, and so on
      type - the type of datum
      Returns:
      the matching datum, never null
    • offset

      public <T extends NodeDatum> T offset(String sourceId, Instant timestamp, int offset, Class<T> type)
      Description copied from interface: DatumService
      Get a datum offset from a given timestamp.
      Specified by:
      offset in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceId - the source ID of the datum to find
      timestamp - the timestamp to reference
      offset - the offset from timestamp, 0 being the latest and 1 the next later, and so on
      type - the type of datum
      Returns:
      the datum, or null if no such datum is available
    • slice

      public <T extends NodeDatum> Collection<T> slice(String sourceId, int offset, int count, Class<T> type)
      Description copied from interface: DatumService
      Get an set of datum offset from the latest available datum of a given type.
      Specified by:
      slice in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceId - the source ID of the datum to find
      offset - the offset from timestamp, 0 being the latest and 1 the next later, and so on
      count - the maximum number of datum to return, starting from offset and iterating over earlier datum
      type - the type of datum to filter the results by, or null to accept all datum
      Returns:
      the matching datum, never null
    • slice

      public <T extends NodeDatum> Collection<T> slice(String sourceId, Instant timestamp, int offset, int count, Class<T> type)
      Description copied from interface: DatumService
      Get a set of datum offset from a given timestamp.
      Specified by:
      slice in interface DatumService
      Type Parameters:
      T - the type of datum to get
      Parameters:
      sourceId - the source ID of the datum to find
      timestamp - the timestamp to reference
      offset - the offset from timestamp, 0 being the latest and 1 the next later, and so on
      count - the maximum number of datum to return, starting from offset and iterating over earlier datum
      type - the type of datum to filter the results by, or null to accept all datum
      Returns:
      the matching datum, never null
    • accept

      public void accept(NodeDatum datum)
      Specified by:
      accept in interface Consumer<NodeDatum>
    • handleEvent

      public void handleEvent(org.osgi.service.event.Event event)
      Specified by:
      handleEvent in interface org.osgi.service.event.EventHandler
    • handlesTopic

      public boolean handlesTopic(String topic)
      Description copied from interface: InstructionHandler
      Test if a topic is handled by this handler.
      Specified by:
      handlesTopic in interface InstructionHandler
      Parameters:
      topic - the topic
      Returns:
      true only if this handler can execute the job for the given topic
    • processInstruction

      public InstructionStatus processInstruction(Instruction instruction)
      Description copied from interface: InstructionHandler
      Process an instruction.
      Specified by:
      processInstruction in interface InstructionHandler
      Parameters:
      instruction - the instruction to process
      Returns:
      the status for the instruction, or null if the instruction was not handled
    • datumMetadata

      public net.solarnetwork.domain.datum.DatumMetadataOperations datumMetadata(String sourceId)
      Description copied from interface: DatumService
      Get the metadata for a given datum stream.
      Specified by:
      datumMetadata in interface DatumService
      Parameters:
      sourceId - the source ID of the datum metadata to get
      Returns:
      the metadata, or null if no such metadata is available
    • datumMetadata

      public Collection<net.solarnetwork.domain.datum.DatumMetadataOperations> datumMetadata(Set<String> sourceIdFilter)
      Description copied from interface: DatumService
      Get the metadata for a set of datum streams matching a filter.
      Specified by:
      datumMetadata in interface DatumService
      Parameters:
      sourceIdFilter - an optional set of Ant-style source ID patterns to filter by; use null or an empty set to return all available sources
      Returns:
      the matching metadata, never null
    • setHistoryRawCount

      public void setHistoryRawCount(int rawCount)
      Change the history raw count.

      Calling this resets the entire history.

      Parameters:
      rawCount - the raw count to set