Search in sources :

Example 31 with ComplexEvent

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

the class QuerySelector method processInBatchGroupBy.

private ComplexEventChunk processInBatchGroupBy(ComplexEventChunk complexEventChunk) {
    Map<String, ComplexEvent> groupedEvents = new LinkedHashMap<String, ComplexEvent>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            switch(event.getType()) {
                case CURRENT:
                case EXPIRED:
                    eventPopulator.populateStateEvent(event);
                    String groupByKey = groupByKeyGenerator.constructEventKey(event);
                    GroupByAggregationAttributeExecutor.getKeyThreadLocal().set(groupByKey);
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    if (!(havingConditionExecutor != null && !havingConditionExecutor.execute(event))) {
                        if ((event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                            complexEventChunk.remove();
                            groupedEvents.put(groupByKey, event);
                        }
                    }
                    GroupByAggregationAttributeExecutor.getKeyThreadLocal().remove();
                    break;
                case TIMER:
                    break;
                case RESET:
                    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
                        attributeProcessor.process(event);
                    }
                    break;
            }
        }
    }
    if (groupedEvents.size() != 0) {
        complexEventChunk.clear();
        for (Map.Entry<String, ComplexEvent> groupedEventEntry : groupedEvents.entrySet()) {
            complexEventChunk.add(new GroupedComplexEvent(groupedEventEntry.getKey(), groupedEventEntry.getValue()));
        }
        if (isOrderBy) {
            orderEventChunk(complexEventChunk);
        }
        if (limit != SiddhiConstants.UNKNOWN_STATE) {
            limitEventChunk(complexEventChunk);
        }
        complexEventChunk.reset();
        return complexEventChunk;
    }
    return null;
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) AttributeProcessor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with ComplexEvent

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

the class GroupByPerSnapshotOutputRateLimiter method tryFlushEvents.

private void tryFlushEvents(List<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
    if (event.getTimestamp() >= scheduledTime) {
        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
        for (ComplexEvent complexEvent : groupByKeyEvents.values()) {
            outputEventChunk.add(cloneComplexEvent(complexEvent));
        }
        outputEventChunks.add(outputEventChunk);
        scheduledTime += value;
        scheduler.notifyAt(scheduledTime);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk)

Example 33 with ComplexEvent

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

the class PerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else if (event.getType() == ComplexEvent.Type.CURRENT) {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                lastEvent = event;
            } else {
                tryFlushEvents(outputEventChunks, event);
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 34 with ComplexEvent

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

the class WindowedPerSnapshotOutputRateLimiter method tryFlushEvents.

private void tryFlushEvents(List<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
    if (event.getTimestamp() >= scheduledTime) {
        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
        for (ComplexEvent complexEvent : eventList) {
            outputEventChunk.add(cloneComplexEvent(complexEvent));
        }
        outputEventChunks.add(outputEventChunk);
        scheduledTime = scheduledTime + value;
        scheduler.notifyAt(scheduledTime);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk)

Example 35 with ComplexEvent

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

the class AllPerTimeOutputRateLimiter 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) {
                    ComplexEvent first = allComplexEventChunk.getFirst();
                    if (first != null) {
                        allComplexEventChunk.clear();
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        outputEventChunk.add(first);
                        outputEventChunks.add(outputEventChunk);
                    }
                    scheduledTime = scheduledTime + value;
                    scheduler.notifyAt(scheduledTime);
                }
            } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                complexEventChunk.remove();
                allComplexEventChunk.add(event);
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Aggregations

ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)29 ArrayList (java.util.ArrayList)20 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)17 Event (org.ballerinalang.siddhi.core.event.Event)15 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)12 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)12 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)12 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)11 Test (org.testng.annotations.Test)11 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)7 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1