T
- Type of object stored.public abstract class AbstractListBackedAggregator<T> extends AbstractTimedAggregator<T>
AbstractTimedAggregator.add(Object)
will add an item in the array and there is no limit to
how much data we can store. It is down to subclasses to decide which types of
List implementation they need to used -- and the abstract factory
createList()
is provided for this.
This implementation also allows for various "aggregations" of the list to be
used by providing a Function
in the
constructor., T>
Thread safety : Note that due to the fact that
AbstractTimedAggregator
provides a threadsafe environment for access
to data, the List
implementation can be unsynchronized.
AbstractTimedAggregator
NO_TIMER, TIMER_NAME
Constructor and Description |
---|
AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction)
Default constructor.
|
AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction,
long interval)
|
AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction,
long interval,
boolean useSharedTimer)
Constructs an aggregator which will use the given function, reset itself
at the given interval and will use a shared timer on own private timer.
|
Modifier and Type | Method and Description |
---|---|
protected abstract List<T> |
createList()
Allows subclasses to create the list which will store the
data series . |
void |
doAdd(T data)
Adds data to the series which will be aggregated.
|
protected T |
doEvaluate()
The actual "beef" of this class: iterate through the list and aggregates
all the data and evaluates the result.
|
protected void |
doReset()
Resets the data series to the empty state.
|
protected List<T> |
getSeries()
Getter for
series . |
protected int |
retrieveDataSize()
Simply returns the size of the data series which is the size of the list
used internally.
|
String |
toString() |
add, addTimerListener, evaluate, finalize, getDataSize, getInterval, isSharedTimer, isTimerEnabled, removeTimerListener, reset, stop
public AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction)
AbstractListBackedAggregator(aggregationFunction,0L
.aggregationFunction
- Aggregation function to use in AbstractTimedAggregator.evaluate()
. Throws
NullPointerException
if this is null
public AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction, long interval)
aggregationFunction
- Aggregation function to use in AbstractTimedAggregator.evaluate()
. Throws
NullPointerException
if this is null
interval
- interval in miliseconds to reset this aggregatorpublic AbstractListBackedAggregator(Function<List<T>,T> aggregationFunction, long interval, boolean useSharedTimer)
aggregationFunction
- Aggregation function to use in AbstractTimedAggregator.evaluate()
. Throws
NullPointerException
if this is null
interval
- interval in miliseconds to reset this aggregatoruseSharedTimer
- if set to true, it will use a shared timer, as per
AbstractTimedAggregator.AbstractTimedAggregator(long, boolean)
; otherwise if it's false it will use its own timer instanceAbstractTimedAggregator.AbstractTimedAggregator(long, boolean)
public final void doAdd(T data)
series
list.doAdd
in class AbstractTimedAggregator<T>
data
- Data to be added to the data series.AbstractTimedAggregator.add(Object)
protected final T doEvaluate()
aggregationFunction.evaluate(series)
.doEvaluate
in class AbstractTimedAggregator<T>
aggregationFunction.evaluate(series)
NullaryFunction.evaluate()
protected final void doReset()
doReset
in class AbstractTimedAggregator<T>
protected abstract List<T> createList()
data series
.List
which will be used to store the
data.protected final int retrieveDataSize()
retrieveDataSize
in class AbstractTimedAggregator<T>
series
-- equivalent to
series.size()
public String toString()
toString
in class AbstractTimedAggregator<T>
Copyright © 2003–2014 The Apache Software Foundation. All rights reserved.