0

I try to send an event with the following code but keep receiving it twice in in the registered listener. Is there maybe something wrong with the query in the listener registration or is there some other mistake I made? Thanks for any advise!

System.out.println("test1");
TestEvent event = new TestEvent(foo);
System.out.println("test 1.5");
epService.getEPRuntime().sendEvent(event);
System.out.println("test2");

Listener function

public void update(EventBean[] newEvents, EventBean[] oldEvents) {
        LOG.info("TestEvent detected!");
        System.out.println("hallo");
    }

Log file looks like this:

test1
test 1.5
INFO - TestEvent detected!
hello
INFO - TestEvent detected!
hello
test2

Listener registration:

// Register listener
EPStatement stmt = this.getEPServiceProvider().getEPAdministrator().createEPL("select * from TestEvent");
stmt.addListener(new TestEventListener());
Chaoz77
  • 37
  • 7

2 Answers2

0

I'll take a stab in the dark here....

I've only seen this happen when doing something like unit testing where I reuse the engine and forget to remove a listener.

The second unit test would then get called twice if it used the same handler for the listener.

Other than that, the comment is probably right, you'll need to post your code as this is very unlikely to be a bug in esper.

chollida
  • 7,834
  • 11
  • 55
  • 85
0

Another possible reason is:

EPStatement statement = admin.createEPL(create window 
TestEventWindow.win:time(1 day) (...));
statement.addListener(TestEventListener());

EPStatement stmt = admin.createEPL("select * from TestEventWindow");
stmt.addListener(new TestEventListener());

When new event arrived or properties changed in TestEventWindow, update() will be invoked twice.

DEarTh
  • 975
  • 1
  • 7
  • 18
winbill
  • 31
  • 1