Search in sources :

Example 11 with EvalError

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);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Interpreter(bsh.Interpreter) EvalError(bsh.EvalError) TargetError(bsh.TargetError) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with EvalError

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;
}
Also used : Interpreter(bsh.Interpreter) EvalError(bsh.EvalError) TargetError(bsh.TargetError)

Aggregations

EvalError (bsh.EvalError)12 Interpreter (bsh.Interpreter)9 TargetError (bsh.TargetError)4 ScriptCompilationException (org.springframework.scripting.ScriptCompilationException)3 Map (java.util.Map)2 BshClassManager (bsh.BshClassManager)1 NameSpace (bsh.NameSpace)1 ParseException (bsh.ParseException)1 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1 IoException (org.jumpmind.exception.IoException)1 IExtensionPoint (org.jumpmind.extension.IExtensionPoint)1 SymmetricException (org.jumpmind.symmetric.SymmetricException)1