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

public class TimerRepresentation extends MeterRepresentation implements de.iip_ecosphere.platform.support.metrics.Timer
This class aims to provide a prototypical implementation of the Timer Interface from Micrometer-API, allowing a client process to access the Timer 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.
Timer intended to track of a large number of short running events.
The JsonObject representing a Timer will have the following format:
{
    "name": "sample.name",
    "description": "sample description, can be null",
    "baseUnit": "ourTimeUnit",
    "measurements": [
        {
            "statistic": "COUNT",
            "value": 123
        },
        {
            "statistic": "TOTAL_TIME",
            "value": 123.123
        },
        {
            "statistic": "MAX",
            "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. For the time valid time unit values, see TimeUnit
The services offered by this class are:
  • Parse a JsonObject into a Timer
  • Take a Histogram Snapshot
  • Record an amount of time with this timer
  • Check the maximum and total time recorded by the timer
  • Check the amount of times the timer has been called
  • Check the basic time unit for the timer
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

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

    de.iip_ecosphere.platform.support.metrics.Timer.DefaultSample, de.iip_ecosphere.platform.support.metrics.Timer.Sample, de.iip_ecosphere.platform.support.metrics.Timer.TimerBuilder
  • Field Summary

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

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

    Modifier and Type
    Method
    Description
     
    long
     
    static de.iip_ecosphere.platform.support.metrics.Timer
    Creates a new Timer with no measurements in it.
    de.iip_ecosphere.platform.support.json.JsonObject
    Provides an updater for the Timer.
    double
    max(TimeUnit unit)
     
    double
    mean(TimeUnit unit)
     
    Iterable<de.iip_ecosphere.platform.support.metrics.Measurement>
     
    static de.iip_ecosphere.platform.support.metrics.Timer
    parseTimer(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags)
    Parses a new timer from a JsonObject.
    See the class documentation to see the format of a JsonObject representing a Timer is expecting to have.
    void
    record(long amount, TimeUnit unit)
     
    void
    record(Runnable runnable)
     
    <T> T
    record(Supplier<T> supplier)
     
    <T> T
    recordCallable(Callable<T> callable)
     
    double
     

    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.Meter

    getId, getName
  • Field Details

    • count

      private long count
    • baseTimeUnit

      private TimeUnit baseTimeUnit
    • measurements

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

      private long totalTime
    • maxTime

      private long maxTime
    • updates

      private List<Long> updates
  • Constructor Details

    • TimerRepresentation

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

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

    • parseTimer

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

      public static de.iip_ecosphere.platform.support.metrics.Timer createNewTimer(String name)
      Creates a new Timer with no measurements in it.
      Parameters:
      name - URN of the timer
      Returns:
      a new Timer ready to be used
      Throws:
      IllegalArgumentException - if the name is null or empty
    • record

      public void record(long amount, TimeUnit unit)
      Specified by:
      record in interface de.iip_ecosphere.platform.support.metrics.Timer
    • record

      public <T> T record(Supplier<T> supplier)
      Specified by:
      record in interface de.iip_ecosphere.platform.support.metrics.Timer
    • recordCallable

      public <T> T recordCallable(Callable<T> callable) throws Exception
      Specified by:
      recordCallable in interface de.iip_ecosphere.platform.support.metrics.Timer
      Throws:
      Exception
    • record

      public void record(Runnable runnable)
      Specified by:
      record in interface de.iip_ecosphere.platform.support.metrics.Timer
    • count

      public long count()
      Specified by:
      count in interface de.iip_ecosphere.platform.support.metrics.Timer
    • totalTime

      public double totalTime(TimeUnit unit)
      Specified by:
      totalTime in interface de.iip_ecosphere.platform.support.metrics.Timer
    • max

      public double max(TimeUnit unit)
      Specified by:
      max in interface de.iip_ecosphere.platform.support.metrics.Timer
    • baseTimeUnit

      public TimeUnit baseTimeUnit()
      Specified by:
      baseTimeUnit in interface de.iip_ecosphere.platform.support.metrics.Timer
    • 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 Timer.
      The information includes the name and the different recordings carried out by this timer since its instantiation. This information is packed into a JSON Object with the following format:
       {
           "name":"customtimer",
           "recordings":[
               100000000,
               300000000,
               200000000
           ]
       }
       
      Specified by:
      getUpdater in class MeterRepresentation
      Returns:
      a JsonObject representing the changes this meter has experienced
      See Also:
    • mean

      public double mean(TimeUnit unit)
      Specified by:
      mean in interface de.iip_ecosphere.platform.support.metrics.Timer