@Override
    protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor,
                           StreamEventCloner streamEventCloner, WindowState state) {
        synchronized (state) {
            while (streamEventChunk.hasNext()) {

                StreamEvent streamEvent = streamEventChunk.next();
                long currentTime = (Long) timeStampVariableExpressionExecutor.execute(streamEvent);

                StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
                clonedEvent.setType(StreamEvent.Type.EXPIRED);

                // reset expiredEventQueue to make sure all of the expired events get removed,
                // otherwise lastReturned.next will always return null and here while check is always false
                state.expiredEventQueue.reset();
                while (state.expiredEventQueue.hasNext()) {
                    StreamEvent expiredEvent = state.expiredEventQueue.next();
                    long expiredEventTime = (Long) timeStampVariableExpressionExecutor.execute(expiredEvent);
                    long timeDiff = expiredEventTime - currentTime + timeToKeep;
                    if (timeDiff <= 0) {
                        state.expiredEventQueue.remove();
                        expiredEvent.setTimestamp(currentTime);
                        streamEventChunk.insertBeforeCurrent(expiredEvent);
                    } else {
                        state.expiredEventQueue.reset();
                        break;
                    }
                }

                if (streamEvent.getType() == StreamEvent.Type.CURRENT) {
                    state.expiredEventQueue.add(clonedEvent);
                }
                state.expiredEventQueue.reset();
            }
        }
        nextProcessor.process(streamEventChunk);
    }
Implementation of {@link WindowProcessor} which represent a Window operating based on external time.
modules/siddhi-core/src/main/java/io/siddhi/core/query/processor/stream/window/ExternalTimeWindowProcessor.java