Adding the APISettableMeter
Sometimes it is required that a meter will not handle its own data, like the APIMeter does. This patch break the added functionality of APIMeter into two classes, APISettableMeter is a Meter with a set value method and APIMeter adds the functionality that reads from the API. Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
parent
b783a0d09a
commit
ac049129de
@ -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();
|
||||
}
|
||||
|
49
src/main/java/com/yammer/metrics/core/APISettableMeter.java
Normal file
49
src/main/java/com/yammer/metrics/core/APISettableMeter.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user