Class TimerRepresentation
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.TimerRepresentation
-
- All Implemented Interfaces:
io.micrometer.core.instrument.distribution.HistogramSupport,io.micrometer.core.instrument.Meter,io.micrometer.core.instrument.Timer
public class TimerRepresentation extends MeterRepresentation implements io.micrometer.core.instrument.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, seeTimeUnit
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:
Timer,TimeUnit
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.TimeUnitbaseTimeUnitprivate longcountprivate longmaxTimeprivate java.util.List<io.micrometer.core.instrument.Measurement>measurementsprivate longtotalTimeprivate java.util.List<java.lang.Long>updates
-
Constructor Summary
Constructors Modifier Constructor Description privateTimerRepresentation(java.lang.String name)Initializes a new TimerRepresentation.privateTimerRepresentation(javax.json.JsonObject object, java.lang.String... tags)Initializes a new TimerRepresentation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.TimeUnitbaseTimeUnit()longcount()static io.micrometer.core.instrument.TimercreateNewTimer(java.lang.String name)Creates a new Timer with no measurements in it.javax.json.JsonObjectgetUpdater()Provides an updater for the Timer.doublemax(java.util.concurrent.TimeUnit unit)java.lang.Iterable<io.micrometer.core.instrument.Measurement>measure()static io.micrometer.core.instrument.TimerparseTimer(javax.json.JsonObject object, java.lang.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.voidrecord(long amount, java.util.concurrent.TimeUnit unit)voidrecord(java.lang.Runnable runnable)<T> Trecord(java.util.function.Supplier<T> supplier)<T> TrecordCallable(java.util.concurrent.Callable<T> callable)io.micrometer.core.instrument.distribution.HistogramSnapshottakeSnapshot()doubletotalTime(java.util.concurrent.TimeUnit unit)-
Methods inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
getId, parseMeter, parseMeter, parseMeterQuiet
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
count
private long count
-
baseTimeUnit
private java.util.concurrent.TimeUnit baseTimeUnit
-
measurements
private java.util.List<io.micrometer.core.instrument.Measurement> measurements
-
totalTime
private long totalTime
-
maxTime
private long maxTime
-
updates
private java.util.List<java.lang.Long> updates
-
-
Constructor Detail
-
TimerRepresentation
private TimerRepresentation(javax.json.JsonObject object, java.lang.String... tags)Initializes a new TimerRepresentation.- Parameters:
object- JsonObject representing the Timertags- tags that the Timer has- Throws:
java.lang.IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid timer.
-
TimerRepresentation
private TimerRepresentation(java.lang.String name)
Initializes a new TimerRepresentation.- Parameters:
name- URN of the timer- Throws:
java.lang.IllegalArgumentException- if the name is null or empty
-
-
Method Detail
-
parseTimer
public static io.micrometer.core.instrument.Timer parseTimer(javax.json.JsonObject object, java.lang.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 parsetags- tags that the counter has following the formatkey:value- Returns:
- a Timer representation of the JsonObject
- Throws:
java.lang.IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid timer.
-
createNewTimer
public static io.micrometer.core.instrument.Timer createNewTimer(java.lang.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:
java.lang.IllegalArgumentException- if the name is null or empty
-
takeSnapshot
public io.micrometer.core.instrument.distribution.HistogramSnapshot takeSnapshot()
- Specified by:
takeSnapshotin interfaceio.micrometer.core.instrument.distribution.HistogramSupport
-
record
public void record(long amount, java.util.concurrent.TimeUnit unit)- Specified by:
recordin interfaceio.micrometer.core.instrument.Timer
-
record
public <T> T record(java.util.function.Supplier<T> supplier)
- Specified by:
recordin interfaceio.micrometer.core.instrument.Timer
-
recordCallable
public <T> T recordCallable(java.util.concurrent.Callable<T> callable) throws java.lang.Exception- Specified by:
recordCallablein interfaceio.micrometer.core.instrument.Timer- Throws:
java.lang.Exception
-
record
public void record(java.lang.Runnable runnable)
- Specified by:
recordin interfaceio.micrometer.core.instrument.Timer
-
count
public long count()
- Specified by:
countin interfaceio.micrometer.core.instrument.Timer
-
totalTime
public double totalTime(java.util.concurrent.TimeUnit unit)
- Specified by:
totalTimein interfaceio.micrometer.core.instrument.Timer
-
max
public double max(java.util.concurrent.TimeUnit unit)
- Specified by:
maxin interfaceio.micrometer.core.instrument.Timer
-
baseTimeUnit
public java.util.concurrent.TimeUnit baseTimeUnit()
- Specified by:
baseTimeUnitin interfaceio.micrometer.core.instrument.Timer
-
measure
public java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()
- Specified by:
measurein interfaceio.micrometer.core.instrument.Meter- Specified by:
measurein interfaceio.micrometer.core.instrument.Timer- Specified by:
measurein classMeterRepresentation
-
getUpdater
public javax.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:
getUpdaterin classMeterRepresentation- Returns:
- a JsonObject representing the changes this meter has experienced
- See Also:
MeterRepresentation.getUpdater()
-
-