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:
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:
The services offered by this class are:
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 TimeUnitThe 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.TypeNested 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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTimerRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags) Initializes a new TimerRepresentation.privateTimerRepresentation(String name) Initializes a new TimerRepresentation. -
Method Summary
Modifier and TypeMethodDescriptionlongcount()static de.iip_ecosphere.platform.support.metrics.TimercreateNewTimer(String name) Creates a new Timer with no measurements in it.de.iip_ecosphere.platform.support.json.JsonObjectProvides an updater for the Timer.doubledoubleIterable<de.iip_ecosphere.platform.support.metrics.Measurement> measure()static de.iip_ecosphere.platform.support.metrics.TimerparseTimer(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.voidvoid<T> T<T> TrecordCallable(Callable<T> callable) doubleMethods inherited from class de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
getId, getName, parseMeter, parseMeter, parseMeterQuietMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.iip_ecosphere.platform.support.metrics.Meter
getId, getName
-
Field Details
-
count
private long count -
baseTimeUnit
-
measurements
-
totalTime
private long totalTime -
maxTime
private long maxTime -
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 Timertags- tags that the Timer has- Throws:
IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid timer.
-
TimerRepresentation
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 parsetags- tags that the counter has following the formatkey:value- Returns:
- a Timer representation of the JsonObject
- Throws:
IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid timer.
-
createNewTimer
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
- Specified by:
recordin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
record
- Specified by:
recordin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
recordCallable
- Specified by:
recordCallablein interfacede.iip_ecosphere.platform.support.metrics.Timer- Throws:
Exception
-
record
- Specified by:
recordin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
count
public long count()- Specified by:
countin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
totalTime
- Specified by:
totalTimein interfacede.iip_ecosphere.platform.support.metrics.Timer
-
max
- Specified by:
maxin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
baseTimeUnit
- Specified by:
baseTimeUnitin interfacede.iip_ecosphere.platform.support.metrics.Timer
-
measure
- Specified by:
measurein interfacede.iip_ecosphere.platform.support.metrics.Meter- Specified by:
measurein classMeterRepresentation
-
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:
getUpdaterin classMeterRepresentation- Returns:
- a JsonObject representing the changes this meter has experienced
- See Also:
-
mean
- Specified by:
meanin interfacede.iip_ecosphere.platform.support.metrics.Timer
-