T - type of statistic datapublic abstract class LeapArray<T> extends Object
Basic data structure for statistic metrics in Sentinel.
Leap array use sliding window algorithm to count data. Each bucket cover windowLengthInMs time span,
and the total time span is intervalInMs, so the total bucket amount is:
sampleCount = intervalInMs / windowLengthInMs.
| Modifier and Type | Field and Description |
|---|---|
protected AtomicReferenceArray<WindowWrap<T>> |
array |
protected int |
intervalInMs |
protected int |
sampleCount |
protected int |
windowLengthInMs |
| Constructor and Description |
|---|
LeapArray(int sampleCount,
int intervalInMs)
The total bucket count is:
sampleCount = intervalInMs / windowLengthInMs. |
| Modifier and Type | Method and Description |
|---|---|
void |
addWaiting(long time,
int acquireCount) |
protected long |
calculateWindowStart(long timeMillis) |
long |
currentWaiting() |
WindowWrap<T> |
currentWindow()
Get the bucket at current timestamp.
|
WindowWrap<T> |
currentWindow(long timeMillis)
Get bucket item at provided timestamp.
|
void |
debug(long time) |
int |
getIntervalInMs()
Get total interval length of the sliding window in milliseconds.
|
double |
getIntervalInSecond()
Get total interval length of the sliding window.
|
WindowWrap<T> |
getPreviousWindow()
Get the previous bucket item for current timestamp.
|
WindowWrap<T> |
getPreviousWindow(long timeMillis)
Get the previous bucket item before provided timestamp.
|
int |
getSampleCount()
Get sample count (total amount of buckets).
|
WindowWrap<T> |
getValidHead()
Get the valid "head" bucket of the sliding window at current timestamp.
|
T |
getWindowValue(long timeMillis)
Get statistic value from bucket for provided timestamp.
|
boolean |
isWindowDeprecated(long time,
WindowWrap<T> windowWrap) |
boolean |
isWindowDeprecated(WindowWrap<T> windowWrap)
Check if a bucket is deprecated, which means that the bucket
has been behind for at least an entire window time span.
|
List<WindowWrap<T>> |
list()
Get valid bucket list for entire sliding window.
|
List<WindowWrap<T>> |
list(long validTime) |
List<WindowWrap<T>> |
listAll()
Get all buckets for entire sliding window including deprecated buckets.
|
abstract T |
newEmptyBucket(long timeMillis)
Create a new statistic value for bucket.
|
protected abstract WindowWrap<T> |
resetWindowTo(WindowWrap<T> windowWrap,
long startTime)
Reset given bucket to provided start time and reset the value.
|
List<T> |
values()
Get aggregated value list for entire sliding window.
|
List<T> |
values(long timeMillis) |
protected int windowLengthInMs
protected int sampleCount
protected int intervalInMs
protected final AtomicReferenceArray<WindowWrap<T>> array
public LeapArray(int sampleCount,
int intervalInMs)
sampleCount = intervalInMs / windowLengthInMs.sampleCount - bucket count of the sliding windowintervalInMs - the total time interval of this LeapArray in millisecondspublic WindowWrap<T> currentWindow()
public abstract T newEmptyBucket(long timeMillis)
timeMillis - current time in millisecondsprotected abstract WindowWrap<T> resetWindowTo(WindowWrap<T> windowWrap, long startTime)
startTime - the start time of the bucket in millisecondswindowWrap - current bucketprotected long calculateWindowStart(long timeMillis)
public WindowWrap<T> currentWindow(long timeMillis)
timeMillis - a valid timestamp in millisecondspublic WindowWrap<T> getPreviousWindow(long timeMillis)
timeMillis - a valid timestamp in millisecondspublic WindowWrap<T> getPreviousWindow()
public T getWindowValue(long timeMillis)
timeMillis - a valid timestamp in millisecondspublic boolean isWindowDeprecated(WindowWrap<T> windowWrap)
windowWrap - a non-null bucketpublic boolean isWindowDeprecated(long time,
WindowWrap<T> windowWrap)
public List<WindowWrap<T>> list()
public List<WindowWrap<T>> list(long validTime)
public List<WindowWrap<T>> listAll()
public List<T> values()
public WindowWrap<T> getValidHead()
public int getSampleCount()
public int getIntervalInMs()
public double getIntervalInSecond()
public void debug(long time)
public long currentWaiting()
public void addWaiting(long time,
int acquireCount)
Copyright © 2019 Alibaba Group. All rights reserved.