类 LeapArray<T>

java.lang.Object
com.alibaba.csp.sentinel.slots.statistic.base.LeapArray<T>
类型参数:
T - type of statistic data
直接已知子类:
BucketLeapArray, FutureBucketLeapArray, OccupiableBucketLeapArray, UnaryLeapArray

public 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.

作者:
jialiang.linjl, Eric Zhao, Carpenter Lee
  • 字段详细资料

    • windowLengthInMs

      protected int windowLengthInMs
    • sampleCount

      protected int sampleCount
    • intervalInMs

      protected int intervalInMs
    • array

      protected final AtomicReferenceArray<WindowWrap<T>> array
  • 构造器详细资料

    • LeapArray

      public LeapArray(int sampleCount, int intervalInMs)
      The total bucket count is: sampleCount = intervalInMs / windowLengthInMs.
      参数:
      sampleCount - bucket count of the sliding window
      intervalInMs - the total time interval of this LeapArray in milliseconds
  • 方法详细资料

    • currentWindow

      public WindowWrap<T> currentWindow()
      Get the bucket at current timestamp.
      返回:
      the bucket at current timestamp
    • newEmptyBucket

      public abstract T newEmptyBucket(long timeMillis)
      Create a new statistic value for bucket.
      参数:
      timeMillis - current time in milliseconds
      返回:
      the new empty bucket
    • resetWindowTo

      protected abstract WindowWrap<T> resetWindowTo(WindowWrap<T> windowWrap, long startTime)
      Reset given bucket to provided start time and reset the value.
      参数:
      startTime - the start time of the bucket in milliseconds
      windowWrap - current bucket
      返回:
      new clean bucket at given start time
    • calculateWindowStart

      protected long calculateWindowStart(long timeMillis)
    • currentWindow

      public WindowWrap<T> currentWindow(long timeMillis)
      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

      public WindowWrap<T> getPreviousWindow(long timeMillis)
      Get the previous bucket item before provided timestamp.
      参数:
      timeMillis - a valid timestamp in milliseconds
      返回:
      the previous bucket item before provided timestamp
    • getPreviousWindow

      public WindowWrap<T> getPreviousWindow()
      Get the previous bucket item for current timestamp.
      返回:
      the previous bucket item for current timestamp
    • getWindowValue

      public T getWindowValue(long timeMillis)
      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

      public 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.
      参数:
      windowWrap - a non-null bucket
      返回:
      true if the bucket is deprecated; otherwise false
    • isWindowDeprecated

      public boolean isWindowDeprecated(long time, WindowWrap<T> windowWrap)
    • list

      public List<WindowWrap<T>> list()
      Get valid bucket list for entire sliding window. The list will only contain "valid" buckets.
      返回:
      valid bucket list for entire sliding window.
    • list

      public List<WindowWrap<T>> list(long validTime)
    • listAll

      public List<WindowWrap<T>> listAll()
      Get all buckets for entire sliding window including deprecated buckets.
      返回:
      all buckets for entire sliding window
    • values

      public List<T> 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

      public List<T> values(long timeMillis)
    • getValidHead

      public WindowWrap<T> 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)