java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
All Implemented Interfaces:
de.iip_ecosphere.platform.support.metrics.Meter
Direct Known Subclasses:
CounterRepresentation, GaugeRepresentation, TimerRepresentation

public abstract class MeterRepresentation extends Object implements de.iip_ecosphere.platform.support.metrics.Meter
This class aims to provide a prototypical implementation of the Meter Interface from Micrometer-API, allowing a client process to access the Meter 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.
A meter is a named and dimensioned producer of one or more measurements. This is a generic superclass that is extended by each individual meter. Even though every meter can be represented as a Meter for simplification and Abstraction, it is recommended that the prototype is instanced as a particular type of Meter in stead of a generic type. Please see CounterRepresentation, GaugeRepresentation and TimerRepresentation to instantiate a more specific type of Meter. This representation of a Meter should only be an important detail to know.
The JsonObject representing a Gauge will have the following format:
{
    "name": "sample.name",
    "description": "sample description, can be null",
    "baseUnit": "sample's.baseUnit",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 123.123
        }
    ],
    "availableTags": []
}
 
Please see CounterRepresentation, GaugeRepresentation and TimerRepresentation for a more specific and accurate representation of each specific type of meter. If a generic meter is instantiated, special attention is required in the keys of the JsonValues as well as making sure that there is at least one measurement that consists of JsonObject containing a statistic and a value.
The services offered by this class are:
  • Collect the Meter's ID
  • Collect the Meter's measurements
  • Create a JsonObject with the update information
Author:
Miguel Gomez
See Also:
  • Nested Class Summary

    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 de.iip_ecosphere.platform.support.metrics.Meter.Id
     
    private static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MeterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, de.iip_ecosphere.platform.support.metrics.Meter.Type type, String... tags)
    Instantiates a new Meter representation.
    This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent.
    protected
    MeterRepresentation(String name, de.iip_ecosphere.platform.support.metrics.Meter.Type type)
    Instantiates a brand new Meter representation with just the name.
    This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static List<de.iip_ecosphere.platform.support.metrics.Tag>
    Extracts the tags from a string array and turns them into a Tags object.
    The tags should be the same ones used for the HTTP request that provided the JsonObject representation of the Meter.
    Following the same format used for the tags from said request, these tags follow the notation key:value.
    de.iip_ecosphere.platform.support.metrics.Meter.Id
     
     
    abstract de.iip_ecosphere.platform.support.json.JsonObject
    Creates a JsonObject with the information required to update the meter in the Meter registry in the server-side.
    abstract Iterable<de.iip_ecosphere.platform.support.metrics.Measurement>
     
    static de.iip_ecosphere.platform.support.metrics.Meter
    parseMeter(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
    Generically parses a meter.
    static de.iip_ecosphere.platform.support.metrics.Meter
    parseMeter(String json, String... tags)
    Generically parses a meter.
    static de.iip_ecosphere.platform.support.metrics.Meter
    parseMeterQuiet(String json, String... tags)
    Generically parses a meter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NON_VALID_JSON

      private static final String NON_VALID_JSON
      See Also:
    • id

      private de.iip_ecosphere.platform.support.metrics.Meter.Id id
  • Constructor Details

    • MeterRepresentation

      protected MeterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, de.iip_ecosphere.platform.support.metrics.Meter.Type type, String... tags)
      Instantiates a new Meter representation.
      This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent. The type of Meter to be indicated is COUNTER, GAUGE or TIMER depending on the subclass calling. If we don't want/need to specify the type, we can use OTHER.
      Parameters:
      object - JsonObject representing the Meter we wish to parse
      type - type of meter that is being created
      tags - tags that the meter has following the format key:value
      Throws:
      IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Meter.
    • MeterRepresentation

      protected MeterRepresentation(String name, de.iip_ecosphere.platform.support.metrics.Meter.Type type)
      Instantiates a brand new Meter representation with just the name.
      This method should be called by all extending subclasses to provide the attributes required by the Meter superclass that is extended by the interface they represent. The type of Meter to be indicated is COUNTER, GAUGE or TIMER depending on the subclass calling. If we don't want/need to specify the type, we can use OTHER.
      Parameters:
      name - URN of the meter
      type - type of meter that is being created
      Throws:
      IllegalArgumentException - if the name is null or empty
  • Method Details

    • extractTagsMap

      private static List<de.iip_ecosphere.platform.support.metrics.Tag> extractTagsMap(String... tags)
      Extracts the tags from a string array and turns them into a Tags object.
      The tags should be the same ones used for the HTTP request that provided the JsonObject representation of the Meter.
      Following the same format used for the tags from said request, these tags follow the notation key:value.
      Parameters:
      tags - tags that the meter has
      Returns:
      Tags representation of the set of tags
    • getId

      public de.iip_ecosphere.platform.support.metrics.Meter.Id getId()
      Specified by:
      getId in interface de.iip_ecosphere.platform.support.metrics.Meter
    • measure

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

      public abstract de.iip_ecosphere.platform.support.json.JsonObject getUpdater()
      Creates a JsonObject with the information required to update the meter in the Meter registry in the server-side.
      Returns:
      a JsonObject representing the changes this meter has experienced
    • parseMeter

      public static de.iip_ecosphere.platform.support.metrics.Meter parseMeter(String json, String... tags)
      Generically parses a meter. Emits a log message if the json cannot be parsed.
      Parameters:
      json - JSON string representation of the meter
      tags - tags that the counter has following the format key:value
      Returns:
      a Meter representation of the JsonObject (null if invalid, unknown)
    • parseMeterQuiet

      public static de.iip_ecosphere.platform.support.metrics.Meter parseMeterQuiet(String json, String... tags)
      Generically parses a meter. Does not emit anything if the json cannot be parsed.
      Parameters:
      json - JSON string representation of the meter
      tags - tags that the counter has following the format key:value
      Returns:
      a Meter representation of the JsonObject (null if invalid, unknown)
    • parseMeter

      public static de.iip_ecosphere.platform.support.metrics.Meter parseMeter(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
      Generically parses a meter.
      Parameters:
      object - JsonObject representing the Timer we wish to parse
      tags - tags that the counter has following the format key:value
      Returns:
      a Meter representation of the JsonObject (null if invalid, unknown)
    • getName

      public String getName()
      Specified by:
      getName in interface de.iip_ecosphere.platform.support.metrics.Meter