當前位置: 首頁>>代碼示例>>Java>>正文


Java JSR223Helper類代碼示例

本文整理匯總了Java中com.espertech.esper.epl.script.jsr223.JSR223Helper的典型用法代碼示例。如果您正苦於以下問題:Java JSR223Helper類的具體用法?Java JSR223Helper怎麽用?Java JSR223Helper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSR223Helper類屬於com.espertech.esper.epl.script.jsr223包,在下文中一共展示了JSR223Helper類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateScript

import com.espertech.esper.epl.script.jsr223.JSR223Helper; //導入依賴的package包/類
private void validateScript(ExpressionScriptProvided script) throws ExprValidationException {
    String dialect = script.getOptionalDialect() == null ? services.getConfigSnapshot().getEngineDefaults().getScripts().getDefaultDialect() : script.getOptionalDialect();
    if (dialect == null) {
        throw new ExprValidationException("Failed to determine script dialect for script '" + script.getName() + "', please configure a default dialect or provide a dialect explicitly");
    }
    if (dialect.trim().toLowerCase(Locale.ENGLISH).equals("mvel")) {
        if (!MVELInvoker.isMVELInClasspath(services.getEngineImportService())) {
            throw new ExprValidationException("MVEL scripting engine not found in classpath, script dialect 'mvel' requires mvel in classpath for script '" + script.getName() + "'");
        }
        MVELHelper.verifyScript(script, services.getEngineImportService());
    } else {
        JSR223Helper.verifyCompileScript(script, dialect);
    }

    if (!script.getParameterNames().isEmpty()) {
        HashSet<String> parameters = new HashSet<String>();
        for (String param : script.getParameterNames()) {
            if (parameters.contains(param)) {
                throw new ExprValidationException("Invalid script parameters for script '" + script.getName() + "', parameter '" + param + "' is defined more then once");
            }
            parameters.add(param);
        }
    }
}
 
開發者ID:espertechinc,項目名稱:esper,代碼行數:25,代碼來源:StatementLifecycleSvcImpl.java

示例2: validateScript

import com.espertech.esper.epl.script.jsr223.JSR223Helper; //導入依賴的package包/類
private void validateScript(ExpressionScriptProvided script) throws ExprValidationException {
    String dialect = script.getOptionalDialect() == null ? services.getConfigSnapshot().getEngineDefaults().getScripts().getDefaultDialect() : script.getOptionalDialect();
    if (dialect == null) {
        throw new ExprValidationException("Failed to determine script dialect for script '" + script.getName() + "', please configure a default dialect or provide a dialect explicitly");
    }
    if (dialect.trim().toLowerCase().equals("mvel")) {
        if (!MVELInvoker.isMVELInClasspath()) {
            throw new ExprValidationException("MVEL scripting engine not found in classpath, script dialect 'mvel' requires mvel in classpath for script '" + script.getName() + "'");
        }
        MVELHelper.verifyScript(script);
    }
    else {
        JSR223Helper.verifyCompileScript(script, dialect);
    }

    if (!script.getParameterNames().isEmpty()) {
        HashSet<String> parameters = new HashSet<String>();
        for (String param : script.getParameterNames()) {
            if (parameters.contains(param)) {
                throw new ExprValidationException("Invalid script parameters for script '" + script.getName() + "', parameter '" + param + "' is defined more then once");
            }
            parameters.add(param);
        }
    }
}
 
開發者ID:mobile-event-processing,項目名稱:Asper,代碼行數:26,代碼來源:StatementLifecycleSvcImpl.java

示例3: run

import com.espertech.esper.epl.script.jsr223.JSR223Helper; //導入依賴的package包/類
/**
 * MVEL does not support JSR 223.
 * Making MVEL an Esper compile-time dependency is not desired.
 * Script and MVEL performance comparison is not close and MVEL is faster.
 */
public void run(EPServiceProvider epService) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    String expressionFib = "fib(num); function fib(n) { if(n <= 1) return n; return fib(n-1) + fib(n-2); };";
    String expressionTwo = "var words = new java.util.ArrayList();\n" +
            "words.add('wordOne');\n" +
            "words.add('wordTwo');\n" +
            "words;\n";
    Compilable compilingEngine = (Compilable) engine;
    CompiledScript script = null;
    try {
        script = compilingEngine.compile(expressionTwo);
    } catch (ScriptException ex) {
        throw new RuntimeException("Script compiler exception: " + JSR223Helper.getScriptCompileMsg(ex), ex);
    }

    Bindings bindings = engine.createBindings();
    bindings.put("epl", new MyEPLContext());

    Object result = script.eval(bindings);
    System.out.println(result + " typed " + (result != null ? result.getClass() : "null"));

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1; i++) {
        script.eval(bindings);
    }
    long end = System.currentTimeMillis();
    long delta = end - start;
    System.out.println("delta=" + delta);
}
 
開發者ID:espertechinc,項目名稱:esper,代碼行數:36,代碼來源:ExecScriptSandboxJSR223.java

示例4: testJSR223Sandboxed

import com.espertech.esper.epl.script.jsr223.JSR223Helper; //導入依賴的package包/類
/**
 * MVEL does not support JSR 223.
 * Making MVEL an Esper compile-time dependency is not desired.
 * Script and MVEL performance comparison is not close and MVEL is faster.
 */
public void testJSR223Sandboxed() throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    String expressionFib = "fib(num); function fib(n) { if(n <= 1) return n; return fib(n-1) + fib(n-2); };";
    String expressionTwo = "importPackage(java.util);\n" +
            "var words = new ArrayList();\n" +
            "words.add('wordOne');\n" +
            "words.add('wordTwo');\n" +
            "words;\n";
    Compilable compilingEngine = (Compilable)engine;
    CompiledScript script = null;
    try {
        script = compilingEngine.compile(expressionTwo);
    }
    catch (ScriptException ex) {
        throw new RuntimeException("Script compiler exception: " + JSR223Helper.getScriptCompileMsg(ex), ex);
    }

    Bindings bindings = engine.createBindings();
    bindings.put("epl", new MyEPLContext());

    Object result = script.eval(bindings);
    System.out.println(result + " typed " + (result != null ? result.getClass() : "null"));

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1; i++) {
        script.eval(bindings);
    }
    long end = System.currentTimeMillis();
    long delta = end - start;
    System.out.println("delta=" + delta);
}
 
開發者ID:mobile-event-processing,項目名稱:Asper,代碼行數:38,代碼來源:TestScriptSandboxJSR223.java


注:本文中的com.espertech.esper.epl.script.jsr223.JSR223Helper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。