diff --git a/src/main/java/com/yammer/metrics/core/APIMeter.java b/src/main/java/com/yammer/metrics/core/APIMeter.java index 5c216c9..9e8be70 100644 --- a/src/main/java/com/yammer/metrics/core/APIMeter.java +++ b/src/main/java/com/yammer/metrics/core/APIMeter.java @@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit; import com.cloudius.urchin.api.APIClient; -public class APIMeter extends Meter { +public class APIMeter extends APISettableMeter { String url; private APIClient c = new APIClient(); @@ -25,19 +25,8 @@ public class APIMeter extends Meter { 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() { + public void tick() { set(get_value()); super.tick(); } diff --git a/src/main/java/com/yammer/metrics/core/APISettableMeter.java b/src/main/java/com/yammer/metrics/core/APISettableMeter.java new file mode 100644 index 0000000..51c92bb --- /dev/null +++ b/src/main/java/com/yammer/metrics/core/APISettableMeter.java @@ -0,0 +1,49 @@ +package com.yammer.metrics.core; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/* + * Copyright 2015 ScyllaDB + * + */ +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +public class APISettableMeter extends Meter { + + public APISettableMeter(ScheduledExecutorService tickThread, + String eventType, TimeUnit rateUnit, Clock clock) { + super(tickThread, eventType, rateUnit, clock); + } + + // 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 + public void tick() { + super.tick(); + } +}