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:
de.iip_ecosphere.platform.support.metrics.Counter,de.iip_ecosphere.platform.support.metrics.Meter
public class CounterRepresentation
extends MeterRepresentation
implements de.iip_ecosphere.platform.support.metrics.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:
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.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.support.metrics.Counter
de.iip_ecosphere.platform.support.metrics.Counter.CounterBuilderNested 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleprivate List<de.iip_ecosphere.platform.support.metrics.Measurement> private double -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCounterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags) Initializes a new CounterRepresentation.privateCounterRepresentation(String name) Initializes a new CounterRepresentation. -
Method Summary
Modifier and TypeMethodDescriptiondoublecount()static de.iip_ecosphere.platform.support.metrics.CountercreateNewCounter(String name) Creates a new counter with no count.de.iip_ecosphere.platform.support.json.JsonObjectProvides an updater for the Counter.
The information includes the name and the amount that this counter was incremented since its instantiation.voidincrement(double amount) Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> measure()static de.iip_ecosphere.platform.support.metrics.CounterparseCounter(de.iip_ecosphere.platform.support.json.JsonObject object, 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, 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.Counter
incrementMethods inherited from interface de.iip_ecosphere.platform.support.metrics.Meter
getId, getName
-
Field Details
-
count
private double count -
update
private double update -
measurements
-
-
Constructor Details
-
CounterRepresentation
private CounterRepresentation(de.iip_ecosphere.platform.support.json.JsonObject object, String... tags) Initializes a new CounterRepresentation.- Parameters:
object- JsonObject representing the Countertags- tags that the counter has- Throws:
IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid Counter.
-
CounterRepresentation
Initializes a new CounterRepresentation.- Parameters:
name- URN of the counter- Throws:
IllegalArgumentException- if the name is null or empty
-
-
Method Details
-
parseCounter
public static de.iip_ecosphere.platform.support.metrics.Counter parseCounter(de.iip_ecosphere.platform.support.json.JsonObject object, 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:
IllegalArgumentException- if the object isnull, or if the JsonObject doesn't represent a valid Counter.
-
createNewCounter
Creates a new counter with no count.- Parameters:
name- URN of the counter- Returns:
- a new Counter ready to be used
- Throws:
IllegalArgumentException- if the name is null or empty
-
increment
public void increment(double amount) - Specified by:
incrementin interfacede.iip_ecosphere.platform.support.metrics.Counter
-
count
public double count()- Specified by:
countin interfacede.iip_ecosphere.platform.support.metrics.Counter
-
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 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:
-