@Override
    public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
        ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>();
        complexEventChunk.reset();
        StreamEvent streamEvent = (StreamEvent) complexEventChunk.next(); //Sure only one will be sent
        StreamPreState state = stateHolder.getState();
        lock.lock();
        try {
            for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
                StateEvent stateEvent = iterator.next();
                stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
                process(stateEvent);
                if (this.thisLastProcessor.isEventReturned()) {
                    this.thisLastProcessor.clearProcessedEvent();
                    returnEventChunk.add(stateEvent);
                }
                if (state.stateChanged) {
                    iterator.remove();
                } else {
                    switch (stateType) {
                        case PATTERN:
                            stateEvent.setEvent(stateId, null);
                            break;
                        case SEQUENCE:
                            stateEvent.setEvent(stateId, null);
                            if (removeOnNoStateChange(stateType)) {
                                iterator.remove();
                            }
                            if (thisStatePostProcessor.callbackPreStateProcessor != null) {
                                thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
                            }
                            break;
                    }
                }
            }
        } finally {
            lock.unlock();
            stateHolder.returnState(state);
        }
        return returnEventChunk;
    }
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