要了解语句何时更改其状态,您可以将 StatementStateListener 附加到您的 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
}
});
但是,如果您只想每 30 秒提供一次输出(而不是在前 30 秒内的最新平均值发生变化时) - 使用 output 子句:
select avg(price) from org.myapp.event.OrderEvent.win:time(30 sec) output last every 30 seconds;