Search code examples
javacomplex-event-processingesper

Instance method not called when declaring a Class-type instance variable and call an instance method in Esper


I'm writing an application that has an instance of a class that contains the esper engine. There are a number of instance variables that I would like to read and set using instance method calls from the EPL in the engine. I don't get any compilation errors and the code runs. But the instance method is not called.

epl statements:

module myModule;
create variable com.tp.main.MyClass myClass;
select myProperty from MyEvent unidirectional, method:myClass.getMyProperty() as myProperty;

A hint could be that if I don't use the method: key word in front of the method call I get an error that myClass.getMyProperty class could not be found. The documentation sometimes uses the method: key word and sometimes not in the examples for calling instance methods from Class-type variables.

I have also tried using the addVariable method in the API with the same results.

code for the method.

public Result getMyProperty() {
    Result result = new Result();
    result.setResult("propertyValue");
    logger.info("This method was called");
    return result;
}

The class Result is a POJO with getter and setter for a string.

public class Result {
    private String result;

    public String getResult() {
        return result;
    }
    public void setResult(String str) {
        result = str;
    }
}

What am I missing?


Solution

  • You could look at a regression test class. The specific one you may want to look at is ExecFromClauseMethodVariable. Maybe your code does not assign a value to the variable?

    Github: https://github.com/espertechinc/esper/blob/3e396d77308532b202ee452100eaaf9e7a044906/esper-regression/src/test/java/com/espertech/esper/regression/epl/fromclausemethod/ExecFromClauseMethodVariable.java