private void orderEventChunk(ComplexEventChunk complexEventChunk) {
        ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk();
        List<ComplexEvent> eventList = new ArrayList<>();

        ComplexEvent.Type currentEventType = null;
        complexEventChunk.reset();
        if (complexEventChunk.getFirst() != null) {
            currentEventType = complexEventChunk.getFirst().getType();
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                complexEventChunk.remove();
                if (currentEventType == event.getType()) {
                    eventList.add(event);
                } else {
                    currentEventType = event.getType();
                    eventList.sort(orderByEventComparator);
                    for (ComplexEvent complexEvent : eventList) {
                        orderingComplexEventChunk.add(complexEvent);
                    }
                    eventList.clear();
                    eventList.add(event);
                }
            }
            eventList.sort(orderByEventComparator);
            for (ComplexEvent complexEvent : eventList) {
                orderingComplexEventChunk.add(complexEvent);
            }
            complexEventChunk.clear();
            complexEventChunk.add(orderingComplexEventChunk.getFirst());
        }

    }
Processor implementation representing selector portion of the Siddhi query.
modules/siddhi-core/src/main/java/io/siddhi/core/query/selector/QuerySelector.java