简体   繁体   English

WSO2 CEP,创建扩展功能

[英]WSO2 CEP, creating extension function

I'm trying to create a new extension function for cep to get the time difference , I'm using the cep version 3.1. 我正在尝试为cep创建新的扩展功能以获取时差,我正在使用cep 3.1版。

I'm extending the class "FunctionExecutor" and overriding the function "execute(Object[] data)" but i don't know how I will link between the siddhi query in execution plan and function created. 我正在扩展类“ FunctionExecutor”并重写函数“ execute(Object [] data)”,但是我不知道如何在执行计划中的siddhi查询与所创建的函数之间建立链接。

BTW, I can't use the annotation because i ccan't find the class "org.wso2.siddhi.query.api.extension.annotation.SiddhiExtension" 顺便说一句,我无法使用注释,因为我找不到类“ org.wso2.siddhi.query.api.extension.annotation.SiddhiExtension”

Try something like this: 尝试这样的事情:

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
    }
}

You can use the following link's guidelines on how to use the extension in your siddhi query. 您可以使用以下链接的指南,了解如何在siddhi查询中使用扩展名。

https://docs.wso2.com/display/CEP310/Writing+a+Custom+Function https://docs.wso2.com/display/CEP310/Writing+a+Custom+Function

To get the siddhi extension dependency to the project use the following repository and dependency in pom.xml 要获取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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM