Search in sources :

Example 56 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class QuerySelector method orderEventChunk.

private void orderEventChunk(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk(complexEventChunk.isBatch());
    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());
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 57 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

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 : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 58 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

the class QuerySelector method limitEventChunk.

private void limitEventChunk(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    int limitCount = 0;
    while (complexEventChunk.hasNext()) {
        ComplexEvent event = complexEventChunk.next();
        if (event.getType() == StreamEvent.Type.CURRENT || event.getType() == StreamEvent.Type.EXPIRED) {
            if ((limit > limitCount) && (event.getType() == StreamEvent.Type.CURRENT && currentOn) || (event.getType() == StreamEvent.Type.EXPIRED && expiredOn)) {
                limitCount++;
            } else {
                complexEventChunk.remove();
            }
        }
    }
}
Also used : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 59 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

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.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList)

Example 60 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent in project siddhi by wso2.

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 : GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(org.wso2.siddhi.core.event.GroupedComplexEvent)

Aggregations

ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)59 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)29 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)26 ArrayList (java.util.ArrayList)21 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 Event (org.wso2.siddhi.core.event.Event)16 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)13 Test (org.testng.annotations.Test)12 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)12 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)10 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)5 Map (java.util.Map)4 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)4 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)3 Iterator (java.util.Iterator)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 HashMap (java.util.HashMap)1