I am new to Esper, and a created a small program that feeds Esper events in the form of Map.
I have added a listener, and everything works as expected, however, when doing complex queries like count(*) over a time windows, I struggle to get the result back as a java.util.Map. How can I, regardless of query result, get the results as standard Map for further processing?
private class EsperUpdateListener implements UpdateListener {
public void update(EventBean[] newEvents, EventBean[] oldEvents) {
System.out.println("Found new event!");
if(newEvents != null) {
System.out.println("newEvents (" + newEvents.length + "):");
for (EventBean e : newEvents) {
System.out.println(" " + e.toString() + "(" + e.getEventType().getName() + ")");
System.out.println(" " + e.getUnderlying().toString());
for (Map.Entry<String,Object> entry : e.getUnderlying().getEntrySet()) {
String key = entry.getKey();
String val = (String)entry.getValue();
System.out.println(" " + key + ": " + val);
}
}
}
if(oldEvents != null) {
System.out.println("oldEvents:");
for (EventBean e : oldEvents) {
System.out.println(" " + e.toString() + "(" + e.getEventType().getName() + ")");
}
}
}
}
I tried the code above, but it complains that getUnderlying returns an Object, not a map. I tried casting, which kinda sorta works, but not without warnings:
warning: [unchecked] unchecked cast
Map<String,Object> emap = (Map<String,Object>)e.getUnderlying();
When you register an UpdateListener, it receives EventBean instances. The "eventBean.getUnderlying()" returns the representation object and in this case a Map.