1

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?

Rajat Jain
  • 1,339
  • 2
  • 16
  • 29
Jim Broiles
  • 353
  • 2
  • 12
  • have you debugged your code? how have you verified that it doesn't run? – Stultuske Jul 12 '18 at 06:04
  • @Stultuske I have verified that the method isn't being called because the logger.info("this method was called") line of code doesn't output the message to the console. There are other epl statements in the module that do log to the console when the methods are called. But these are static methods and that part works. It is the instance methods that are not working. – Jim Broiles Jul 12 '18 at 14:00
  • are you sure the logger is configured to print to the console? – Stultuske Jul 12 '18 at 14:09
  • @Stultuske that is a good question and the answer is yes. There are other epl statements (not shown in this question) that call static methods that log to the console when they run. – Jim Broiles Jul 12 '18 at 14:25
  • @Stultuske as another confirmation I put a breakpoint at the method declaration and ran in debug mode. The breakpoint is not hit. – Jim Broiles Jul 12 '18 at 14:38

2 Answers2

2

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

user650839
  • 2,594
  • 1
  • 13
  • 9
  • I did look at the regression test class you recommended and found that I was not configuring the variable correctly in the API. Now it works. Thanks! – Jim Broiles Jul 13 '18 at 04:50
0

Problem solved and I thought it might be useful to share the solution. Credit to user650839 who pointed me in the right direction. Here is what ended up fixing the problem.

I reverted back to declaring the variable in the runtime configuration API. I found that I must register the variable class, initialize it with the instance object (this) and finally import the class. Here is the snippet of code that does this configuration in the runtime configuration API.

Configuration configuration = new Configuration();
configuration.addVariable("myClass", com.tp.main.MyClass.class, this);
configuration.addImport(com.tp.main.MyClass.class);
epService = EPServiceProviderManager.getProvider(trade.getTradeName(), configuration);

It seems there is a limitation when declaring the Class variable in the EPL. You cannot initialize it with the instance object you want to use. In the runtime configuration API I was able to initialize it with "this" instance of the object which contains all of the instance variables I want to access from the EPL.

The EPL statement did not change. However, it does seem that you must use the key word method: in front of the method call or you get an error "cannot find class..."

Jim Broiles
  • 353
  • 2
  • 12