org.pipservices3.components.count.CompositeCounters Maven / Gradle / Ivy
package org.pipservices3.components.count;
import java.time.ZonedDateTime;
import java.util.*;
import org.pipservices3.commons.refer.*;
/**
* Aggregates all counters from component references under a single component.
*
* It allows to capture metrics and conveniently send them to multiple destinations.
*
* ### References ###
*
* - *:counters:*:*:1.0 (optional) {@link ICounters} components to pass collected measurements
*
*
* ### Example ###
*
* {@code
* class MyComponent implements IReferenceable {
* CompositeCounters _counters = new CompositeCounters();
*
* public void setReferences(IReferences references) {
* this._counters.setReferences(references);
* ...
* }
*
* public void myMethod() {
* this._counters.increment("mycomponent.mymethod.calls");
* Timing timing = this._counters.beginTiming("mycomponent.mymethod.exec_time");
* try {
* ...
* } finally {
* timing.endTiming();
* }
* }
* }
* }
*
* @see ICounters
*/
public class CompositeCounters implements ICounters, ITimingCallback, IReferenceable {
private List _counters = new ArrayList();
/**
* Creates a new instance of the counters.
*/
public CompositeCounters() {
}
/**
* Sets references to dependent components.
*
* @param references references to locate the component dependencies.
* @throws ReferenceException when no references found.
*/
public void setReferences(IReferences references) throws ReferenceException {
List