Class CachedCounters
java.lang.Object
org.pipservices3.components.count.CachedCounters
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.config.IReconfigurable,ICounters,ICounterTimingCallback
- Direct Known Subclasses:
LogCounters
public abstract class CachedCounters
extends Object
implements ICounters, org.pipservices3.commons.config.IReconfigurable, ICounterTimingCallback
Abstract implementation of performance counters that measures and stores counters in memory.
Child classes implement saving of the counters into various destinations.
### Configuration parameters ###
- options:
- interval: interval in milliseconds to save current counters measurements (default: 5 mins)
- reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeginTiming(String name) Begins measurement of execution time interval.voidClears (resets) a counter specified by its name.voidclearAll()Clears (resets) all counters.voidconfigure(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.voiddump()Dumps (saves) the current values of counters.voidEnds measurement of execution elapsed time and updates specified counter.Gets a counter specified by its name.getAll()Gets all captured counters.longGets the counters dump/save interval.voidIncrements counter by given value.voidincrementOne(String name) Increments counter by 1.voidRecords the last calculated measurement value.protected abstract voidSaves the current counters measurements.voidsetInterval(long value) Gets the counters dump/save interval.voidCalculates min/average/max statistics based on the current and previous values.voidtimestamp(String name, ZonedDateTime value) Records the given timestamp.voidtimestampNow(String name) Records the current time as a timestamp.protected voidupdate()Makes counter measurements as updated and dumps them when timeout expires.
-
Field Details
-
_lastResetTime
protected long _lastResetTime -
_resetTimeout
protected long _resetTimeout
-
-
Constructor Details
-
CachedCounters
protected CachedCounters()Creates a new CachedCounters object.
-
-
Method Details
-
save
protected abstract void save(List<Counter> counters) throws org.pipservices3.commons.errors.InvocationException Saves the current counters measurements.- Parameters:
counters- current counters measurements to be saves.- Throws:
org.pipservices3.commons.errors.InvocationException- when error occured.
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices3.commons.config.IConfigurable- Parameters:
config- configuration parameters to be set.
-
getInterval
public long getInterval()Gets the counters dump/save interval.- Returns:
- the interval in milliseconds.
-
setInterval
public void setInterval(long value) Gets the counters dump/save interval.- Parameters:
value- the interval in milliseconds.
-
clear
Clears (resets) a counter specified by its name.- Parameters:
name- a counter name to clear.
-
clearAll
public void clearAll()Clears (resets) all counters. -
dump
public void dump() throws org.pipservices3.commons.errors.InvocationExceptionDumps (saves) the current values of counters.- Throws:
org.pipservices3.commons.errors.InvocationException- when error occured.- See Also:
-
update
protected void update()Makes counter measurements as updated and dumps them when timeout expires.- See Also:
-
getAll
Gets all captured counters.- Returns:
- a list with counters.
-
get
Gets a counter specified by its name. It counter does not exist or its type doesn't match the specified type it creates a new one.- Parameters:
name- a counter name to retrieve.type- a counter type.- Returns:
- an existing or newly created counter of the specified type.
-
beginTiming
Begins measurement of execution time interval. It returns CounterTiming object which has to be called atCounterTiming.endTiming()to end the measurement and update the counter.- Specified by:
beginTimingin interfaceICounters- Parameters:
name- a counter name of Interval type.- Returns:
- a CounterTiming callback object to end timing.
-
endTiming
Ends measurement of execution elapsed time and updates specified counter.- Specified by:
endTimingin interfaceICounterTimingCallback- Parameters:
name- a counter nameelapsed- execution elapsed time in milliseconds to update the counter.- See Also:
-
stats
Calculates min/average/max statistics based on the current and previous values. -
last
Records the last calculated measurement value.Usually this method is used by metrics calculated externally.
-
timestampNow
Records the current time as a timestamp.- Specified by:
timestampNowin interfaceICounters- Parameters:
name- a counter name of Timestamp type.
-
timestamp
Records the given timestamp. -
incrementOne
Increments counter by 1.- Specified by:
incrementOnein interfaceICounters- Parameters:
name- a counter name of Increment type.
-
increment
Increments counter by given value.
-