Use calculateTimeIdx to calculate array idx in LeapArray#getPreviousWindow (#723)
* also some code cleanup
This commit is contained in:
parent
ee38587a6e
commit
0176f0ead3
|
|
@ -147,8 +147,7 @@ public class StatisticNode implements Node {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long totalRequest() {
|
public long totalRequest() {
|
||||||
long totalRequest = rollingCounterInMinute.pass() + rollingCounterInMinute.block();
|
return rollingCounterInMinute.pass() + rollingCounterInMinute.block();
|
||||||
return totalRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -209,8 +209,7 @@ public abstract class LeapArray<T> {
|
||||||
if (timeMillis < 0) {
|
if (timeMillis < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long timeId = (timeMillis - windowLengthInMs) / windowLengthInMs;
|
int idx = calculateTimeIdx(timeMillis - windowLengthInMs);
|
||||||
int idx = (int)(timeId % array.length());
|
|
||||||
timeMillis = timeMillis - windowLengthInMs;
|
timeMillis = timeMillis - windowLengthInMs;
|
||||||
WindowWrap<T> wrap = array.get(idx);
|
WindowWrap<T> wrap = array.get(idx);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,8 @@ public class ArrayMetric implements Metric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long previousWindowBlock() {
|
public long previousWindowBlock() {
|
||||||
WindowWrap<MetricBucket> wrap = data.currentWindow();
|
data.currentWindow();
|
||||||
wrap = data.getPreviousWindow();
|
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
|
||||||
if (wrap == null) {
|
if (wrap == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -244,8 +244,8 @@ public class ArrayMetric implements Metric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long previousWindowPass() {
|
public long previousWindowPass() {
|
||||||
WindowWrap<MetricBucket> wrap = data.currentWindow();
|
data.currentWindow();
|
||||||
wrap = data.getPreviousWindow();
|
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
|
||||||
if (wrap == null) {
|
if (wrap == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue