Package org.apache.cassandra.metrics
Class Sampler<T>
- java.lang.Object
-
- org.apache.cassandra.metrics.Sampler<T>
-
- Direct Known Subclasses:
FrequencySampler
,MaxSampler
public abstract class Sampler<T> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Sampler.Sample<S>
Represents the ranked items collected during a sample periodstatic class
Sampler.SamplerType
-
Field Summary
Fields Modifier and Type Field Description static ExecutorPlus
samplerExecutor
-
Constructor Summary
Constructors Constructor Description Sampler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addSample(T item, int value)
abstract void
beginSampling(int capacity, long durationMillis)
Begin sampling with the configured capacity and durationvoid
disable()
abstract java.util.List<Sampler.Sample<T>>
finishSampling(int count)
Stop sampling and return the resultsprotected abstract void
insert(T item, long value)
boolean
isActive()
boolean
isEnabled()
A sampler is enabled between {@link this#beginSampling} and {@link this#finishSampling}static void
shutdownNowAndWait(long time, java.util.concurrent.TimeUnit units)
abstract java.lang.String
toString(T value)
void
updateEndTime(long endTimeMillis)
Update the end time for the sampler.
-
-
-
Field Detail
-
samplerExecutor
public static final ExecutorPlus samplerExecutor
-
-
Method Detail
-
addSample
public void addSample(T item, int value)
-
insert
protected abstract void insert(T item, long value)
-
isEnabled
public boolean isEnabled()
A sampler is enabled between {@link this#beginSampling} and {@link this#finishSampling}- Returns:
- true if the sampler is enabled.
-
disable
public void disable()
-
isActive
public boolean isActive()
- Returns:
- true if the sampler is active. A sampler is active only if it is enabled and the current time is within the `durationMillis` when beginning sampling.
-
updateEndTime
public void updateEndTime(long endTimeMillis)
Update the end time for the sampler. Implicitly, calling this method enables the sampler.
-
beginSampling
public abstract void beginSampling(int capacity, long durationMillis)
Begin sampling with the configured capacity and duration- Parameters:
capacity
- Number of sample items to keep in memory, the lower this is the less accurate results are. For best results use value close to cardinality, but understand the memory trade offs.durationMillis
- Upperbound duration in milliseconds for sampling. The sampler stops accepting new samples after exceeding the duration even iffinishSampling(int)
} is not called.
-
finishSampling
public abstract java.util.List<Sampler.Sample<T>> finishSampling(int count)
Stop sampling and return the results- Parameters:
count
- The number of the samples requested to retrieve from the sampler- Returns:
- a list of samples, the size is the minimum of the total samples and {@param count}.
-
toString
public abstract java.lang.String toString(T value)
-
shutdownNowAndWait
public static void shutdownNowAndWait(long time, java.util.concurrent.TimeUnit units) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
- Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException
-
-