Search in sources :

Example 61 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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 62 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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 63 with ComplexEvent

use of org.wso2.siddhi.core.event.ComplexEvent 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 64 with ComplexEvent

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

the class GroupByAggregationAttributeExecutor method execute.

@Override
public Object execute(ComplexEvent event) {
    long currentTime = timestampGenerator.currentTime();
    boolean canClean = false;
    if (lastCleanupTimestamp + 5000 < currentTime || obsoleteAggregatorKeys.size() > 25) {
        lastCleanupTimestamp = currentTime;
        canClean = true;
    }
    if (event.getType() == ComplexEvent.Type.RESET) {
        Object aOutput = null;
        if (canClean) {
            Iterator<AttributeAggregator> iterator = aggregatorMap.values().iterator();
            if (iterator.hasNext()) {
                aOutput = iterator.next().process(event);
            }
            aggregatorMap.clear();
            obsoleteAggregatorKeys.clear();
        } else {
            for (Map.Entry<String, AttributeAggregator> attributeAggregatorEntry : aggregatorMap.entrySet()) {
                aOutput = attributeAggregatorEntry.getValue().process(event);
            }
        }
        return aOutput;
    }
    String key = keyThreadLocal.get();
    AttributeAggregator currentAttributeAggregator = aggregatorMap.get(key);
    if (currentAttributeAggregator == null) {
        currentAttributeAggregator = attributeAggregator.cloneAggregator(key);
        aggregatorMap.put(key, currentAttributeAggregator);
    }
    Object results = currentAttributeAggregator.process(event);
    if (event.getType() == ComplexEvent.Type.EXPIRED && currentAttributeAggregator.canDestroy()) {
        obsoleteAggregatorKeys.add(key);
    }
    if (canClean) {
        destroyObsoleteAggregators();
    }
    return results;
}
Also used : AttributeAggregator(org.wso2.siddhi.core.query.selector.attribute.aggregator.AttributeAggregator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 65 with ComplexEvent

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

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