public final class MetricBuffer extends Object
This class is particularly useful when you want to:
| Constructor and Description |
|---|
MetricBuffer(int capacity)
Creates a new buffer with fixed capacity.
|
| Modifier and Type | Method and Description |
|---|---|
void |
insert(SingleMetric metric)
Inserts a new element in this buffer.
|
void |
reInsert(List<SingleMetric> metrics)
Re-inserts a batch previously removed with
remove(int). |
int |
remainingCapacity() |
List<SingleMetric> |
remove(int batchSize)
Retrieves and removes the oldest elements in this buffer.
|
int |
size() |
public MetricBuffer(int capacity)
capacity - the maximum number of elements in the bufferpublic int size()
public int remainingCapacity()
public void insert(SingleMetric metric)
remainingCapacity() is zero, the oldest element is discarded.metric - silently ignored if nullpublic List<SingleMetric> remove(int batchSize)
batchSize - the desired number of elements to returnbatchSize and buffer sizeIllegalArgumentException - if batchSize < 0public void reInsert(List<SingleMetric> metrics)
remove(int). Elements are re-inserted as much as
capacity permits. The elements are expected to be sorted in their order of insertion in the buffer before they
were removed.
Example
Consider a buffer with a capacity of 5 elements. The buffer is filled with five elements:
buffer.insert(metric1); ... ; buffer.insert(metric5);The buffer looks like:
metric5 >> metric4 >> metric3 >> metric2 >> metric1A batch of two elements is removed:
List batch = buffer.remove(2);The buffer looks like:
metric5 >> metric4 >> metric3And the
batch list:
metric1 << metric2Now a new element is inserted:
buffer.insert(metric6);The buffers looks like:
metric6 >> metric5 >> metric4 >> metric3But the batch previously removed needs to be re-inserted, because sending failed.
buffer.reInsert(batch);As there's room for a single element, after re-insertion the buffer will look like:
metric6 >> metric5 >> metric4 >> metric3 >> metric2
metrics - silently ignored if null or empty; null elements in the list are also silently ignoredCopyright © 2014–2017 Red Hat, Inc.. All rights reserved.