Class BaseDatumFilterSupport

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.service.support.BaseDatumFilterSupport
All Implemented Interfaces:
net.solarnetwork.service.Identifiable
Direct Known Subclasses:
DatumFilterChainService

public class BaseDatumFilterSupport extends BaseIdentifiable
Base class for services like DatumFilterService to extend.
Since:
2.0
Version:
1.1
Author:
matt
  • Field Details

    • DEFAULT_UID

      public static final String DEFAULT_UID
      The default value for the UID property.
      See Also:
    • DEFAULT_STAT_LOG_FREQUENCY

      public static final int DEFAULT_STAT_LOG_FREQUENCY
      The default stat logging frequency.
      Since:
      1.2
      See Also:
    • stats

      protected final net.solarnetwork.util.StatCounter stats
      A stats counter.

      The base stats will be DatumFilterStats.

      Since:
      1.2
  • Constructor Details

    • BaseDatumFilterSupport

      public BaseDatumFilterSupport()
      Constructor.
    • BaseDatumFilterSupport

      public BaseDatumFilterSupport(net.solarnetwork.util.StatCounter.Stat[] stats)
      Constructor.
      Parameters:
      stats - the status to use (can be null
      Since:
      1.2
  • Method Details

    • populateBaseSampleTransformSupportSettings

      public static void populateBaseSampleTransformSupportSettings(List<net.solarnetwork.settings.SettingSpecifier> settings)
      Populate settings for the BaseDatumFilterSupport class.

      This will use null for all default values.

      Parameters:
      settings - the settings to populate
      Since:
      1.1
      See Also:
    • populateBaseSampleTransformSupportSettings

      public static void populateBaseSampleTransformSupportSettings(List<net.solarnetwork.settings.SettingSpecifier> settings, String sourceIdDefault, String requiredOperationalModeDefault, String requiredTagDefault)
      Populate settings for the BaseDatumFilterSupport class.

      This will add settings for the sourceId and requiredOperationalMode settings.

      Parameters:
      settings - the list to add settings to
      sourceIdDefault - the default sourceId value
      requiredOperationalModeDefault - the default requiredOperationalMode value
      requiredTagDefault - the requiredTag default value
      Since:
      1.1
    • populateStatusSettings

      protected void populateStatusSettings(List<net.solarnetwork.settings.SettingSpecifier> settings)
      Populate a "status" setting.
      Parameters:
      settings - the settings to add the status to
      Since:
      1.2
      See Also:
    • getStatusMessage

      protected String getStatusMessage()
      Generate a status message.

      This will resolve the status.msg message and pass in parameters for all of the DatumFilterStats values along with a processing time average and "not ignored" processing time average.

      Returns:
      the status message
    • incrementInputStats

      protected long incrementInputStats()
      Increment the statistics for "input" invocation.
      Returns:
      the current time, for passing to incrementIgnoredStats(long) or incrementStats(long, DatumSamplesOperations, DatumSamplesOperations) later
      Since:
      1.2
    • incrementIgnoredStats

      protected void incrementIgnoredStats(long startTime)
      Increment the statistics for an "ignored" invocation.
      Parameters:
      startTime - the start time
      Since:
      1.2
    • incrementStats

      protected void incrementStats(long startTime, net.solarnetwork.domain.datum.DatumSamplesOperations in, net.solarnetwork.domain.datum.DatumSamplesOperations out)
      Increment the statistics for a "not ignored" invocation.
      Parameters:
      startTime - the start time
      in - the input samples
      out - the output samples
      Since:
      1.2
    • matchesAny

      public static boolean matchesAny(Pattern[] pats, String value, boolean emptyPatternMatches)
      Test if any regular expression in a set matches a string value.
      Parameters:
      pats - the regular expressions to use
      value - the value to test
      emptyPatternMatches - true if a null regular expression is treated as a match (thus matching any value)
      Returns:
      true if at least one regular expression matches value
    • sourceIdMatches

      protected boolean sourceIdMatches(net.solarnetwork.domain.datum.Datum datum)
      Test if a given datum's source ID matches the configured source ID pattern.
      Parameters:
      datum - the datum whose source ID should be tested
      Returns:
      true if the datum's sourceId value matches the configured source ID pattern, or no pattern is configured
    • operationalModeMatches

      protected boolean operationalModeMatches()
      Test if the configured required operational mode is active.

      If getRequiredOperationalMode() is configured but #getOpModesService() is not, this method will always return false.

      Returns:
      true if an operational mode is required and that mode is currently active
      Since:
      1.1
    • tagMatches

      protected boolean tagMatches(net.solarnetwork.domain.datum.Datum datum, net.solarnetwork.domain.datum.DatumSamplesOperations samples)
      Test if the configured getRequiredTag() expression matches the given datum or samples.

      If no required tag expression is configured, this method returns true. Otherwise, the expression is split on a comma delimiter (surrounding whitespace is allowed) and each tag is tested against the samples and datum. If any tag matches, true is returned, thus the multiple required tags are treated as if joined by a logical OR operator. Any individual tag may be prefixed by ! to invert the match logic, meaning the given samples match if the given tag is not present.

      Parameters:
      datum - the datum (may be null)
      samples - the samples (may be null)
      Returns:
      true if the configured requiredTag expression matches either samples or datum
      Since:
      1.1
    • conditionsMatch

      protected boolean conditionsMatch(net.solarnetwork.domain.datum.Datum datum, net.solarnetwork.domain.datum.DatumSamplesOperations samples, Map<String,Object> parameters)
      Test if any configured conditions match the given arguments.

      This method calls the following condition-testing methods:

      1. sourceIdMatches(Datum)
      2. operationalModeMatches()
      3. tagMatches(Datum, DatumSamplesOperations)

      Extending classes can override this to add additional tests.

      Parameters:
      datum - the datum associated with samples
      samples - the samples object to transform
      parameters - optional implementation-specific parameters to pass to the transformer
      Returns:
      true if all of the condition-testing methods return true
      Since:
      1.1
    • smartPlaceholders

      protected Map<String,Object> smartPlaceholders(Map<String,Object> parameters)
      Create a parameter map that includes placeholders.

      If the BaseIdentifiable.getPlaceholderService() is configured the PlaceholderService.smartCopyPlaceholders(Map) method will be invoked to create valid Number instances out of placeholder values. The parameters map, if provided, will be copied into the returned map, overwriting any duplicate entries.

      Parameters:
      parameters - an optional set of parameters to copy into the result
      Returns:
      a new map, never null
      Since:
      1.1
    • getSourceIdPattern

      protected Pattern getSourceIdPattern()
      Get the source ID regex.
      Returns:
      the regex
    • getDescription

      public String getDescription()
      Get a description of this service.
      Returns:
      the description
    • setUid

      public void setUid(String uid)
      Overrides:
      setUid in class net.solarnetwork.service.support.BasicIdentifiable
    • getSourceId

      public String getSourceId()
      Get the source ID pattern.
      Returns:
      The pattern.
    • setSourceId

      public void setSourceId(String sourceIdPattern)
      Set a source ID pattern to match samples against. Samples will only be considered for filtering if Datum.getSourceId() matches this pattern. The sourceIdPattern must be a valid Pattern regular expression. The expression will be allowed to match anywhere in Datum.getSourceId() values, so if the pattern must match the full value only then use pattern positional expressions like ^ and $.
      Parameters:
      sourceIdPattern - The source ID regex to match. Syntax errors in the pattern will be ignored and a null value will be set instead.
    • getOpModesService

      public OperationalModesService getOpModesService()
      Get the operational modes service to use.
      Returns:
      the service, or null
    • setOpModesService

      public void setOpModesService(OperationalModesService opModesService)
      Set the operational modes service to use.
      Parameters:
      opModesService - the service to use
      Since:
      1.1
    • getRequiredOperationalMode

      public String getRequiredOperationalMode()
      Get an operational mode that is required by this service.
      Returns:
      the required operational mode, or null for none
      Since:
      1.1
    • setRequiredOperationalMode

      public void setRequiredOperationalMode(String requiredOperationalMode)
      Set an operational mode that is required by this service.
      Parameters:
      requiredOperationalMode - the required operational mode, or null or an empty string that will be treated as null
      Since:
      1.1
    • 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
    • getRequiredTag

      public String getRequiredTag()
      Get the required tag expression.
      Returns:
      the required tag
      Since:
      1.1
    • setRequiredTag

      public void setRequiredTag(String requiredTag)
      Set the required tag expression.
      Parameters:
      requiredTag - the tag expression to set
      Since:
      1.1