mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
add generalized error handling in http
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -17,4 +18,5 @@ public interface Element {
|
||||
|
||||
<T> T getOr(String name, T defaultValue);
|
||||
|
||||
Map<String, Object> getMap();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A generic type-safe reader interface for parameters.
|
||||
* TODO: This should be consolidated with the design of ConfigLoader once the features of these two APIs are stabilized.
|
||||
@@ -13,6 +15,8 @@ public interface ElementData {
|
||||
|
||||
Object get(String name);
|
||||
|
||||
Set<String> getKeys();
|
||||
|
||||
boolean containsKey(String name);
|
||||
|
||||
// default ElementData getChildElementData(String name) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public class ElementImpl implements Element {
|
||||
|
||||
@@ -50,5 +48,18 @@ public class ElementImpl implements Element {
|
||||
return get(name, cls).orElse(defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getMap() {
|
||||
Set<String> keys = this.data.getKeys();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
|
||||
for (String key : keys) {
|
||||
Object value = this.data.get(key);
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JsonBackedConfigElement implements ElementData {
|
||||
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
@@ -20,6 +22,11 @@ public class JsonBackedConfigElement implements ElementData {
|
||||
return jsonObject.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return jsonObject.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String name) {
|
||||
return jsonObject.keySet().contains(name);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MapBackedElement implements ElementData {
|
||||
|
||||
@@ -15,6 +16,11 @@ public class MapBackedElement implements ElementData {
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(String name) {
|
||||
return map.containsKey(name);
|
||||
|
||||
Reference in New Issue
Block a user