Class CounterRepresentation

  • All Implemented Interfaces:
    io.micrometer.core.instrument.Counter, io.micrometer.core.instrument.Meter

    public class CounterRepresentation
    extends MeterRepresentation
    implements io.micrometer.core.instrument.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 io.micrometer.core.instrument.Counter

        io.micrometer.core.instrument.Counter.Builder
      • 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 double count  
      private java.util.List<io.micrometer.core.instrument.Measurement> measurements  
      private double update  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CounterRepresentation​(java.lang.String name)
      Initializes a new CounterRepresentation.
      private CounterRepresentation​(javax.json.JsonObject object, java.lang.String... tags)
      Initializes a new CounterRepresentation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double count()  
      static io.micrometer.core.instrument.Counter createNewCounter​(java.lang.String name)
      Creates a new counter with no count.
      javax.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.
      void increment​(double amount)  
      java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()  
      static io.micrometer.core.instrument.Counter parseCounter​(javax.json.JsonObject object, java.lang.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 java.lang.Object

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

        increment
      • Methods inherited from interface io.micrometer.core.instrument.Meter

        close, getId, match, use
    • Field Detail

      • count

        private double count
      • update

        private double update
      • measurements

        private java.util.List<io.micrometer.core.instrument.Measurement> measurements
    • Constructor Detail

      • CounterRepresentation

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

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

      • parseCounter

        public static io.micrometer.core.instrument.Counter parseCounter​(javax.json.JsonObject object,
                                                                         java.lang.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:
        java.lang.IllegalArgumentException - if the object is null, or if the JsonObject doesn't represent a valid Counter.
      • createNewCounter

        public static io.micrometer.core.instrument.Counter createNewCounter​(java.lang.String name)
        Creates a new counter with no count.
        Parameters:
        name - URN of the counter
        Returns:
        a new Counter ready to be used
        Throws:
        java.lang.IllegalArgumentException - if the name is null or empty
      • increment

        public void increment​(double amount)
        Specified by:
        increment in interface io.micrometer.core.instrument.Counter
      • count

        public double count()
        Specified by:
        count in interface io.micrometer.core.instrument.Counter
      • measure

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

        public javax.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:
        MeterRepresentation.getUpdater()