@Override
    public void expireEvents(long timestamp) {
        StreamPreState state = stateHolder.getState();
        lock.lock();
        try {
            StateEvent expiredStateEvent = null;
            for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
                StateEvent stateEvent = iterator.next();
                if (isExpired(stateEvent, timestamp)) {
                    iterator.remove();
                    if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
                        stateEvent.setType(ComplexEvent.Type.EXPIRED);
                        expiredStateEvent = stateEvent;
                    }
                } else {
                    break;
                }
            }
            for (Iterator<StateEvent> iterator = state.newAndEveryStateEventList.iterator(); iterator.hasNext(); ) {
                StateEvent stateEvent = iterator.next();
                if (isExpired(stateEvent, timestamp)) {
                    iterator.remove();
                    if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
                        stateEvent.setType(ComplexEvent.Type.EXPIRED);
                        expiredStateEvent = stateEvent;
                    }
                }
            }
            if (expiredStateEvent != null && withinEveryPreStateProcessor != null) {
                withinEveryPreStateProcessor.addEveryState(expiredStateEvent);
                withinEveryPreStateProcessor.updateState();
            }
        } finally {
            lock.unlock();
            stateHolder.returnState(state);
        }
    }
Set as the last element of the processor chain

@param processor Last processor in the chain
modules/siddhi-core/src/main/java/io/siddhi/core/query/input/stream/state/StreamPreStateProcessor.java