polyglot mode now does full type introspection

This commit is contained in:
Jonathan Shook 2020-05-15 11:26:24 -05:00
parent ae8506ca3b
commit 9d0403a59f

View File

@ -4,6 +4,7 @@ import io.nosqlbench.engine.api.activityimpl.ActivityDef;
import org.graalvm.polyglot.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.helpers.AttributesImpl;
import java.security.InvalidParameterException;
import java.util.Map;
@ -23,11 +24,45 @@ public class PolyglotScenarioController {
// int timeout = vtimeout.asInt();
// run(timeout, vspec);
// }
public synchronized void run(Value v) {
run(Integer.MAX_VALUE, v);
//
// public synchronized void run(Map<String,String> map) {
// controller.run(map);
// }
//
// public synchronized void run(int timeout, Map<String,String> map) {
// controller.run(timeout, map);
// }
//
public synchronized void run(Object o) {
if (o instanceof Value) {
runValue((Value) o);
} else if (o instanceof Map) {
controller.run((Map<String, String>) o);
} else if (o instanceof String) {
controller.run(o.toString());
} else {
throw new RuntimeException("Unrecognized type: " + o.getClass().getCanonicalName());
}
}
public synchronized void run(int timeout, Value spec) {
public synchronized void run(int timeout, Object o) {
if (o instanceof Value) {
runValue(timeout, (Value) o);
} else if (o instanceof Map) {
controller.run(timeout, (Map<String, String>) o);
} else if (o instanceof String) {
controller.run(timeout, o.toString());
} else {
throw new RuntimeException("Uncrecognized type: " + o.getClass().getCanonicalName());
}
}
private synchronized void runValue(Value v) {
runValue(Integer.MAX_VALUE, v);
}
private synchronized void runValue(int timeout, Value spec) {
logger.debug("run(Value) called with:" + spec);
if (spec.isHostObject()) {
controller.run(timeout, (ActivityDef) spec.asHostObject());
@ -47,7 +82,20 @@ public class PolyglotScenarioController {
}
}
public synchronized void start(Value spec) {
public synchronized void start(Object o) {
if (o instanceof Value) {
startValue((Value) o);
} else if (o instanceof Map) {
controller.start((Map<String, String>) o);
} else if (o instanceof String) {
controller.start(o.toString());
} else {
throw new RuntimeException("unrecognized type " + o.getClass().getCanonicalName());
}
}
private synchronized void startValue(Value spec) {
if (spec.isHostObject()) {
controller.start((ActivityDef) spec.asHostObject());
} else if (spec.isString()) {
@ -59,7 +107,19 @@ public class PolyglotScenarioController {
}
}
public synchronized void stop(Value spec) {
public synchronized void stop(Object o) {
if (o instanceof Value) {
stopValue((Value) o);
} else if (o instanceof Map) {
controller.stop((Map<String, String>) o);
} else if (o instanceof String) {
controller.stop(o.toString());
} else {
throw new RuntimeException("unknown type " + o.getClass().getCanonicalName());
}
}
private synchronized void stopValue(Value spec) {
if (spec.isHostObject()) {
controller.stop((ActivityDef) spec.asHostObject());
} else if (spec.isString()) {
@ -71,15 +131,37 @@ public class PolyglotScenarioController {
}
}
public synchronized void apply(Value spec) {
public synchronized void apply(Object o) {
if (o instanceof Value) {
applyValue((Value) o);
} else if (o instanceof Map) {
controller.apply((Map<String, String>) o);
} else {
throw new RuntimeException("unknown type: " + o.getClass().getCanonicalName());
}
}
private synchronized void applyValue(Value spec) {
Map<String, String> map = spec.as(Map.class);
controller.apply(map);
}
public synchronized void await(Value spec) {
awaitActivity(spec);
public synchronized void awaitActivity(Object o) {
this.await(o);
}
public synchronized void awaitActivity(Value spec) {
public synchronized void await(Object o) {
if (o instanceof String) {
controller.await(o.toString());
} else if (o instanceof Value) {
awaitValue((Value) o);
} else if (o instanceof Map) {
controller.await((Map<String, String>) o);
} else {
throw new RuntimeException("unknown type: " + o.getClass().getCanonicalName());
}
}
private synchronized void awaitValue(Value spec) {
if (spec.isHostObject()) {
controller.await((ActivityDef) spec.asHostObject());
} else if (spec.hasMembers()) {
@ -91,10 +173,22 @@ public class PolyglotScenarioController {
}
}
public synchronized void waitMillis(Value spec) {
public synchronized void waitMillis(Object o) {
if (o instanceof Value) {
waitMillisValue((Value) o);
} else if (o instanceof Integer) {
controller.waitMillis((Integer) o);
} else if (o instanceof Long) {
controller.waitMillis((Long) o);
} else {
throw new RuntimeException("unknown type: " + o.getClass().getCanonicalName());
}
}
private synchronized void waitMillisValue(Value spec) {
if (spec.isString()) {
controller.waitMillis(Long.parseLong(spec.asString()));
} else if (spec.isNumber()){
} else if (spec.isNumber()) {
controller.waitMillis(spec.asLong());
} else {
throw new InvalidParameterException(
@ -102,7 +196,19 @@ public class PolyglotScenarioController {
}
}
public synchronized boolean isRunningActivity(Value spec) {
public synchronized boolean isRunningActivity(Object o) {
if (o instanceof Value) {
return isRunningActivityValue((Value) o);
} else if (o instanceof String) {
return controller.isRunningActivity(o.toString());
} else if (o instanceof Map) {
return controller.isRunningActivity((Map<String, String>) o);
} else {
throw new RuntimeException("unknown type:" + o.getClass().getCanonicalName());
}
}
private synchronized boolean isRunningActivityValue(Value spec) {
if (spec.isHostObject()) {
return controller.isRunningActivity((ActivityDef) spec.asHostObject());
} else if (spec.isString()) {