Search in sources :

Example 11 with GroupedComplexEvent

use of io.siddhi.core.event.GroupedComplexEvent in project siddhi by wso2.

the class LastGroupByPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    complexEventChunk.reset();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                if (event.getType() == ComplexEvent.Type.TIMER) {
                    if (event.getTimestamp() >= state.scheduledTime) {
                        if (state.allGroupByKeyEvents.size() != 0) {
                            for (ComplexEvent complexEvent : state.allGroupByKeyEvents.values()) {
                                outputEventChunk.add(complexEvent);
                            }
                            state.allGroupByKeyEvents.clear();
                        }
                        state.scheduledTime = state.scheduledTime + value;
                        scheduler.notifyAt(state.scheduledTime);
                    }
                } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEventChunk.remove();
                    GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                    state.allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent)

Aggregations

ComplexEvent (io.siddhi.core.event.ComplexEvent)11 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)11 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)10 LinkedList (java.util.LinkedList)4 AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1