我正在尝试为cep创建一个新的扩展函数以获得时差,我正在使用cep 3.1版。
我正在扩展类“FunctionExecutor”并覆盖函数“execute(Object [] data)”但我不知道如何在执行计划中的siddhi查询和创建的函数之间建立链接。
BTW,我无法使用注释,因为我找不到类“org.wso2.siddhi.query.api.extension.annotation.SiddhiExtension”
答案 0 :(得分:1)
尝试这样的事情:
import org.wso2.siddhi.core.config.SiddhiContext;
import org.wso2.siddhi.core.executor.function.FunctionExecutor;
import org.wso2.siddhi.query.api.definition.Attribute;
import org.wso2.siddhi.query.api.extension.annotation.SiddhiExtension;
@SiddhiExtension(namespace = "testNamespace", function = "testFunction")
public class Test extends FunctionExecutor {
Attribute.Type returnType;
@Override
public void init(Attribute.Type[] types, SiddhiContext siddhiContext) { }
@Override
protected Object process(Object object) {
Object[] arrayObject;
int param1 = 0;
int param2 = 0;
if (object instanceof Object[]) { // if you pass params into yours function in executionPlan, you will have arrayObject (remember about order)
arrayObject = (Object[]) object;
param1 = (Integer) arrayObject[0];
param2 = (Integer) arrayObject[1];
}
return (param1 + param2);
}
@Override
public void destroy() { }
@Override
public Attribute.Type getReturnType() {
return returnType.INT; //type of what you want to return (STRING, INT, LONG, FLOAT, DOUBLE, BOOL, TYPE) or null <-- but then it doesn not make sense
}
}
答案 1 :(得分:1)
您可以使用以下链接的指南来了解如何在siddhi查询中使用扩展程序。
https://docs.wso2.com/display/CEP310/Writing+a+Custom+Function
要获取项目的siddhi扩展依赖项,请使用pom.xml中的以下存储库和依赖项
<repositories>
<repository>
<id>wso2-maven2-repository</id>
<name>WSO2 Maven2 Repository</name>
<url>http://dist.wso2.org/maven2</url>
</repository>
</repositories>
<dependency>
<groupId>org.wso2.siddhi</groupId>
<artifactId>siddhi-core</artifactId>
<version>2.0.0-wso2v4</version>
</dependency>