ColumnFamilyStore: Preparation for removing the pull mode

This expose the ColumnFamilyStore registration via static method.

It would allow an external object (ie. MBeanServer) to update the
registration on demand.

Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
Amnon Heiman 2016-05-02 12:54:20 +03:00
parent 9f2f92c379
commit 5c33a8afa7

View File

@ -50,6 +50,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean {
private String keyspace;
private String name;
private String mbeanName;
private static APIClient s_c = new APIClient();
static final int INTERVAL = 1000; // update every 1second
public final ColumnFamilyMetrics metric;
@ -102,16 +103,9 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean {
+ ",columnfamily=" + name;
}
private static final class CheckRegistration extends TimerTask {
private APIClient c = new APIClient();
private int missed_response = 0;
// After MAX_RETRY retry we assume the API is not available
// and the jmx will shutdown
private static final int MAX_RETRY = 30;
@Override
public void run() {
public static boolean checkRegistration() {
try {
JsonArray mbeans = c.getJsonArray("/column_family/");
JsonArray mbeans = s_c.getJsonArray("/column_family/");
Set<String> all_cf = new HashSet<String>();
for (int i = 0; i < mbeans.size(); i++) {
JsonObject mbean = mbeans.getJsonObject(i);
@ -131,12 +125,28 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean {
cf.remove(n);
}
}
missed_response = 0;
} catch (IllegalStateException e) {
return false;
}
return true;
}
private static final class CheckRegistration extends TimerTask {
private int missed_response = 0;
// After MAX_RETRY retry we assume the API is not available
// and the jmx will shutdown
private static final int MAX_RETRY = 30;
@Override
public void run() {
try {
if (checkRegistration()) {
missed_response = 0;
} else {
if (missed_response++ > MAX_RETRY) {
System.err.println("API is not available, JMX is shuting down");
System.exit(-1);
}
}
} catch (Exception e) {
// ignoring exceptions, will retry on the next interval
}