Working with Esper: Problems and Solutions
Esper is an open-source Complex Event Processing solution for Java (or use NEsper for .NET). The code seems fairly straight forward, and there are plenty of examples included with the package. However, there is very little documentation available for troubleshooting problems. Over the last few days I have been attempting to set up a fairly simple example: read data from a CSV file and look for specific patterns (signaling an event). After spending hours debugging errors, I decided to put my findings all down in one place.
Exception in thread "main" com.espertech.esper.client.EPException: myInputFile.csv not found
Exception in thread "main" com.espertech.esper.client.EPException: Encountered unexpected character "
CSVInputAdapter createMapFromRow ArrayIndexOutOfBounds
My .csv file had a blank line at the bottom, which I deleted. I can't reproduce the problem now.
com.espertech.esper.client.EPException: Cannot populate bean instance
Exception in thread "main" com.espertech.esper.client.EPException: myInputFile.csv not found
Put the file at the same level as the packages (under src/ or src/main/java in Maven) and then refresh the package explorer in Eclipse
Exception in thread "main" com.espertech.esper.client.EPException: Encountered unexpected character "
I removed quotation marks around my data in the csv file. I can't reproduce the problem now, it is working fine with quotes around the data.
CSVInputAdapter createMapFromRow ArrayIndexOutOfBounds
My .csv file had a blank line at the bottom, which I deleted. I can't reproduce the problem now.
com.espertech.esper.client.EPException: Cannot populate bean instance
...Caused by: java.lang.InstantiationException: MyEventClass
MyEventClass (whatever class is being used as the event) needs a constructor with no arguments.
log4j:WARN No appenders could be found for logger (MyMainClass).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" com.espertech.esper.client.EPException: Cannot resolve the order of properties in the CSV file
Exception in thread "main" com.espertech.esper.client.EPException: java.lang.reflect.InvocationTargetException
....
Caused by: java.lang.reflect.InvocationTargetException
at $java.util.Date$$FastClassByCGLIB$$3e8996e.newInstance(<generated>)
This exception occurs if there is an error converting the CSV data to the specified type. Either the types were specified incorrectly in the POJO or HashMap, or the CSV file isn't right. Reading further down the error stack trace usually lists what CSV data it was trying to read and what type it was trying to cast it to.
ERROR - Unexpected exception invoking listener update method on listener class <Listener> :
java.lang.ClassCastException: java.util.HashMap cannot be cast to MyEventClass
Here is my finished product... to run it just needs an input csv file with "date" "time" and "message" fields.
It sometimes helps to change the Logger level from WARN to DEBUG for more information.
MyEventClass (whatever class is being used as the event) needs a constructor with no arguments.
log4j:WARN No appenders could be found for logger (MyMainClass).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
add the following lines to set up the logger:
private static final Log log = LogFactory.getLog(MyMainClass.class);
public static void main(String[] args)
{
SimpleLayout layout = new SimpleLayout();
ConsoleAppender appender = new ConsoleAppender(new SimpleLayout());
Logger.getRootLogger().addAppender(appender);
Logger.getRootLogger().setLevel((Level) Level.WARN);
new MyMainClass().run();
}
Exception in thread "main" com.espertech.esper.client.EPException: Cannot resolve the order of properties in the CSV file
The first line in the CSV file should have field names which match exactly (case-sensitive) to the fields listed in the code. The field names can't include special characters like underscores. The getter and setter method name should match the field names exactly. E.g. for field private String date, public String getDate() and public void setDate(String date).
Exception in thread "main" com.espertech.esper.client.EPException: java.lang.reflect.InvocationTargetException
....
Caused by: java.lang.reflect.InvocationTargetException
at $java.util.Date$$FastClassByCGLIB$$3e8996e.newInstance(<generated>)
This exception occurs if there is an error converting the CSV data to the specified type. Either the types were specified incorrectly in the POJO or HashMap, or the CSV file isn't right. Reading further down the error stack trace usually lists what CSV data it was trying to read and what type it was trying to cast it to.
ERROR - Unexpected exception invoking listener update method on listener class <Listener> :
java.lang.ClassCastException: java.util.HashMap cannot be cast to MyEventClass
This depends on the EPStatement. If it selects particular fields, you get a MapEventBean with Underlying type HashMap<String, Object>. If it selects *, you get a BeanEventBean with Underlying type MyEventClass
No events being captured:
Tried changing the query to something very simple... "select * from MyEventClass"
I discovered that the problem was that all of the attributes of the events were coming up null, so they didn't match my query. Trying with a very simple query like this helps in debugging where the issue is.
If no events are captured even with select *, make sure the MyEventClass type matches up everywhere (Configuration, EPStatement, and CSVInputAdapter).
Event properties are all null
I've been having the problem that no events match my pattern because the properties aren't being set correctly. Basically my event type isn't populated. This is because I didn't have setters in my POJO... all the examples I read said that you need getters, but none mentioned setters.
Here is my finished product... to run it just needs an input csv file with "date" "time" and "message" fields.
Awesome!!!!!!!!!
ReplyDelete