tags:

views:

84

answers:

1

I have a non real time Esper configuration where I feed a stream that I read from a file. I'm trying to create an expression that computes a statistic over the entire stream and outputs one value at the very end. Esper has semantics for forcing a view to output every X seconds, for instance, but is there a semantic for asking the view or the engine to "flush" the output when you know there are no more events to feed.

A: 

Turns out that at least one way to do this is to use the output clause with a variable trigger.

The expression would be:

select count(*) as totalCount from events output last when OutputSummary = true

The OutputSummary variable would be initialized like so:

epConfiguration.addVariable("OutputSummary", Boolean.class, "false");

When you're ready to flush, set the variable to true like so:

epRuntime.setVariableValue("OutputSummary", true);
long currentTime = epService.getEPRuntime().getCurrentTime();
epRuntime.sendEvent(new CurrentTimeEvent(currentTime));

It's necessary to send another time event to force the expression to evaluate.

Sasha