Search in sources :

Example 11 with GroupedComplexEvent

use of org.ballerinalang.siddhi.core.event.GroupedComplexEvent in project ballerina by ballerina-lang.

the class FirstGroupByPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                if (event.getTimestamp() >= scheduledTime) {
                    if (allComplexEventChunk.getFirst() != null) {
                        ComplexEventChunk<ComplexEvent> eventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        eventChunk.add(allComplexEventChunk.getFirst());
                        allComplexEventChunk.clear();
                        groupByKeys.clear();
                        outputEventChunks.add(eventChunk);
                    } else {
                        groupByKeys.clear();
                    }
                    scheduledTime = scheduledTime + value;
                    scheduler.notifyAt(scheduledTime);
                }
            } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (!groupByKeys.contains(groupedComplexEvent.getGroupKey())) {
                    complexEventChunk.remove();
                    groupByKeys.add(groupedComplexEvent.getGroupKey());
                    allComplexEventChunk.add(groupedComplexEvent.getComplexEvent());
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Aggregations

ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)11 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)11 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)10 ArrayList (java.util.ArrayList)8 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)2 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1