Signed-off-by: Eric Zhao <sczyh16@gmail.com>master
@@ -33,8 +33,7 @@ public class ClusterMetric { | |||||
AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); | AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); | ||||
AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); | AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); | ||||
AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); | AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); | ||||
int windowLengthInMs = intervalInMs / sampleCount; | |||||
this.metric = new ClusterMetricLeapArray(windowLengthInMs, intervalInMs); | |||||
this.metric = new ClusterMetricLeapArray(sampleCount, intervalInMs); | |||||
} | } | ||||
public void add(ClusterFlowEvent event, long count) { | public void add(ClusterFlowEvent event, long count) { | ||||
@@ -30,14 +30,8 @@ public class ClusterMetricLeapArray extends LeapArray<ClusterMetricBucket> { | |||||
private final LongAdder[] occupyCounter; | private final LongAdder[] occupyCounter; | ||||
private boolean hasOccupied = false; | private boolean hasOccupied = false; | ||||
/** | |||||
* The total bucket count is: {@link #sampleCount} = intervalInMs / windowLengthInMs. | |||||
* | |||||
* @param windowLengthInMs a single window bucket's time length in milliseconds. | |||||
* @param intervalInMs the total time span of this {@link LeapArray} in milliseconds. | |||||
*/ | |||||
public ClusterMetricLeapArray(int windowLengthInMs, int intervalInMs) { | |||||
super(windowLengthInMs, intervalInMs / 1000); | |||||
public ClusterMetricLeapArray(int sampleCount, int intervalInMs) { | |||||
super(sampleCount, intervalInMs); | |||||
ClusterFlowEvent[] events = ClusterFlowEvent.values(); | ClusterFlowEvent[] events = ClusterFlowEvent.values(); | ||||
this.occupyCounter = new LongAdder[events.length]; | this.occupyCounter = new LongAdder[events.length]; | ||||
for (ClusterFlowEvent event : events) { | for (ClusterFlowEvent event : events) { | ||||
@@ -39,8 +39,7 @@ public class ClusterParamMetric { | |||||
AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); | AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); | ||||
AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); | AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); | ||||
AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); | AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); | ||||
int windowLengthInMs = intervalInMs / sampleCount; | |||||
this.metric = new ClusterParameterLeapArray<>(windowLengthInMs, intervalInMs, maxCapacity); | |||||
this.metric = new ClusterParameterLeapArray<>(sampleCount, intervalInMs, maxCapacity); | |||||
} | } | ||||
public long getSum(Object value) { | public long getSum(Object value) { | ||||
@@ -30,8 +30,8 @@ public class ClusterParameterLeapArray<C> extends LeapArray<CacheMap<Object, C>> | |||||
private final int maxCapacity; | private final int maxCapacity; | ||||
public ClusterParameterLeapArray(int windowLengthInMs, int intervalInMs, int maxCapacity) { | |||||
super(windowLengthInMs, intervalInMs / 1000); | |||||
public ClusterParameterLeapArray(int sampleCount, int intervalInMs, int maxCapacity) { | |||||
super(sampleCount, intervalInMs); | |||||
AssertUtil.isTrue(maxCapacity > 0, "maxCapacity of LRU map should be positive"); | AssertUtil.isTrue(maxCapacity > 0, "maxCapacity of LRU map should be positive"); | ||||
this.maxCapacity = maxCapacity; | this.maxCapacity = maxCapacity; | ||||
} | } | ||||