T
- Which must be Double, Long, or String.public class History<T> extends Object
This class is thread-safe.
Modifier and Type | Class and Description |
---|---|
class |
History.SampleIterator
Takes a snapshot of the samples in the
History and then visits those
samples. |
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log |
Modifier | Constructor and Description |
---|---|
protected |
History(int capacity,
History<T> source)
Constructor used when aggregating from another collection period.
|
|
History(T[] data,
long period,
boolean overwrite)
Constructor used at the base collection period.
|
Modifier and Type | Method and Description |
---|---|
void |
add(long timestamp,
T value)
Adds a sample to the history.
|
int |
capacity()
The #of samples that can be stored in the buffer.
|
T |
getAverage()
Computes the average of the samples.
|
T |
getAverage(int nperiods)
Compute the average of the samples over the last N reporting periods.
|
long |
getPeriod()
The period in milliseconds between each sample in the buffer.
|
IHistoryEntry<T> |
getSample()
Return a snapshot of the most recent value in the buffer -or-
null if there are no samples in the buffer. |
protected History<T> |
getSink()
The sink on which the history writes when it overflows -or-
null if no sink has been assigned (it is assigned by the
alternate ctor). |
History |
getSource()
The source
History which feeds this one. |
Class |
getValueType()
The datatype for the individual values.
|
boolean |
isDouble() |
boolean |
isLong() |
boolean |
isNumeric() |
History.SampleIterator |
iterator()
Visits a snapshot of the samples in the buffer in timestamp order.
|
int |
size()
The #of non-missing samples that are stored in the buffer.
|
String |
toString()
Return a representation of a snapshot of the samples in buffer.
|
protected T |
valueOf(double d)
Convert a double to an instance of the generic type parameter for
this class.
|
public History(T[] data, long period, boolean overwrite)
data
- An array whose size is the capacity of the history buffer. The
contents of the array will be used to store the data. (This
API requirement arises since generics are fixed at compile
time rather than runtime.)period
- The period covered by each slot in milliseconds.overwrite
- true
iff overwrite of slots in the buffer is
allowed (when false
the buffer will fill up and
then refuse additional samples if they would overwrite slots
which are in use).public long getPeriod()
public int capacity()
public int size()
public boolean isNumeric()
public boolean isLong()
public boolean isDouble()
public Class getValueType()
public IHistoryEntry<T> getSample()
null
if there are no samples in the buffer.public History.SampleIterator iterator()
public String toString()
public T getAverage()
null
if the samples are not
numbers (no average is reported for dates, strings, etc).public T getAverage(int nperiods)
nperiods
- The #of reporting periods over which the average is to be
computed. E.g., last 10 minutes. The reporting periods have to
be read from the logicalSlot for 10 minutes ago up through the
current logicalSlot.IllegalArgumentException
- If you request data that is older (in reporting periods) that
is stored within the history. E.g., you can not ask for more
than a 60 minute average if the reporting period is minutes
and the capacity is 60.protected T valueOf(double d)
d
- The double value.public void add(long timestamp, T value)
If the history wraps around into the next period and there is another history that aggregates this one, then the average for the last period will be added to the aggregating history.
Multiple samples in the same period are recorded as (a) the total of those samples in the period; and (b) the #of samples in the period.
timestamp
- The timestamp associated with the sample.value
- The sampled value.IllegalArgumentException
- if the timestamp is non-postitive.TimestampOrderException
- if the timestamp is way out of the current range for the
history buffer.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.