views:

13

answers:

1

I am a novice in using the Esper event stream engine in Java. The scenario is that events are coming in as POJOs. They have a field that I want to filter on. The filtered values will change over time. I would prefer to not remove and insert a new statement every time a change occurs.

Example:

Event is named 'MyEvent', and has the field 'source'. Value could be one of 'home', 'work', or 'school'. A web service allows users to change the values for 'source' they are interested in. The EPL statement will look like

select * from MyEvent where source in ( 'home', 'school' )

So at any time, 'school' could be removed, and the impact must be reflected as fast as possible. The question is, how best to make this happen? I've ruled out cached database calls because of the latency between the update taking effect.

Ideas are:

1) Have a stream called 'SourcesOfInterest' with a 'sources' field of type List, and change the statement to be:

select * from MyEvent where source in (SourcesOfInterest.win:length(1).sources)

The web service inserts 'SourcesOfInterest' events into this stream, where only the most recent is looked at. Not even sure if the syntax is right.

2) Have the statement reference a runtime variable. Then the statement would be:

select * from MyEvent where source in ( mySourcesVariable )

The web service would invoke

EPRuntime.setVariableValue( "mySourcesVariable", myArrayOfSources )

Are there other options? Performance issues to any of these?

A: 

After some flailing, I used the second idea in the question.

The variable needed to be set in the configuration, prior to startup, using

Set<String> mySetOfValues = new HashSet<String>();

esperConfiguration.addVariable( mySourcesVariable, Set.class, mySetOfValues );

The web service works as described, with a Set instead of an array.

All good now, and the performance is not obscenely bad, so I'm going with it.

cmonkey