From 1cf027964415438232e53e31fb44f185690029c4 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 18 Jun 2015 11:48:14 +0300 Subject: [PATCH] APIMeter update the included value on each click This change update the internal value on each time click, after this change the rate calculation will be done on the proxy at the price of continuesly query the server. It is yet to be determine if this is a problem, if so, it is possible to do and store those calculation on the server and just pull them on demend. Signed-off-by: Amnon Heiman --- .../com/yammer/metrics/core/APIMeter.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yammer/metrics/core/APIMeter.java b/src/main/java/com/yammer/metrics/core/APIMeter.java index fc1a801..5c216c9 100644 --- a/src/main/java/com/yammer/metrics/core/APIMeter.java +++ b/src/main/java/com/yammer/metrics/core/APIMeter.java @@ -21,9 +21,25 @@ public class APIMeter extends Meter { url = _url; } - @Override - public long count() { + public long get_value() { return c.getLongValue(url); } + // Meter doesn't have a set value method. + // to mimic it, we clear the old value and set it to a new one. + // This is safe because the only this method would be used + // to update the values + public long set(long new_value) { + long res = super.count(); + mark(-res); + mark(new_value); + return res; + } + + @Override + void tick() { + set(get_value()); + super.tick(); + } + }