Class DatumDataSourceSupport

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.service.support.DatumDataSourceSupport
All Implemented Interfaces:
net.solarnetwork.service.Identifiable

public class DatumDataSourceSupport extends BaseIdentifiable
Helper class for DatumDataSource and MultiDatumDataSource implementations to extend.
Since:
2.0
Version:
1.1
Author:
matt
  • Field Details

    • SUB_SAMPLE_PROPS

      public static final Map<String,Object> SUB_SAMPLE_PROPS
      A transform properties instance that can be used to signal "sub-sampling" mode to the transform service.
    • DEFAULT_SUBSAMPLE_START_DELAY

      public static final long DEFAULT_SUBSAMPLE_START_DELAY
      The subSampleStartDelay property default value.
      See Also:
    • DEFAULT_PUBLISH_DEVICE_INFO_METADATA

      public static final boolean DEFAULT_PUBLISH_DEVICE_INFO_METADATA
      The publishDeviceInfoMetadata property default value.
      See Also:
  • Constructor Details

    • DatumDataSourceSupport

      public DatumDataSourceSupport()
  • Method Details

    • clearSourceMetadataCache

      public static final void clearSourceMetadataCache()
      Clear the source metadata cache.

      This is designed to support testing primarily.

      Since:
      1.1
    • offerDatumCapturedEvent

      protected final void offerDatumCapturedEvent(NodeDatum datum)
      Offer a non-persisted datum event to the configured DatumQueue, if available.
      Parameters:
      datum - the datum that was captured
    • addSourceMetadata

      protected boolean addSourceMetadata(String sourceId, net.solarnetwork.domain.datum.GeneralDatumMetadata meta)
      Add source metadata using the configured DatumMetadataService (if available). The metadata will be cached so that subsequent calls to this method with the same metadata value will not try to re-save the unchanged value. This method will catch all exceptions and silently discard them.
      Parameters:
      sourceId - the source ID to add metadata to; place holders will be resolved via BaseIdentifiable.resolvePlaceholders(String)
      meta - the metadata to add
      Returns:
      true if the metadata was saved successfully, or does not need to be updated
    • getIdentifiableSettingSpecifiers

      protected List<net.solarnetwork.settings.SettingSpecifier> getIdentifiableSettingSpecifiers()
      Get setting specifiers for the uid and groupUid properties.
      Returns:
      list of setting specifiers
    • getSubSampleSettingSpecifiers

      protected List<net.solarnetwork.settings.SettingSpecifier> getSubSampleSettingSpecifiers()
      Get setting specifiers for the sub-sample supporting properties.
      Returns:
      list of setting specifiers
    • getDeviceInfoMetadataSettingSpecifiers

      protected List<net.solarnetwork.settings.SettingSpecifier> getDeviceInfoMetadataSettingSpecifiers()
      Get setting specifiers for device info metadata publishing support.
      Returns:
      list of settings
    • canPublishDeviceInfo

      public boolean canPublishDeviceInfo()
      Support the DeviceInfoProvider publish setting.
      Returns:
      the isPublishDeviceInfoMetadata() value
    • startSubSampling

      protected ScheduledFuture<?> startSubSampling(DatumDataSource dataSource)
      Schedule sub-sampling with the given data source.
      Parameters:
      dataSource - the data source
      Returns:
      the scheduled future or null if sub-sampling support is not configured; canceling this will stop the sub-sampling task
      See Also:
    • readSubSampleDatum

      protected void readSubSampleDatum(DatumDataSource dataSource)
      Read a sub-sample datum value.

      This method is invoked by a task scheduled after calling startSubSampling(DatumDataSource). It simply calls DatumDataSource.readCurrentDatum(). Extending classes may want to override this behavior.

      Parameters:
      dataSource - the data source previously passed to startSubSampling(DatumDataSource)
    • stopSubSampling

      protected void stopSubSampling()
      Stop any running sub-sampling task.
      See Also:
    • isSubSampling

      protected boolean isSubSampling()
      Test if sub-sampling is currently active.
      Returns:
      true if sub-sampling is active
    • applyDatumFilter

      protected NodeDatum applyDatumFilter(NodeDatum datum, Map<String,Object> props)
      Apply the configured datum filter service to a given datum.
      Parameters:
      datum - the datum to possibly filter
      props - optional transform properties to pass to DatumFilterService.filter(net.solarnetwork.domain.datum.Datum, DatumSamplesOperations, Map)
      Returns:
      the same datum, possibly transformed, or null if the datum has been filtered out completely
    • populateExpressionDatumProperties

      protected void populateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs)
      Evaluate a set of expression configurations and store the results as properties on a datum.

      This method will create a new ExpressionRoot instance for the expression root object and pass that to populateExpressionDatumProperties(MutableNodeDatum, ExpressionConfig[], Object).

      Parameters:
      d - the datum to store the results of expression evaluations on
      expressionConfs - the expression configurations
      See Also:
    • populateExpressionDatumProperties

      protected void populateExpressionDatumProperties(MutableNodeDatum d, ExpressionConfig[] expressionConfs, Object root)
      Evaluate a set of expression configurations and store the results as properties on a datum.
      Parameters:
      d - the datum to store the results of expression evaluations on
      expressionConfs - the expression configurations
      root - the expression root object
    • saveMetadata

      protected void saveMetadata(String sourceId)
      Save the BasicIdentifiable.getMetadata() data as datum source metadata.
      Parameters:
      sourceId - the source ID to save the metadata on
      Since:
      1.1
    • getDatumMetadataService

      public net.solarnetwork.service.OptionalService<DatumMetadataService> getDatumMetadataService()
      Get the configured DatumMetadataService.
      Returns:
      the service to use
    • setDatumMetadataService

      public void setDatumMetadataService(net.solarnetwork.service.OptionalService<DatumMetadataService> datumMetadataService)
      Set a DatumMetadataService to use for managing datum metadata.
      Parameters:
      datumMetadataService - the service to use
    • getTaskScheduler

      public org.springframework.scheduling.TaskScheduler getTaskScheduler()
      Get the task scheduler.
      Returns:
      the task scheduler
    • setTaskScheduler

      public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
      Set the task scheduler.
      Parameters:
      taskScheduler - the task scheduler to set
    • getSubSampleFrequency

      public Long getSubSampleFrequency()
      Get a sub-sample frequency at which to request datum.
      Returns:
      the sub-sample frequency, in milliseconds, or null or anything less than 1 to disable sub-sampling
    • setSubSampleFrequency

      public void setSubSampleFrequency(Long subSampleFrequency)
      Set a sub-sample frequency at which to request datum.

      This is designed to work with a setDatumFilterService(OptionalFilterableService) transformer that performs down-sampling of higher frequency data.

      Parameters:
      subSampleFrequency - the frequency, to set, in milliseconds
    • getSubSampleStartDelay

      public long getSubSampleStartDelay()
      Get the sub-sample start delay.
      Returns:
      the delay, in milliseconds
    • setSubSampleStartDelay

      public void setSubSampleStartDelay(long subSampleStartDelay)
      Set the sub-sample start delay.
      Parameters:
      subSampleStartDelay - the sub-sample start delay to set, in milliseconds
    • getDatumFilterService

      public net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> getDatumFilterService()
      Get a datum filter service to use.
      Returns:
      the service
    • setDatumFilterService

      public void setDatumFilterService(net.solarnetwork.service.OptionalService.OptionalFilterableService<net.solarnetwork.service.DatumFilterService> datumFilterService)
      Set a datum filter service to use.
      Parameters:
      datumFilterService - the service to set
    • getExpressionConfigs

      public ExpressionConfig[] getExpressionConfigs()
      Get the expression configurations.
      Returns:
      the expression configurations
    • setExpressionConfigs

      public void setExpressionConfigs(ExpressionConfig[] expressionConfigs)
      Set the expression configurations to use.
      Parameters:
      expressionConfigs - the configs to use
    • getExpressionConfigsCount

      public int getExpressionConfigsCount()
      Get the number of configured expressionConfigs elements.
      Returns:
      the number of expressionConfigs elements
    • setExpressionConfigsCount

      public void setExpressionConfigsCount(int count)
      Adjust the number of configured ExpressionConfig elements.

      Any newly added element values will be set to new ExpressionConfig instances.

      Parameters:
      count - The desired number of expressionConfigs elements.
    • isPublishDeviceInfoMetadata

      public boolean isPublishDeviceInfoMetadata()
      Get the desired device info metadata publish mode.
      Returns:
      true to publish device metadata; defaults to DEFAULT_PUBLISH_DEVICE_INFO_METADATA
    • setPublishDeviceInfoMetadata

      public void setPublishDeviceInfoMetadata(boolean publishDeviceInfoMetadata)
      Get the desired device info metadata publish mode.
      Parameters:
      publishDeviceInfoMetadata - true to publish device metadata once, after the first datum has been captured
    • getDatumQueue

      public net.solarnetwork.service.OptionalService<DatumQueue> getDatumQueue()
      Get the datum queue.
      Returns:
      the queue
    • setDatumQueue

      public void setDatumQueue(net.solarnetwork.service.OptionalService<DatumQueue> datumQueue)
      Set the datum queue.
      Parameters:
      datumQueue - the queue to set
    • getDatumService

      public net.solarnetwork.service.OptionalService<DatumService> getDatumService()
      Get the datum service.
      Returns:
      the datum service
    • setDatumService

      public void setDatumService(net.solarnetwork.service.OptionalService<DatumService> datumService)
      Set the datum service.
      Parameters:
      datumService - the datum service