Search in sources :

Example 91 with ComplexEventChunk

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

the class ExpressionBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
    if (expressionStringExecutor == null && !init) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
        QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
        init = true;
    }
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
    synchronized (state) {
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            if (expressionStringExecutor != null) {
                String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
                if (!expressionStringNew.equals(expressionString)) {
                    expressionString = expressionStringNew;
                    processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
                }
            }
            if (!streamInputEvents) {
                processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
            } else {
                processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 92 with ComplexEventChunk

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

the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.

private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents, WindowState state) {
    ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<>();
    if (outputExpectsExpiredEvents) {
        if (state.expiredEventChunk.getFirst() != null) {
            // mark the timestamp for the expiredType event
            state.expiredEventChunk.reset();
            while (state.expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = state.expiredEventChunk.next();
                expiredEvent.setTimestamp(currentTime);
            }
            // add expired event to newEventChunk.
            newEventChunk.add(state.expiredEventChunk.getFirst());
        }
    }
    if (state.expiredEventChunk != null) {
        state.expiredEventChunk.clear();
    }
    if (state.currentEventChunk.getFirst() != null) {
        // add reset event in front of current events
        state.resetEvent.setTimestamp(currentTime);
        newEventChunk.add(state.resetEvent);
        state.resetEvent = null;
        // move to expired events
        if (preserveCurrentEvents || state.expiredEventChunk != null) {
            state.currentEventChunk.reset();
            while (state.currentEventChunk.hasNext()) {
                StreamEvent currentEvent = state.currentEventChunk.next();
                StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                state.expiredEventChunk.add(toExpireEvent);
            }
        }
        // add current event chunk to next processor
        newEventChunk.add(state.currentEventChunk.getFirst());
    }
    state.currentEventChunk.clear();
    if (newEventChunk.getFirst() != null) {
        complexEventChunks.add(newEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 93 with ComplexEventChunk

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

the class LengthBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
    synchronized (state) {
        ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            if (length == 0) {
                processLengthZeroBatch(streamEvent, outputStreamEventChunk, currentTime, streamEventCloner);
            } else {
                if (state.resetEvent == null) {
                    state.resetEvent = streamEventCloner.copyStreamEvent(streamEvent);
                    state.resetEvent.setType(ComplexEvent.Type.RESET);
                }
                if (isStreamCurrentEvents) {
                    processStreamCurrentEvents(streamEvent, outputStreamEventChunk, currentTime, state, streamEventCloner);
                } else {
                    processFullBatchEvents(streamEvent, outputStreamEventChunk, currentTime, state, streamEventCloner);
                }
            }
            if (outputStreamEventChunk.getFirst() != null) {
                streamEventChunks.add(outputStreamEventChunk);
                outputStreamEventChunk = new ComplexEventChunk<>();
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 94 with ComplexEventChunk

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

the class AbstractStreamProcessor method process.

@Override
public void process(List<ComplexEventChunk> complexEventChunks) {
    ComplexEventChunk complexEventChunk = new ComplexEventChunk();
    for (ComplexEventChunk streamEventChunk : complexEventChunks) {
        complexEventChunk.addAll(streamEventChunk);
    }
    process(complexEventChunk);
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk)

Example 95 with ComplexEventChunk

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

Aggregations

ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)114 StreamEvent (io.siddhi.core.event.stream.StreamEvent)75 ComplexEvent (io.siddhi.core.event.ComplexEvent)41 StateEvent (io.siddhi.core.event.state.StateEvent)38 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)34 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)14 GroupedComplexEvent (io.siddhi.core.event.GroupedComplexEvent)13 LinkedList (java.util.LinkedList)12 Map (java.util.Map)12 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ArrayList (java.util.ArrayList)10 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)7 HashMap (java.util.HashMap)7 Attribute (io.siddhi.query.api.definition.Attribute)5 Event (io.siddhi.core.event.Event)4 TimePeriod (io.siddhi.query.api.aggregation.TimePeriod)4 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (io.siddhi.core.table.Table)3 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2