0

In Java Esper I would like to know when exactly has the timer on the time window ended. In other words, for example, in the EPL statement (taken from the esper home page):

select avg(price) from org.myapp.event.OrderEvent.win:time(30 sec)

The statement will be used to calculate average of prices of incoming events for 30 seconds, I would like to know if I can find out when the statement end. It would be nice if I could say run this statement and every 30 seconds output a statement saying 30 sec summary and the output throughout the 30 seconds.

I tried using the isStopped() method but that doesn't seem to help, unless it does and I could be using it wrong?

Mario S
  • 11,715
  • 24
  • 39
  • 47
jonathan1987
  • 251
  • 1
  • 6
  • 17

1 Answers1

2

To find out when a statement changes its state you can attach a StatementStateListener to your Provider

epProvider = EPServiceProviderManager.getProvider("myCEPEngine", c);
epProvider.addStatementStateListener(new EPStatementStateListener() {
  //interface implementation
  @Override
  public void onStatementStateChange(EPServiceProvider serviceProvider, EPStatement statement) {
    //here use the EPStatement statement object to check if the statement is the one of your interest:
    //you can compare the name with the one assigned using @Name annotation to your statement
  }
});

If you however want to simply provide the output every 30 seconds (and not whenever the most current average over the preceding 30 seconds changes) - use the output clause:

select avg(price) from org.myapp.event.OrderEvent.win:time(30 sec) output last every 30 seconds;
bawey
  • 149
  • 1
  • 4