The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Pwachira (1) [Avatar] Offline
On pg 349 there is a comment #3 stating "adds new amount to total sum". this is repeated in the explanation following the code.
To me , especially after reading esper documentation, it seems the addition has already taken place at this point. My understanding is that esper does the addition when a 2nd event is received since the widow length is 2.
What happens at the event listener is not the addition but simply the assignment of the sum that's already calculated to the private variable sumAmount.

I'm I mistaken?
Also what does newEvents[0] represent? The newest event or the newest query results?

Public class EventLengthWindowTest {
Private int sumAmount;

Public void testEventLengthWindow(){
configuration ...

EPStatement epstatement = epservice.get......
epStatement.addListener.......... // this is where the comment about

// addition is found


tijs.rademakers (494) [Avatar] Offline
Re: Chapter 14 esper pg 349: code description ; calculation of sum of window

Right, Esper has already calculated the sum and on that line of code, only the sumAmount variable is filled with that value. newEvents represent the new events that have occurred. So newEvents[0] is the first event out of the new events and in this example we expect that there's only one event.

Best regards,