Class ISOMsgCounter

java.lang.Object
org.jpos.metrics.iso.ISOMsgCounter
All Implemented Interfaces:
Configurable, ISOMsgMetrics, LogSource

public class ISOMsgCounter extends Object implements ISOMsgMetrics, LogSource, Configurable
Counts ISO messages using Micrometer meters and tags resolved from message fields.
  • Constructor Details

  • Method Details

    • getMetricSignature

      Returns the metric meters.
      Specified by:
      getMetricSignature in interface ISOMsgMetrics
      Returns:
      This overrides the default implementation, also including the keys from the internal field set.
    • getMetricName

      Description copied from interface: ISOMsgMetrics
      Returns the metric name.
      Specified by:
      getMetricName in interface ISOMsgMetrics
      Returns:
      the metric name
    • setMetricName

      public void setMetricName(String metricName)
      Description copied from interface: ISOMsgMetrics
      Sets the metric name.
      Specified by:
      setMetricName in interface ISOMsgMetrics
      Parameters:
      metricName - the metric name
    • getMetricDescription

      Description copied from interface: ISOMsgMetrics
      Returns the metric description.
      Specified by:
      getMetricDescription in interface ISOMsgMetrics
      Returns:
      the metric description
    • setMetricDescription

      public void setMetricDescription(String metricDescription)
      Description copied from interface: ISOMsgMetrics
      Sets the metric description.
      Specified by:
      setMetricDescription in interface ISOMsgMetrics
      Parameters:
      metricDescription - the metric description
    • addTags

      public io.micrometer.core.instrument.Tags addTags(io.micrometer.core.instrument.Tags tags)
      Description copied from interface: ISOMsgMetrics
      Adds metric tags to the given Tags object.
      Specified by:
      addTags in interface ISOMsgMetrics
      Parameters:
      tags - the Tags to add to
      Returns:
      the updated Tags
    • getTags

      public io.micrometer.core.instrument.Tags getTags()
      Description copied from interface: ISOMsgMetrics
      Returns all metric tags.
      Specified by:
      getTags in interface ISOMsgMetrics
      Returns:
      the metric tags
    • recordMessage

      public void recordMessage(ISOMsg m)
      Description copied from interface: ISOMsgMetrics
      Records an ISOMsg in the meter registry.
      The metric name and tags will be taken strictly from this object's configuration.
      If this object hasn't been successfully registered, it throws an IllegalStateException.
      Specified by:
      recordMessage in interface ISOMsgMetrics
      Parameters:
      m - the ISOMsg to record.
    • recordMessage

      public void recordMessage(ISOMsg m, MeterInfo meterInfo)
      Description copied from interface: ISOMsgMetrics
      Records an ISOMsg in the meter registry.
      Similar to ISOMsgMetrics.recordMessage(ISOMsg) but using the metric name, description and maybe some tags taken from the MeterInfo argument.

      If the metric for that combination of MeterInfo values and local values fails to register in the global MeterRegistry (or any underlying one like the Prometheus registry), the method may throw an IllegalStateException. This also happens if this object hasn't been successfully registered by The metric name and tags will be taken from what has been configured. If this object hasn't been successfully registered, it throws an IllegalStateException.

      Specified by:
      recordMessage in interface ISOMsgMetrics
      Parameters:
      m - the ISO message
      meterInfo - the meter info to record
    • register

      public boolean register(io.micrometer.core.instrument.MeterRegistry registry)
      Description copied from interface: ISOMsgMetrics
      Register this object to work with a given MeterRegistry.
      This method may serve more than one purpose in the object's lifecycle:
      • Assign a MeterRegistry to be used for the created meters. (The registry can be obtained by calling ISOMsgMetrics.getRegistry())
      • Before this object has been registered, it can be configured by setting tags, etc., but attempting to record a message (e.g. through ISOMsgMetrics.recordMessage(ISOMsg)) will throw an IllegalStateException.
      • After it has been registered, it's ready to record messages. However, it can't be configured any longer, or it will throw an IllegalStateException. The object's configuration can be considered "frozen".
      • In some (future) implementation, it may make use of the ISOMsgMetrics.getMetricSignature() to do some caching to ensure that every metric name has only one set of tag keys, thus avoiding metrics name+keyset collision in PrometheusMeterRegistry.
      The ISOMsgMetrics.unregister() method should be called when done using this object.
      Specified by:
      register in interface ISOMsgMetrics
      Parameters:
      registry - the meter registry to register with
      Returns:
      true if successful, false if there was an error
    • unregister

      public void unregister()
      Description copied from interface: ISOMsgMetrics
      It calls ISOMsgMetrics.removeMeters() and clears its internal reference to its MeterRegistry.
      It will also "unfreeze" the object, making it available for reconfiguration.
      Specified by:
      unregister in interface ISOMsgMetrics
    • getRegistry

      public io.micrometer.core.instrument.MeterRegistry getRegistry()
      Description copied from interface: ISOMsgMetrics
      Returns the meter registry.
      Specified by:
      getRegistry in interface ISOMsgMetrics
      Returns:
      the MeterRegistry
    • removeMeters

      public void removeMeters()
      Description copied from interface: ISOMsgMetrics
      Removes all registered meters.
      Specified by:
      removeMeters in interface ISOMsgMetrics
    • setConfiguration

      Description copied from interface: Configurable
      Configures this object with the supplied Configuration.
      Specified by:
      setConfiguration in interface Configurable
      Parameters:
      cfg - Configuration object
      Throws:
      ConfigurationException - if the configuration is invalid
    • parseTagPairs

      protected Map<String,String> parseTagPairs(String tp, boolean copySingleTag)
      Parses tag-value pairs from a string.
      Parameters:
      tp - tag-pair string to parse
      copySingleTag - if true, copy single tags
      Returns:
      the parsed tag pairs
    • validateFieldSetMap

      protected void validateFieldSetMap(Map<String,String> fieldsMap) throws ConfigurationException
      Validates the field set map.
      Parameters:
      fieldsMap - the field set map to validate
      Throws:
      ConfigurationException - if validation fails
    • getMeters

      protected Set<io.micrometer.core.instrument.Meter> getMeters()
      Returns a clone set, which may not be up to date next time you use it.
      Returns:
      a snapshot of the live meter set
    • getFieldSet

      protected Map<String,String> getFieldSet()
      Returns the configured field set map.
      Returns:
      the field set map
    • getTagsAsMap

      Returns the metric tags as a map.
      Returns:
      the tags map
    • resolveValExpr

      protected String resolveValExpr(ISOMsg m, String val)
      Hook for subclasses to resolve, against an ISOMsg, the valexpr part of a tag:valexpr in a fieldset.
      A subclass may add or override its own aliases, or have a special way to convert "valexpr" to a String taken from the given ISOMsg.
      If the subclass can't resolve the alias/valexpr, it may call super (i.e. this method) as a fallback.
      Parameters:
      m - the ISOMsg whose fields are inspected
      val - the valexpr (alias name or field path) to resolve
      Returns:
      the resolved value, or an empty string when no value is available
    • setLogger

      public void setLogger(Logger logger, String realm)
      Description copied from interface: LogSource
      Attaches a Logger and realm to this log source.
      Specified by:
      setLogger in interface LogSource
      Parameters:
      logger - the logger to use
      realm - the log realm (diagnostic label)
    • getRealm

      public String getRealm()
      Description copied from interface: LogSource
      Returns the log realm associated with this source.
      Specified by:
      getRealm in interface LogSource
      Returns:
      log realm
    • getLogger

      public Logger getLogger()
      Description copied from interface: LogSource
      Returns the Logger associated with this source.
      Specified by:
      getLogger in interface LogSource
      Returns:
      the Logger