Class MeterRepresentation

  • All Implemented Interfaces:
    io.micrometer.core.instrument.Meter
    Direct Known Subclasses:
    CounterRepresentation, GaugeRepresentation, TimerRepresentation

    public abstract class MeterRepresentation
    extends java.lang.Object
    implements io.micrometer.core.instrument.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:
    Meter, CounterRepresentation, GaugeRepresentation, TimerRepresentation
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.micrometer.core.instrument.Meter

        io.micrometer.core.instrument.Meter.Builder, io.micrometer.core.instrument.Meter.Id, io.micrometer.core.instrument.Meter.Type
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private io.micrometer.core.instrument.Meter.Id id  
      private static java.lang.String NON_VALID_JSON  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MeterRepresentation​(java.lang.String name, io.micrometer.core.instrument.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.
      protected MeterRepresentation​(javax.json.JsonObject object, io.micrometer.core.instrument.Meter.Type type, java.lang.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.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private static io.micrometer.core.instrument.Tags extractTagsMap​(java.lang.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.
      io.micrometer.core.instrument.Meter.Id getId()  
      abstract javax.json.JsonObject getUpdater()
      Creates a JsonObject with the information required to update the meter in the Meter registry in the server-side.
      abstract java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()  
      static io.micrometer.core.instrument.Meter parseMeter​(java.lang.String json, java.lang.String... tags)
      Generically parses a meter.
      static io.micrometer.core.instrument.Meter parseMeter​(javax.json.JsonObject object, java.lang.String... tags)
      Generically parses a meter.
      static io.micrometer.core.instrument.Meter parseMeterQuiet​(java.lang.String json, java.lang.String... tags)
      Generically parses a meter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.micrometer.core.instrument.Meter

        close, match, use
    • Field Detail

      • id

        private io.micrometer.core.instrument.Meter.Id id
    • Constructor Detail

      • MeterRepresentation

        protected MeterRepresentation​(javax.json.JsonObject object,
                                      io.micrometer.core.instrument.Meter.Type type,
                                      java.lang.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:
        java.lang.IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Meter.
      • MeterRepresentation

        protected MeterRepresentation​(java.lang.String name,
                                      io.micrometer.core.instrument.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:
        java.lang.IllegalArgumentException - if the name is null or empty
    • Method Detail

      • extractTagsMap

        private static io.micrometer.core.instrument.Tags extractTagsMap​(java.lang.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 io.micrometer.core.instrument.Meter.Id getId()
        Specified by:
        getId in interface io.micrometer.core.instrument.Meter
      • measure

        public abstract java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()
        Specified by:
        measure in interface io.micrometer.core.instrument.Meter
      • getUpdater

        public abstract javax.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 io.micrometer.core.instrument.Meter parseMeter​(java.lang.String json,
                                                                     java.lang.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 io.micrometer.core.instrument.Meter parseMeterQuiet​(java.lang.String json,
                                                                          java.lang.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 io.micrometer.core.instrument.Meter parseMeter​(javax.json.JsonObject object,
                                                                     java.lang.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)