Class CachedCounters

java.lang.Object
org.pipservices3.components.count.CachedCounters
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, ICounters, ITimingCallback
Direct Known Subclasses:
LogCounters

public abstract class CachedCounters
extends Object
implements ICounters, org.pipservices3.commons.config.IReconfigurable, ITimingCallback
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
    Modifier and Type Field Description
    protected long _lastResetTime  
    protected long _resetTimeout  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected CachedCounters()
    Creates a new CachedCounters object.
  • Method Summary

    Modifier and Type Method Description
    Timing beginTiming​(String name)
    Begins measurement of execution time interval.
    void clear​(String name)
    Clears (resets) a counter specified by its name.
    void clearAll()
    Clears (resets) all counters.
    void configure​(org.pipservices3.commons.config.ConfigParams config)
    Configures component by passing configuration parameters.
    void dump()
    Dumps (saves) the current values of counters.
    void endTiming​(String name, float elapsed)
    Ends measurement of execution elapsed time and updates specified counter.
    Counter get​(String name, int type)
    Gets a counter specified by its name.
    List<Counter> getAll()
    Gets all captured counters.
    void increment​(String name, int value)
    Increments counter by given value.
    void incrementOne​(String name)
    Increments counter by 1.
    void last​(String name, float value)
    Records the last calculated measurement value.
    protected abstract void save​(List<Counter> counters)
    Saves the current counters measurements.
    void stats​(String name, float value)
    Calculates min/average/max statistics based on the current and previous values.
    void timestamp​(String name, ZonedDateTime value)
    Records the given timestamp.
    void timestampNow​(String name)
    Records the current time as a timestamp.
    protected void update()
    Makes counter measurements as updated and dumps them when timeout expires.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      configure in interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
    • clear

      public void clear​(String name)
      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.InvocationException
      Dumps (saves) the current values of counters.
      Throws:
      org.pipservices3.commons.errors.InvocationException - when error occured.
      See Also:
      save(List)
    • update

      protected void update()
      Makes counter measurements as updated and dumps them when timeout expires.
      See Also:
      dump()
    • getAll

      public List<Counter> getAll()
      Gets all captured counters.
      Returns:
      a list with counters.
    • get

      public Counter get​(String name, int type)
      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

      public Timing beginTiming​(String name)
      Begins measurement of execution time interval. It returns Timing object which has to be called at Timing.endTiming() to end the measurement and update the counter.
      Specified by:
      beginTiming in interface ICounters
      Parameters:
      name - a counter name of Interval type.
      Returns:
      a Timing callback object to end timing.
    • endTiming

      public void endTiming​(String name, float elapsed)
      Ends measurement of execution elapsed time and updates specified counter.
      Specified by:
      endTiming in interface ITimingCallback
      Parameters:
      name - a counter name
      elapsed - execution elapsed time in milliseconds to update the counter.
      See Also:
      Timing.endTiming()
    • stats

      public void stats​(String name, float value)
      Calculates min/average/max statistics based on the current and previous values.
      Specified by:
      stats in interface ICounters
      Parameters:
      name - a counter name of Statistics type
      value - a value to update statistics
    • last

      public void last​(String name, float value)
      Records the last calculated measurement value. Usually this method is used by metrics calculated externally.
      Specified by:
      last in interface ICounters
      Parameters:
      name - a counter name of Last type.
      value - a last value to record.
    • timestampNow

      public void timestampNow​(String name)
      Records the current time as a timestamp.
      Specified by:
      timestampNow in interface ICounters
      Parameters:
      name - a counter name of Timestamp type.
    • timestamp

      public void timestamp​(String name, ZonedDateTime value)
      Records the given timestamp.
      Specified by:
      timestamp in interface ICounters
      Parameters:
      name - a counter name of Timestamp type.
      value - a timestamp to record.
    • incrementOne

      public void incrementOne​(String name)
      Increments counter by 1.
      Specified by:
      incrementOne in interface ICounters
      Parameters:
      name - a counter name of Increment type.
    • increment

      public void increment​(String name, int value)
      Increments counter by given value.
      Specified by:
      increment in interface ICounters
      Parameters:
      name - a counter name of Increment type.
      value - a value to add to the counter.