Java 如何在部署语句时在Esper 8.5中设置语句ID/语句名称

Java 如何在部署语句时在Esper 8.5中设置语句ID/语句名称,java,complex-event-processing,esper,Java,Complex Event Processing,Esper,在ESPERVersion5中,我们使用以下代码注册EPL语句并添加侦听器- final EPStatement statement = admin.createEPL(epl, subsc.getId().toString(), subsc); statement.addListener(createListenerAdapter(listenerCallback)); 根据版本8()中的Esper文档,我们可以编写一个实用程序方法compileDeploy()来注册epl语句,如下所示--

在ESPERVersion5中,我们使用以下代码注册EPL语句并添加侦听器-

final EPStatement statement = admin.createEPL(epl, subsc.getId().toString(), subsc);
statement.addListener(createListenerAdapter(listenerCallback));
根据版本8()中的Esper文档,我们可以编写一个实用程序方法compileDeploy()来注册epl语句,如下所示--

我们如何在这里传递语句Id/语句名称以及部署Id

稍后,在从EPDeploymentService获取语句时,似乎需要传递部署id和语句名称,如下所示-

 public EPDeployment compileDeploy(EPRuntime runtime, final String epl, final String deploymentId,final Subs subsc) {
        try {
            // Obtain a copy of the engine configuration
            Configuration configuration = runtime.getConfigurationDeepCopy();

            // Build compiler arguments
            CompilerArguments args = new CompilerArguments(configuration);

            // Make the existing EPL objects available to the compiler
            args.getPath().add(runtime.getRuntimePath());

            // Compile
            EPCompiled compiled = EPCompilerProvider.getCompiler().compile(epl, args);

            DeploymentOptions options = new DeploymentOptions();
            options.setDeploymentId(deploymentId);

           options.setStatementUserObjectRuntime(new StatementUserObjectRuntimeOption() {
                public Object getUserObject(StatementUserObjectRuntimeContext env) {
                  return subsc;
                }
              });

            // Return the deployment
            return runtime.getDeploymentService().deploy(compiled, options);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
final EPStatement语句=epDeploymentService.getStatement(deploymentId,subsc.getId())

显然,我们在这里得到的语句为Null。实际上,我们需要它来从Esper运行时中删除该语句

有人能告诉我如何在compileDeploy()方法中传递语句Id/语句名吗?或者其他任何我们需要通过的地方?

有三种方法

您可以在EPL中设置语句名称:

@name('mystatement') select * from ....
您可以在编译时设置语句名称

CompilerArguments args = new CompilerArguments();
args.getOptions().setStatementName(new MyStatementNameResolver());
String epl = "select * from ....";
EPCompiled compiled = env.compile(epl, args);

private static class MyStatementNameResolver implements StatementNameOption {
     public String getValue(StatementNameContext env) {
         return "mystatement";
     }
}
可以在部署时设置语句名称

DeploymentOptions options = new DeploymentOptions();
options.setStatementNameRuntime(new StatementNameRuntimeOption() {
    public String getStatementName(StatementNameRuntimeContext env) {
        return "mystatementname";
    }
}));
runtime.getDeploymentService().deploy(compiled, options);

user650839-EPStatement语句=epDeploymentService.getStatement(deploymentId,statementName);在部署语句时,我为每个语句使用了唯一的deploymentId和相同的statementName。这是个问题吗?statementName是否也应该是唯一的?因为在执行上面的代码以获取语句时,有时我们将开始语句设置为null。请建议。