Class UnboundedEventsCollector<T>
- java.lang.Object
-
- org.pipecraft.infra.monitoring.collectors.UnboundedEventsCollector<T>
-
- Type Parameters:
T- The data type representing the different categories. Must be suitable for hash structure keys! Thread safe.
- All Implemented Interfaces:
JsonMonitorable
public class UnboundedEventsCollector<T> extends Object implements JsonMonitorable
Collects counts on an unbounded set of categories. UnlikeEventsCollector, which works with a closed set defined by an enum, here we allow values that aren't known in advance. This may results in bigger memory consumption, so this utility should be used with caution. This collector also supports an atomic reset operation for a given category- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description UnboundedEventsCollector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcountEvent(T category, long multiplicity)Increments an event counterEventStatsMap<T>getAll()Set<T>getCategories()Map<String,? extends JsonMonitorable>getChildren()longgetCount(T category)net.minidev.json.JSONObjectgetOwnMetrics()longreset(T category)Resets a counter.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.pipecraft.infra.monitoring.JsonMonitorable
getFullMetrics
-
-
-
-
Method Detail
-
getCategories
public Set<T> getCategories()
- Returns:
- The set of categories currently maintained by this collector. Read only.
-
countEvent
public void countEvent(T category, long multiplicity)
Increments an event counter- Parameters:
category- The event categorymultiplicity- The amount to increment by
-
reset
public long reset(T category)
Resets a counter.- Parameters:
category- The counter category- Returns:
- The last value seen before the counter was reset. The retrieval of last value and the reseting are performed as a single atomic operation.
-
getCount
public long getCount(T category)
- Parameters:
category- An event category- Returns:
- The current count in the given category
-
getAll
public EventStatsMap<T> getAll()
- Returns:
- A snapshot of the event counts map. Not necessarily consistent.
-
getOwnMetrics
public net.minidev.json.JSONObject getOwnMetrics()
- Specified by:
getOwnMetricsin interfaceJsonMonitorable- Returns:
- The json string describing the entity, not including the child entities.
-
getChildren
public Map<String,? extends JsonMonitorable> getChildren()
- Specified by:
getChildrenin interfaceJsonMonitorable- Returns:
- The monitorable children of this entity, as [id, JsonExportable] pairs. Using this method, the framework can manage a complete tree to be monitored, where every entity has a unique path.
-
-