类 LeapArray<T>
java.lang.Object
com.alibaba.csp.sentinel.slots.statistic.base.LeapArray<T>
- 类型参数:
T- type of statistic data
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.
- 作者:
- jialiang.linjl, Eric Zhao, Carpenter Lee
-
字段概要
字段修饰符和类型字段说明protected final AtomicReferenceArray<WindowWrap<T>>protected intprotected intprotected int -
构造器概要
构造器构造器说明LeapArray(int sampleCount, int intervalInMs) The total bucket count is:sampleCount = intervalInMs / windowLengthInMs. -
方法概要
修饰符和类型方法说明voidaddWaiting(long time, int acquireCount) protected longcalculateWindowStart(long timeMillis) longGet the bucket at current timestamp.currentWindow(long timeMillis) Get bucket item at provided timestamp.voiddebug(long time) intGet total interval length of the sliding window in milliseconds.doubleGet total interval length of the sliding window.Get the previous bucket item for current timestamp.getPreviousWindow(long timeMillis) Get the previous bucket item before provided timestamp.intGet sample count (total amount of buckets).Get the valid "head" bucket of the sliding window at current timestamp.getWindowValue(long timeMillis) Get statistic value from bucket for provided timestamp.booleanisWindowDeprecated(long time, WindowWrap<T> windowWrap) booleanisWindowDeprecated(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 TnewEmptyBucket(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.values()Get aggregated value list for entire sliding window.values(long timeMillis)
-
字段详细资料
-
windowLengthInMs
protected int windowLengthInMs -
sampleCount
protected int sampleCount -
intervalInMs
protected int intervalInMs -
array
-
-
构造器详细资料
-
LeapArray
public LeapArray(int sampleCount, int intervalInMs) The total bucket count is:sampleCount = intervalInMs / windowLengthInMs.- 参数:
sampleCount- bucket count of the sliding windowintervalInMs- the total time interval of thisLeapArrayin milliseconds
-
-
方法详细资料
-
currentWindow
Get the bucket at current timestamp.- 返回:
- the bucket at current timestamp
-
newEmptyBucket
Create a new statistic value for bucket.- 参数:
timeMillis- current time in milliseconds- 返回:
- the new empty bucket
-
resetWindowTo
Reset given bucket to provided start time and reset the value.- 参数:
startTime- the start time of the bucket in millisecondswindowWrap- current bucket- 返回:
- new clean bucket at given start time
-
calculateWindowStart
protected long calculateWindowStart(long timeMillis) -
currentWindow
Get bucket item at provided timestamp.- 参数:
timeMillis- a valid timestamp in milliseconds- 返回:
- current bucket item at provided timestamp if the time is valid; null if time is invalid
-
getPreviousWindow
Get the previous bucket item before provided timestamp.- 参数:
timeMillis- a valid timestamp in milliseconds- 返回:
- the previous bucket item before provided timestamp
-
getPreviousWindow
Get the previous bucket item for current timestamp.- 返回:
- the previous bucket item for current timestamp
-
getWindowValue
Get statistic value from bucket for provided timestamp.- 参数:
timeMillis- a valid timestamp in milliseconds- 返回:
- the statistic value if bucket for provided timestamp is up-to-date; otherwise null
-
isWindowDeprecated
Check if a bucket is deprecated, which means that the bucket has been behind for at least an entire window time span.- 参数:
windowWrap- a non-null bucket- 返回:
- true if the bucket is deprecated; otherwise false
-
isWindowDeprecated
-
list
Get valid bucket list for entire sliding window. The list will only contain "valid" buckets.- 返回:
- valid bucket list for entire sliding window.
-
list
-
listAll
Get all buckets for entire sliding window including deprecated buckets.- 返回:
- all buckets for entire sliding window
-
values
Get aggregated value list for entire sliding window. The list will only contain value from "valid" buckets.- 返回:
- aggregated value list for entire sliding window
-
values
-
getValidHead
Get the valid "head" bucket of the sliding window at current timestamp.- 返回:
- the "head" bucket if it exists and is valid; otherwise null
-
getSampleCount
public int getSampleCount()Get sample count (total amount of buckets).- 返回:
- sample count
-
getIntervalInMs
public int getIntervalInMs()Get total interval length of the sliding window in milliseconds.- 返回:
- interval in second
-
getIntervalInSecond
public double getIntervalInSecond()Get total interval length of the sliding window.- 返回:
- interval in second
-
debug
public void debug(long time) -
currentWaiting
public long currentWaiting() -
addWaiting
public void addWaiting(long time, int acquireCount)
-