mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-11 16:32:01 -06:00
package organization
This commit is contained in:
parent
2ab118f400
commit
cfa92eabcc
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.core;
|
||||
package io.nosqlbench.engine.core.lifecycle;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -29,7 +29,7 @@ public class IndexedThreadFactory implements ThreadFactory {
|
||||
|
||||
private final Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
|
||||
private String name = Thread.currentThread().getName() + "-factory";
|
||||
private AtomicInteger threadIndexer = new AtomicInteger(0);
|
||||
private final AtomicInteger threadIndexer = new AtomicInteger(0);
|
||||
|
||||
public IndexedThreadFactory(String name, Thread.UncaughtExceptionHandler exceptionHandler) {
|
||||
this.name = name;
|
||||
@ -38,7 +38,7 @@ public class IndexedThreadFactory implements ThreadFactory {
|
||||
|
||||
public class IndexedThread extends Thread {
|
||||
|
||||
private int threadIndex;
|
||||
private final int threadIndex;
|
||||
private String metricName = "default-name-" + Thread.currentThread().getName();
|
||||
|
||||
public IndexedThread(int threadIndex, Runnable r) {
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.nosqlbench.engine.core;
|
||||
package io.nosqlbench.engine.core.lifecycle;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.Shutdownable;
|
||||
|
||||
@ -22,8 +22,10 @@ import java.util.LinkedList;
|
||||
* A simple callback handler for shutting down things gracefully.
|
||||
*/
|
||||
public class ShutdownManager {
|
||||
private ShutdownManager() {}
|
||||
private static ShutdownManager instance = new ShutdownManager();
|
||||
private ShutdownManager() {
|
||||
}
|
||||
|
||||
private static final ShutdownManager instance = new ShutdownManager();
|
||||
|
||||
private final LinkedList<Shutdownable> managedInstances = new LinkedList<>();
|
||||
|
@ -15,7 +15,7 @@
|
||||
package io.nosqlbench.engine.core.script;
|
||||
|
||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.core.ScenarioController;
|
||||
import io.nosqlbench.engine.core.lifecycle.ScenarioController;
|
||||
import org.graalvm.polyglot.Value;
|
||||
import org.graalvm.polyglot.proxy.ProxyObject;
|
||||
|
||||
@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
public class NashornActivityBindings implements Bindings, ProxyObject {
|
||||
|
||||
private final ScenarioController scenario;
|
||||
private Map<String,Bindings> elementMap = new HashMap<String,Bindings>();
|
||||
private final Map<String, Bindings> elementMap = new HashMap<String, Bindings>();
|
||||
|
||||
public NashornActivityBindings(ScenarioController scenarioController) {
|
||||
this.scenario = scenarioController;
|
||||
|
@ -14,12 +14,12 @@
|
||||
*/
|
||||
package io.nosqlbench.engine.core.script;
|
||||
|
||||
import io.nosqlbench.engine.core.ScenarioController;
|
||||
import io.nosqlbench.engine.core.lifecycle.ScenarioController;
|
||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||
|
||||
public class ScenarioContext extends ScriptEnvBuffer {
|
||||
|
||||
private ScenarioController sc;
|
||||
private final ScenarioController sc;
|
||||
|
||||
public ScenarioContext(ScenarioController sc) {
|
||||
this.sc = sc;
|
||||
|
@ -73,12 +73,7 @@ public class MutableConfigModel implements ConfigModel {
|
||||
"while configuring a " + getOf().getSimpleName());
|
||||
}
|
||||
Object value = config.get(configkey);
|
||||
if (!element.getType().isAssignableFrom(value.getClass())) {
|
||||
throw new RuntimeException("Unable to assign provided configuration\n" +
|
||||
"of type '" + value.getClass().getSimpleName() + " to config\n" +
|
||||
"parameter of type '" + element.getType().getSimpleName() + "'\n" +
|
||||
"while configuring a " + getOf().getSimpleName());
|
||||
}
|
||||
Object testValue = convertValueTo(ofType.getSimpleName(), configkey, value, element.getType());
|
||||
}
|
||||
for (ConfigElement element : elements.values()) {
|
||||
if (element.isRequired() && element.getDefaultValue() == null) {
|
||||
@ -91,6 +86,42 @@ public class MutableConfigModel implements ConfigModel {
|
||||
}
|
||||
}
|
||||
|
||||
private Object convertValueTo(String configName, String paramName, Object value, Class<?> type) {
|
||||
try {
|
||||
if (type.isAssignableFrom(value.getClass())) {
|
||||
return type.cast(value);
|
||||
} else if (Number.class.isAssignableFrom(type)
|
||||
&& Number.class.isAssignableFrom(value.getClass())) {
|
||||
Number number = (Number) value;
|
||||
if (type.equals(Float.class)) {
|
||||
return number.floatValue();
|
||||
} else if (type.equals(Integer.class)) {
|
||||
return number.intValue();
|
||||
} else if (type.equals(Double.class)) {
|
||||
return number.doubleValue();
|
||||
} else if (type.equals(Long.class)) {
|
||||
return number.longValue();
|
||||
} else if (type.equals(Byte.class)) {
|
||||
return number.byteValue();
|
||||
} else if (type.equals(Short.class)) {
|
||||
return number.shortValue();
|
||||
} else {
|
||||
throw new RuntimeException("Number type " + type.getSimpleName() + " could " +
|
||||
" not be converted from " + value.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
throw new RuntimeException(
|
||||
"While configuring " + paramName + " for " + configName + ", " +
|
||||
"Unable to convert " + value.getClass() + " to " +
|
||||
type.getCanonicalName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigReader apply(Map<String, ?> config) {
|
||||
assertValidConfig(config);
|
||||
@ -104,12 +135,8 @@ public class MutableConfigModel implements ConfigModel {
|
||||
cval = v.getDefaultValue();
|
||||
}
|
||||
if (cval != null) {
|
||||
if (type.isAssignableFrom(cval.getClass())) {
|
||||
validConfig.put(name, cval);
|
||||
} else {
|
||||
throw new RuntimeException("Unable to assign a " + cval.getClass().getSimpleName() +
|
||||
" to a " + type.getSimpleName());
|
||||
}
|
||||
cval = convertValueTo(ofType.getSimpleName(), k, cval, type);
|
||||
validConfig.put(name, cval);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -18,11 +18,11 @@ public class Synonyms {
|
||||
* Each entry in this list is a list of synonyms in configuration.
|
||||
*/
|
||||
public final static Map<String, Set<String>> PARAM_SYNONYMS = new HashMap<>() {{
|
||||
put("hosts",Set.of("host"));
|
||||
put("workload",Set.of("yaml"));
|
||||
put("driver",Set.of("type"));
|
||||
put("cyclerate", Set.of("targetrate", "rate"));
|
||||
put("parameterized", Set.of("parametrized")); // mispelling safety net
|
||||
put("hosts", Set.of("host" ));
|
||||
put("workload", Set.of("yaml" ));
|
||||
put("driver", Set.of("type" ));
|
||||
put("rate", Set.of("targetrate", "cyclerate" ));
|
||||
put("parameterized", Set.of("parametrized" )); // mispelling safety net
|
||||
}};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user