Class CounterRepresentation
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.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
-
-
Field Summary
Fields Modifier and Type Field Description private doublecountprivate java.util.List<io.micrometer.core.instrument.Measurement>measurementsprivate doubleupdate
-
Constructor Summary
Constructors Modifier Constructor Description privateCounterRepresentation(java.lang.String name)Initializes a new CounterRepresentation.privateCounterRepresentation(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 doublecount()static io.micrometer.core.instrument.CountercreateNewCounter(java.lang.String name)Creates a new counter with no count.javax.json.JsonObjectgetUpdater()Provides an updater for the Counter.
The information includes the name and the amount that this counter was incremented since its instantiation.voidincrement(double amount)java.lang.Iterable<io.micrometer.core.instrument.Measurement>measure()static io.micrometer.core.instrument.CounterparseCounter(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 de.iip_ecosphere.platform.services.environment.metricsProvider.meterRepresentation.MeterRepresentation
getId, parseMeter, parseMeter, parseMeterQuiet
-
-
-
-
Constructor Detail
-
CounterRepresentation
private CounterRepresentation(javax.json.JsonObject object, java.lang.String... tags)Initializes a new CounterRepresentation.- Parameters:
object- JsonObject representing the Countertags- tags that the counter has- Throws:
java.lang.IllegalArgumentException- if the object isnull, 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 parsetags- tags that the counter has following the formatkey:value- Returns:
- a Counter representation of the JsonObject
- Throws:
java.lang.IllegalArgumentException- if the object isnull, 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:
incrementin interfaceio.micrometer.core.instrument.Counter
-
count
public double count()
- Specified by:
countin interfaceio.micrometer.core.instrument.Counter
-
measure
public java.lang.Iterable<io.micrometer.core.instrument.Measurement> measure()
- Specified by:
measurein interfaceio.micrometer.core.instrument.Counter- Specified by:
measurein interfaceio.micrometer.core.instrument.Meter- Specified by:
measurein classMeterRepresentation
-
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:
getUpdaterin classMeterRepresentation- Returns:
- a JsonObject representing the changes this meter has experienced
- See Also:
MeterRepresentation.getUpdater()
-
-