use of bsh.EvalError in project symmetric-ds by JumpMind.
the class BshDataRouter method routeToNodes.
public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
Set<String> boundVariableNames = new LinkedHashSet<String>();
try {
long ts = System.currentTimeMillis();
Interpreter interpreter = getInterpreter(context);
context.incrementStat(System.currentTimeMillis() - ts, "bsh.init.ms");
HashSet<String> targetNodes = new HashSet<String>();
ts = System.currentTimeMillis();
bind(interpreter, dataMetaData, nodes, targetNodes, boundVariableNames, initialLoad);
context.incrementStat(System.currentTimeMillis() - ts, "bsh.bind.ms");
ts = System.currentTimeMillis();
Object returnValue = interpreter.eval(dataMetaData.getRouter().getRouterExpression());
context.incrementStat(System.currentTimeMillis() - ts, "bsh.eval.ms");
return eval(returnValue, nodes, targetNodes);
} catch (EvalError e) {
if (e instanceof TargetError) {
Throwable t = ((TargetError) e).getTarget();
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else {
throw new RuntimeException("Routing script failed at line " + ((TargetError) e).getErrorLineNumber(), t);
}
} else {
throw new RuntimeException("Failed to evaluate bsh router script. Bound variables were: " + boundVariableNames, e);
}
}
}
use of bsh.EvalError in project symmetric-ds by JumpMind.
the class DefaultNodeIdCreator method evaluateScript.
protected String evaluateScript(Node node, String remoteHost, String remoteAddress) {
String script = parameterService.getString(ParameterConstants.NODE_ID_CREATOR_SCRIPT);
if (StringUtils.isNotBlank(script)) {
try {
Interpreter interpreter = new Interpreter();
interpreter.set("node", node);
interpreter.set("hostname", remoteHost);
interpreter.set("remoteHost", remoteHost);
interpreter.set("remoteAddress", remoteAddress);
interpreter.set("log", log);
Object retValue = interpreter.eval(script);
if (retValue != null) {
return retValue.toString();
}
} catch (TargetError e) {
if (e.getTarget() instanceof RuntimeException) {
throw (RuntimeException) e.getTarget();
} else {
throw new RuntimeException(e.getTarget() != null ? e.getTarget() : e);
}
} catch (EvalError e) {
log.error("Failed to evalute node id generator script. The default node id generation mechanism will be used.", e);
}
}
return null;
}
Aggregations