当前位置: 首页>>代码示例>>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;未经允许,请勿转载。