use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getJsonObj.
public JsonObject getJsonObj(String string, MultivaluedMap<String, String> queryParams, long duration) {
if (string.equals("")) {
return null;
}
String key = getCacheKey(string, queryParams, duration);
JsonObject res = getJsonObjectFromCache(key, duration);
if (res != null) {
return res;
}
JsonReader reader = getReader(string, queryParams);
res = reader.readObject();
reader.close();
if (duration > 0) {
cache.put(key, new CacheEntry(res));
}
return res;
}
use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getMapStringSnapshotTabularDataValue.
public Map<String, TabularData> getMapStringSnapshotTabularDataValue(String string, MultivaluedMap<String, String> queryParams) {
if (string.equals("")) {
return null;
}
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
Map<String, TabularData> map = new HashMap<>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.getJsonObject(i);
if (obj.containsKey("key") && obj.containsKey("value")) {
String key = obj.getString("key");
map.put(key, getSnapshotData(key, obj.getJsonArray("value")));
}
}
reader.close();
return map;
}
use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getIntArrValue.
public int[] getIntArrValue(String string, MultivaluedMap<String, String> queryParams) {
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
int[] res = new int[arr.size()];
for (int i = 0; i < arr.size(); i++) {
res[i] = arr.getInt(i);
}
reader.close();
return res;
}
use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getMapStringDouble.
public Map<String, Double> getMapStringDouble(String string, MultivaluedMap<String, String> queryParams) {
if (string.equals("")) {
return null;
}
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
Map<String, Double> map = new HashMap<String, Double>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.getJsonObject(i);
Iterator<String> it = obj.keySet().iterator();
String key = "";
double val = -1;
while (it.hasNext()) {
String k = it.next();
if (obj.get(k) instanceof JsonString) {
key = obj.getString(k);
} else {
val = obj.getJsonNumber(k).doubleValue();
}
}
if (!key.equals("")) {
map.put(key, val);
}
}
reader.close();
return map;
}
use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getMapInetAddressFloatValue.
public Map<InetAddress, Float> getMapInetAddressFloatValue(String string, MultivaluedMap<String, String> queryParams) {
Map<InetAddress, Float> res = new HashMap<InetAddress, Float>();
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
JsonObject obj = null;
for (int i = 0; i < arr.size(); i++) {
try {
obj = arr.getJsonObject(i);
res.put(InetAddress.getByName(obj.getString("key")), Float.parseFloat(obj.getString("value")));
} catch (UnknownHostException e) {
logger.warning("Bad formatted address " + obj.getString("key"));
}
}
return res;
}
Aggregations