Search in sources :

Example 11 with ComplexEvent

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

the class LastGroupByPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                complexEventChunk.remove();
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
                if (++counter == value) {
                    counter = 0;
                    if (allGroupByKeyEvents.size() != 0) {
                        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                        for (ComplexEvent complexEvent : allGroupByKeyEvents.values()) {
                            outputEventChunk.add(complexEvent);
                        }
                        allGroupByKeyEvents.clear();
                        outputEventChunks.add(outputEventChunk);
                    }
                }
            }
        }
    }
    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)

Example 12 with ComplexEvent

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

the class LastPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                if (++counter == value) {
                    complexEventChunk.remove();
                    ComplexEventChunk<ComplexEvent> lastPerEventChunk = new ComplexEventChunk<ComplexEvent>(complexEventChunk.isBatch());
                    lastPerEventChunk.add(event);
                    counter = 0;
                    outputEventChunks.add(lastPerEventChunk);
                }
            }
        }
    }
    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 13 with ComplexEvent

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method constructOutputChunk.

private void constructOutputChunk(List<ComplexEventChunk<ComplexEvent>> outputEventChunks) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
    for (GroupedComplexEvent originalComplexEvent : eventList) {
        String currentGroupByKey = originalComplexEvent.getGroupKey();
        Map<Integer, Object> currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
        ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent.getComplexEvent());
        for (Integer position : aggregateAttributePositionList) {
            eventCopy.getOutputData()[position] = currentAggregateAttributeValueMap.get(position);
        }
        outputEventChunk.add(eventCopy);
    }
    outputEventChunks.add(outputEventChunk);
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 14 with ComplexEvent

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        complexEventChunk.reset();
        String currentGroupByKey = null;
        Map<Integer, Object> currentAggregateAttributeValueMap = null;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
                    currentGroupByKey = groupedComplexEvent.getGroupKey();
                    currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
                    if (currentAggregateAttributeValueMap == null) {
                        currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
                        groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
                    }
                }
                if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                    eventList.add(groupedComplexEvent);
                    for (Integer position : aggregateAttributePositionList) {
                        currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    for (Iterator<GroupedComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
                        GroupedComplexEvent currentEvent = iterator.next();
                        if (comparator.compare(currentEvent.getComplexEvent(), groupedComplexEvent.getComplexEvent()) == 0) {
                            iterator.remove();
                            for (Integer position : aggregateAttributePositionList) {
                                currentAggregateAttributeValueMap.put(position, groupedComplexEvent.getOutputData()[position]);
                            }
                            break;
                        }
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
                    eventList.clear();
                    groupByAggregateAttributeValueMap.clear();
                }
            }
        }
    }
    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) Iterator(java.util.Iterator) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 15 with ComplexEvent

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

the class AggregationWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                if (event.getType() == ComplexEvent.Type.CURRENT) {
                    eventList.add(event);
                    for (Integer position : aggregateAttributePositionList) {
                        aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                    }
                } else if (event.getType() == ComplexEvent.Type.EXPIRED) {
                    for (Iterator<ComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
                        ComplexEvent complexEvent = iterator.next();
                        if (comparator.compare(event, complexEvent) == 0) {
                            iterator.remove();
                            for (Integer position : aggregateAttributePositionList) {
                                aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                            }
                            break;
                        }
                    }
                } else if (event.getType() == ComplexEvent.Type.RESET) {
                    eventList.clear();
                    aggregateAttributeValueMap.clear();
                }
            }
        }
    }
    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) Iterator(java.util.Iterator)

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