private void limitEventChunk(ComplexEventChunk complexEventChunk) {
        complexEventChunk.reset();
        int limitCount = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == StreamEvent.Type.CURRENT || event.getType() == StreamEvent.Type.EXPIRED) {
                if ((limit > limitCount) &&
                        (event.getType() == StreamEvent.Type.CURRENT && currentOn) ||
                        (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                    limitCount++;
                } else {
                    complexEventChunk.remove();
                }
            }
        }
    }
Processor implementation representing selector portion of the Siddhi query.
modules/siddhi-core/src/main/java/io/siddhi/core/query/selector/QuerySelector.java