private void addLateEvent(ComplexEventChunk<StreamEvent> streamEventChunk,
                              long eventTimestamp, StreamEvent streamEvent, WindowState state) {

        SessionComplexEventChunk<StreamEvent> currentSession = state.sessionContainer.getCurrentSession();
        SessionComplexEventChunk<StreamEvent> previousSession = state.sessionContainer.getPreviousSession();

        if (allowedLatency > 0) {

            if (eventTimestamp >= (currentSession.getStartTimestamp() - sessionGap)) {
                if (currentSession.hasNext()) {
                    currentSession.next();
                }
                currentSession.insertBeforeCurrent(streamEvent);
                currentSession.setStartTimestamp(eventTimestamp);
                mergeWindows(previousSession, currentSession);
            } else {

                if (previousSession.getFirst() == null &&
                        eventTimestamp < (currentSession.getStartTimestamp() - sessionGap)) {
                    streamEventChunk.remove();
                    log.info("The event, " + streamEvent + " is late and it's session window has been timeout");

                } else {
                    if (eventTimestamp >= (previousSession.getStartTimestamp() - sessionGap)) {
                        previousSession.add(streamEvent);
                        //when this condition true, previous session will not merge with the current session
                        if (eventTimestamp <= (previousSession.getEndTimestamp() - sessionGap) &&
                                eventTimestamp < previousSession.getStartTimestamp()) {

                            previousSession.setStartTimestamp(eventTimestamp);

                        } else {
                            previousSession.setEndTimestamp(eventTimestamp + sessionGap);
                            previousSession.setAliveTimestamp(eventTimestamp + sessionGap + allowedLatency);
                            mergeWindows(previousSession, currentSession);
                        }

                    } else {
                        //late event does not belong to the previous session
                        streamEventChunk.remove();
                        log.info("The event, " + streamEvent + " is late and it's session window has been timeout");
                    }
                }
            }
        } else {
            //no allowedLatency time
            //check the late event belongs to the same session
            if (eventTimestamp >= (currentSession.getStartTimestamp() - sessionGap)) {
                if (currentSession.hasNext()) {
                    currentSession.next();
                }
                currentSession.insertBeforeCurrent(streamEvent);
                currentSession.setStartTimestamp(eventTimestamp);
            } else {
                streamEventChunk.remove();
                log.info("The event, " + streamEvent + " is late and it's session window has been timeout");
            }
        }

    }
Handles when the late event arrives to the system.
modules/siddhi-core/src/main/java/io/siddhi/core/query/processor/stream/window/SessionWindowProcessor.java