Search in sources :

Example 51 with ComplexEvent

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

the class StreamFunctionProcessor method processEventChunk.

@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater, S state) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        Object[] outputData;
        switch(attributeExpressionLength) {
            case 0:
                outputData = process((Object) null);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            case 1:
                outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            default:
                Object[] inputData = new Object[attributeExpressionLength];
                for (int i = 0; i < attributeExpressionLength; i++) {
                    inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
                }
                outputData = process(inputData);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent)

Example 52 with ComplexEvent

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

the class LastGroupByPerEventOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEventChunk.remove();
                    GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                    state.allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
                    if (++state.counter == value) {
                        state.counter = 0;
                        if (state.allGroupByKeyEvents.size() != 0) {
                            for (ComplexEvent complexEvent : state.allGroupByKeyEvents.values()) {
                                outputEventChunk.add(complexEvent);
                            }
                            state.allGroupByKeyEvents.clear();
                        }
                    }
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent)

Example 53 with ComplexEvent

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    List<ComplexEventChunk> outputEventChunks = new LinkedList<>();
    AggregationGroupByRateLimiterState state = (AggregationGroupByRateLimiterState) stateHolder.getState();
    try {
        synchronized (state) {
            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, state);
                } else {
                    complexEventChunk.remove();
                    tryFlushEvents(outputEventChunks, event, state);
                    GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                    if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
                        currentGroupByKey = groupedComplexEvent.getGroupKey();
                        currentAggregateAttributeValueMap = state.groupByAggregateAttributeValueMap.get(currentGroupByKey);
                        if (currentAggregateAttributeValueMap == null) {
                            currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
                            state.groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
                        }
                    }
                    if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                        state.eventList.add(groupedComplexEvent);
                        for (Integer position : aggregateAttributePositionList) {
                            currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                        }
                    } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                        for (Iterator<GroupedComplexEvent> iterator = state.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) {
                        state.eventList.clear();
                        state.groupByAggregateAttributeValueMap.clear();
                    }
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    sendToCallBacks(outputEventChunks);
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Iterator(java.util.Iterator) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) LinkedList(java.util.LinkedList)

Example 54 with ComplexEvent

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method constructOutputChunk.

private void constructOutputChunk(List<ComplexEventChunk> outputEventChunks, AggregationGroupByRateLimiterState state) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    Set<String> outputGroupingKeys = new HashSet<>();
    for (GroupedComplexEvent originalComplexEvent : state.eventList) {
        String currentGroupByKey = originalComplexEvent.getGroupKey();
        if (!outputGroupingKeys.contains(currentGroupByKey)) {
            outputGroupingKeys.add(currentGroupByKey);
            Map<Integer, Object> currentAggregateAttributeValueMap = state.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(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) HashSet(java.util.HashSet)

Example 55 with ComplexEvent

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

the class LastGroupByPerTimeOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<>();
    complexEventChunk.reset();
    RateLimiterState state = stateHolder.getState();
    try {
        synchronized (state) {
            while (complexEventChunk.hasNext()) {
                ComplexEvent event = complexEventChunk.next();
                if (event.getType() == ComplexEvent.Type.TIMER) {
                    if (event.getTimestamp() >= state.scheduledTime) {
                        if (state.allGroupByKeyEvents.size() != 0) {
                            for (ComplexEvent complexEvent : state.allGroupByKeyEvents.values()) {
                                outputEventChunk.add(complexEvent);
                            }
                            state.allGroupByKeyEvents.clear();
                        }
                        state.scheduledTime = state.scheduledTime + value;
                        scheduler.notifyAt(state.scheduledTime);
                    }
                } else if (event.getType() == ComplexEvent.Type.CURRENT || event.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEventChunk.remove();
                    GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                    state.allGroupByKeyEvents.put(groupedComplexEvent.getGroupKey(), groupedComplexEvent.getComplexEvent());
                }
            }
        }
    } finally {
        stateHolder.returnState(state);
    }
    outputEventChunk.reset();
    if (outputEventChunk.hasNext()) {
        sendToCallBacks(outputEventChunk);
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(io.siddhi.core.event.GroupedComplexEvent)

Aggregations

ComplexEvent (io.siddhi.core.event.ComplexEvent)75 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)41 StreamEvent (io.siddhi.core.event.stream.StreamEvent)34 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)19 Event (io.siddhi.core.event.Event)16 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (io.siddhi.core.SiddhiManager)13 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)13 StreamCallback (io.siddhi.core.stream.output.StreamCallback)13 StateEvent (io.siddhi.core.event.state.StateEvent)12 InputHandler (io.siddhi.core.stream.input.InputHandler)12 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)8 AttributeProcessor (io.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 ArrayList (java.util.ArrayList)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)3 Map (java.util.Map)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)2 Iterator (java.util.Iterator)2 Operation (io.siddhi.core.event.stream.Operation)1