Interface MeterConfigBuilder

All Known Subinterfaces:
ProductMeterConfigBuilder
All Known Implementing Classes:
MeterConfigBuilderImpl

public interface MeterConfigBuilder
Builder used to dynamically create a MeterConfig.
Since:
5.0.0
  • Method Details

    • addEnabledCheck

      MeterConfigBuilder addEnabledCheck(Predicate<MeterConfig> enabledCheck)
      Adds a check to the MeterConfigBuilder that will be used to determine if the MeterConfig is enabled.

      Adding a new check will not remove the previous checks. All checks must pass for the MeterConfig to be enabled.

      Parameters:
      enabledCheck - predicate returning true if the Meter should be enabled
      Returns:
      this MeterConfigBuilder
    • setWorkInProgress

      MeterConfigBuilder setWorkInProgress(boolean workInProgress)
      Sets meter as "work in progress". Work in progress meters require additional feature flag to be enabled. It is intended for meter we want to test on internal instances before enabling them on production.
      Parameters:
      workInProgress - true if the meter is work in progress
      Returns:
      this MeterConfigBuilder
    • setProperty

      MeterConfigBuilder setProperty(String key, Object value)
      Sets a property on the MeterConfigBuilder. Properties can be accessed later on for individual meters through MeterConfig.getProperties().
      Parameters:
      key - property key
      value - property value
      Returns:
      this MeterConfigBuilder
    • logOnceEveryInterval

      MeterConfigBuilder logOnceEveryInterval(int interval)
      Makes the meter to be logged once every 'interval' times.

      By default, the 'interval' is set to 1, which usually means the meter will be logged every minute.

      If product logs meters every minute, setting the 'interval' value to 5 will make the meter to be logged every 5 minutes.

      Parameters:
      interval - how often the meter should be logged. Is a positive integer.
      Returns:
      this MeterConfigBuilder
    • logIfUpdatedInLastMinute

      MeterConfigBuilder logIfUpdatedInLastMinute()
      Makes the meter to be logged only if it was updated in the last minute.
      Returns:
      this MeterConfigBuilder
    • setCustomLogger

      MeterConfigBuilder setCustomLogger(org.slf4j.Logger logger)
      Sets a custom logger for the meter. This logger will be used to log the meter values.

      By default, the meter is logged to ipd log file using default logger defined in IpdConstants.DEFAULT_DATA_LOGGER.

      Parameters:
      logger - custom logger
      Returns:
      this MeterConfigBuilder
    • setIntervalLogging

      MeterConfigBuilder setIntervalLogging(boolean enabled)
      Sets the meter to log at regular intervals.

      By default, the meters are automatically logged in a regular interval.

      Setting the 'enabled' value to false, doesn't disable all logging, but only the regular interval logging. If the meter has setLogOnUpdate(boolean) enabled, it will still be logged when updated.
      Parameters:
      enabled - true if the meter should be logged at regular intervals
      Returns:
      this MeterConfigBuilder
    • setLogOnUpdate

      MeterConfigBuilder setLogOnUpdate(boolean logOnUpdate)
      Sets the meter to be logged when it's updated.

      Meter will still be logged at regular intervals if setIntervalLogging(boolean) is enabled.

      Parameters:
      logOnUpdate - true if the meter should be logged when updated
      Returns:
      this MeterConfigBuilder
    • logWhen

      MeterConfigBuilder logWhen(Predicate<IpdMeter> shouldLog)
      Adds additional condition for logging the meter.Meter will be logged only when this condition is met.

      All conditions must be met to log the meter.

      Parameters:
      shouldLog - predicate returning true if the meter should be logged
      Returns:
      this MeterConfigBuilder
    • setUpdateListener

      MeterConfigBuilder setUpdateListener(Consumer<IpdMeter> updateListener)
      Sets the listener that will be called when the meter value is updated and setLogOnUpdate(boolean) is enabled.

      By default this value is set to IpdConstants.NO_OP.
      However, products should set this value for all meters to IpdLoggingService.logMetric(IpdMeter).

      Parameters:
      updateListener - listener that is called when the meter value is updated
      Returns:
      this MeterConfigBuilder