java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.CounterRepresentation
All Implemented Interfaces:
de.iip_ecosphere.platform.support.metrics.Counter, de.iip_ecosphere.platform.support.metrics.Meter

public class CounterRepresentation extends MeterRepresentation implements de.iip_ecosphere.platform.support.metrics.Counter
This class aims to provide a prototypical implementation of the Counter Interface from Micrometer-API, allowing a client process to access the Counter values collected from a Service in a uniform way.
Even though the methods are functional and will indeed offer an accurate implementation of the metric we are simulating with this prototype, it is highly recommended that an instance of this class is used solely to access data and not to modify it, as the changes will not be registered in any sort of registry under normal circumstances, and this will alter the read values of the actual metrics.
Counters monitor monotonically increasing values. Counters may never be reset to a lesser value. The JsonObject representing a Counter will have the following format:
{
    "name": "sample.name",
    "description": "sample description, can be null",
    "baseUnit": "sample's.baseUnit",
    "measurements": [
        {
            "statistic": "COUNT",
            "value": 123.123
        }
    ],
    "availableTags": []
}
 
Special attention is required in the keys for the JsonValues as well as the type of Statistic and number of measurements.
The services offered by this class are:
  • Parse a JsonObject into a Counter
  • Increment a counter
  • Check the counter's value
Author:
Miguel Gomez
See Also:
  • Counter
  • Nested Class Summary

    Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.support.metrics.Counter

    de.iip_ecosphere.platform.support.metrics.Counter.CounterBuilder

    Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.support.metrics.Meter

    de.iip_ecosphere.platform.support.metrics.Meter.Id, de.iip_ecosphere.platform.support.metrics.Meter.Type
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
     
    private List<de.iip_ecosphere.platform.support.metrics.Measurement>
     
    private double
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    CounterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
    Initializes a new CounterRepresentation.
    private
    Initializes a new CounterRepresentation.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    static de.iip_ecosphere.platform.support.metrics.Counter
    Creates a new counter with no count.
    de.iip_ecosphere.platform.support.json.JsonObject
    Provides an updater for the Counter.
    The information includes the name and the amount that this counter was incremented since its instantiation.
    void
    increment(double amount)
     
    Iterable<de.iip_ecosphere.platform.support.metrics.Measurement>
     
    static de.iip_ecosphere.platform.support.metrics.Counter
    parseCounter(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
    Parses a new counter from a JsonObject.
    See the class documentation to see the format a JsonObject representing a counter is expected to have.

    Methods inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation

    getId, getName, parseMeter, parseMeter, parseMeterQuiet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface de.iip_ecosphere.platform.support.metrics.Counter

    increment

    Methods inherited from interface de.iip_ecosphere.platform.support.metrics.Meter

    getId, getName
  • Field Details

    • count

      private double count
    • update

      private double update
    • measurements

      private List<de.iip_ecosphere.platform.support.metrics.Measurement> measurements
  • Constructor Details

    • CounterRepresentation

      private CounterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
      Initializes a new CounterRepresentation.
      Parameters:
      object - JsonObject representing the Counter
      tags - tags that the counter has
      Throws:
      IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Counter.
    • CounterRepresentation

      private CounterRepresentation(String name)
      Initializes a new CounterRepresentation.
      Parameters:
      name - URN of the counter
      Throws:
      IllegalArgumentException - if the name is null or empty
  • Method Details

    • parseCounter

      public static de.iip_ecosphere.platform.support.metrics.Counter parseCounter(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
      Parses a new counter from a JsonObject.
      See the class documentation to see the format a JsonObject representing a counter is expected to have.
      Parameters:
      object - JsonObject representing the Counter we wish to parse
      tags - tags that the counter has following the format key:value
      Returns:
      a Counter representation of the JsonObject
      Throws:
      IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Counter.
    • createNewCounter

      public static de.iip_ecosphere.platform.support.metrics.Counter createNewCounter(String name)
      Creates a new counter with no count.
      Parameters:
      name - URN of the counter
      Returns:
      a new Counter ready to be used
      Throws:
      IllegalArgumentException - if the name is null or empty
    • increment

      public void increment(double amount)
      Specified by:
      increment in interface de.iip_ecosphere.platform.support.metrics.Counter
    • count

      public double count()
      Specified by:
      count in interface de.iip_ecosphere.platform.support.metrics.Counter
    • measure

      public Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> measure()
      Specified by:
      measure in interface de.iip_ecosphere.platform.support.metrics.Meter
      Specified by:
      measure in class MeterRepresentation
    • getUpdater

      public de.iip_ecosphere.platform.support.json.JsonObject getUpdater()
      Provides an updater for the Counter.
      The information includes the name and the amount that this counter was incremented since its instantiation. This information is packed into a JSON Object with the following format:
       {
           "name":"customcounter",
           "increment":2.5
       }
       
      Specified by:
      getUpdater in class MeterRepresentation
      Returns:
      a JsonObject representing the changes this meter has experienced
      See Also: