Merge commit log API

Amnon says:

"After this patch series, it will be possible to run the JMX API and using
jconsole get the ActiveSegmentName and (the empty) ArchivingSegmentNames."
This commit is contained in:
Avi Kivity 2015-05-19 18:13:38 +03:00
commit 088c7c356b
3 changed files with 26 additions and 6 deletions

View File

@ -5,6 +5,7 @@ package com.cloudius.urchin.api;
import java.io.StringReader;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -71,8 +72,15 @@ public class APIClient {
}
public List<String> getListStrValue(String string) {
// TODO Auto-generated method stub
return null;
JsonReader reader = getReader(string);
JsonArray arr = reader.readArray();
List<String> res = new ArrayList<String>(arr.size());
for (int i = 0; i < arr.size(); i++) {
res.add(arr.getString(i));
}
reader.close();
return res;
}
public Map<List<String>, List<String>> getMapListStrValue(String string) {

View File

@ -43,7 +43,6 @@ public class CommitLog implements CommitLogMBean {
private APIClient c = new APIClient();
public void log(String str) {
System.out.println(str);
logger.info(str);
}
@ -52,6 +51,7 @@ public class CommitLog implements CommitLogMBean {
public static CommitLog getInstance() {
return instance;
}
private CommitLog() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
@ -108,7 +108,13 @@ public class CommitLog implements CommitLogMBean {
*/
public List<String> getActiveSegmentNames() {
log(" getActiveSegmentNames()");
return c.getListStrValue("");
List<String> lst = c.getListStrValue("/commitlog/segments/active");
Set<String> set = new HashSet<String>();
for (String l : lst) {
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
set.add(name);
}
return new ArrayList<String>(set);
}
/**
@ -117,7 +123,13 @@ public class CommitLog implements CommitLogMBean {
*/
public List<String> getArchivingSegmentNames() {
log(" getArchivingSegmentNames()");
return c.getListStrValue("");
List<String> lst = c.getListStrValue("/commitlog/segments/archiving");
Set<String> set = new HashSet<String>();
for (String l : lst) {
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
set.add(name);
}
return new ArrayList<String>(set);
}
}

View File

@ -45,7 +45,7 @@ public class EndpointSnitchInfo implements EndpointSnitchInfoMBean {
private EndpointSnitchInfo() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
mbs.registerMBean(new EndpointSnitchInfo(), new ObjectName(
mbs.registerMBean(this, new ObjectName(
"org.apache.cassandra.db:type=EndpointSnitchInfo"));
} catch (Exception e) {
throw new RuntimeException(e);