Search in sources :

Example 96 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk 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)

Example 97 with ComplexEventChunk

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

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

Example 98 with ComplexEventChunk

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

the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.

private void tryFlushEvents(ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
    if (event.getTimestamp() >= scheduledTime) {
        ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
        for (ComplexEvent originalComplexEvent : eventList) {
            ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent);
            for (Integer position : aggregateAttributePositionList) {
                eventCopy.getOutputData()[position] = aggregateAttributeValueMap.get(position);
            }
            outputEventChunk.add(eventCopy);
        }
        outputEventChunks.add(outputEventChunk);
        scheduledTime += value;
        scheduler.notifyAt(scheduledTime);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk)

Example 99 with ComplexEventChunk

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

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

Example 100 with ComplexEventChunk

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

the class ListEventHolder method add.

@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
    addingEventChunk.reset();
    while (addingEventChunk.hasNext()) {
        ComplexEvent complexEvent = addingEventChunk.next();
        StreamEvent streamEvent = tableStreamEventPool.borrowEvent();
        eventConverter.convertComplexEvent(complexEvent, streamEvent);
        this.add(streamEvent);
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)72 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)69 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)44 ArrayList (java.util.ArrayList)30 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)26 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)19 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)13 Map (java.util.Map)12 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 HashMap (java.util.HashMap)6 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)5 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)4 Collection (java.util.Collection)3 Event (org.wso2.siddhi.core.event.Event)3 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (org.wso2.siddhi.core.table.Table)3 Iterator (java.util.Iterator)2 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2