rename#243 code refactor

This commit is contained in:
Calvin
2013-12-27 10:57:16 +08:00
parent cc90f75d85
commit ee96d83eec
2 changed files with 15 additions and 16 deletions
@@ -32,23 +32,22 @@ public class Counter {
counter.addAndGet(-n);
}
public CounterMetric calculateMetric() {
public CounterMetric calculateMetric() {
long lastCount = counter.getAndSet(0);
long currentTime = clock.getCurrentTime();
long currentCount = counter.getAndSet(0);
long currentTime = clock.getCurrentTime();
CounterMetric metric = new CounterMetric();
CounterMetric metric = new CounterMetric();
totalCount += lastCount;
metric.lastCount = lastCount;
metric.totalCount = totalCount;
totalCount += currentCount;
metric.lastCount = currentCount;
metric.totalCount = totalCount;
long elapsed = currentTime - lastReportTime;
if (elapsed > 0) {
metric.lastRate = (lastCount * 1000) / elapsed;
}
long timePass = currentTime - lastReportTime;
if (timePass > 0) {
metric.lastRate = (currentCount * 1000) / timePass;
}
lastReportTime = currentTime;
return metric;
}
lastReportTime = currentTime;
return metric;
}
}
@@ -117,7 +117,7 @@ public class GraphiteReporter implements Reporter {
writer.write(' ');
writer.write(sanitize(value));
writer.write(' ');
writer.write(Long.toString(timestamp));
writer.write(format(timestamp));
writer.write('\n');
} catch (IOException e) {
throw e;