Class InaccurateSampler<T>
- java.lang.Object
-
- org.pipecraft.infra.monitoring.sampling.InaccurateSampler<T>
-
- Type Parameters:
T- The type of the values to be sampled.
- All Implemented Interfaces:
JsonMonitorable,Sampler<T>
public class InaccurateSampler<T> extends Object implements Sampler<T>
A utility for sampling of recent values, using a non-blocking approach for improved performance. A capacity of K doesn't guarantee that last K values are stored, though it is highly probable, assuming that threads aren't likely to perform the sample operation at the exact same time. What this implementation does guarantee, is that the K items stored in the sample are a subset of the last K*Min(P,T) calls to the sampler, where T stands for the number of threads performing sampling, and P stands for the number of cores.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description InaccurateSampler(int size)ConstructorInaccurateSampler(int size, SampleTextualizer<T> textualizer)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,JsonMonitorable>getChildren()net.minidev.json.JSONObjectgetOwnMetrics()Collection<T>getSnapshot()booleannewValue(T value)Notifies about a new valueintsize()-
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
-
-
-
-
Constructor Detail
-
InaccurateSampler
public InaccurateSampler(int size, SampleTextualizer<T> textualizer)Constructor- Parameters:
size- The number of sampled values to keeptextualizer- The textualizer to use for converting sample items into text for monitoring purposes
-
InaccurateSampler
public InaccurateSampler(int size)
Constructor- Parameters:
size- The number of sampled values to keep
-
-
Method Detail
-
newValue
public boolean newValue(T value)
Description copied from interface:SamplerNotifies about a new value
-
getSnapshot
public Collection<T> getSnapshot()
- Specified by:
getSnapshotin interfaceSampler<T>- Returns:
- The collection of all values currently stored in the sampler. Consistency is not guaranteed (i.e. this is not necessarily a real snapshot of the inner collection). Note that null values or unrecorded values are returned as nulls.
-
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,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.
-
-