Search in sources :

Example 86 with ComplexEventChunk

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

the class SnapshotableEventQueueOperator method find.

@Override
public StreamEvent find(StateEvent matchingEvent, Object storeEvents, StreamEventCloner storeEventCloner) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<>();
    storeEventQueue.reset();
    while (storeEventQueue.hasNext()) {
        StreamEvent storeEvent = storeEventQueue.next();
        matchingEvent.setEvent(storeEventPosition, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
        }
        matchingEvent.setEvent(storeEventPosition, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 87 with ComplexEventChunk

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

the class IndexOperator method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
    updatingEventChunk.reset();
    while (updatingEventChunk.hasNext()) {
        StateEvent updatingEvent = updatingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(updatingEvent, (IndexedEventHolder) storeEvents, null);
        if (streamEvents != null) {
            ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
            foundEventChunk.add(streamEvents);
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, updatingEvent, foundEventChunk);
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 88 with ComplexEventChunk

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

the class IndexOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        StreamEvent streamEvents = collectionExecutor.find(overwritingOrAddingEvent, (IndexedEventHolder) storeEvents, null);
        ComplexEventChunk<StreamEvent> foundEventChunk = new ComplexEventChunk<>();
        foundEventChunk.add(streamEvents);
        if (foundEventChunk.getFirst() != null) {
            // for cases when indexed attribute is also updated but that not changed
            // to reduce number of passes needed to update the events
            update((IndexedEventHolder) storeEvents, compiledUpdateSet, overwritingOrAddingEvent, foundEventChunk);
        } else {
            updatingOrAddingEventChunk.remove();
            failedEventChunk.add(overwritingOrAddingEvent);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 89 with ComplexEventChunk

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

the class CacheTable method addAndTrimUptoMaxSize.

public void addAndTrimUptoMaxSize(ComplexEventChunk<StreamEvent> addingEventChunk) {
    ComplexEventChunk<StreamEvent> addingEventChunkForCache = new ComplexEventChunk<>();
    addingEventChunk.reset();
    while (addingEventChunk.hasNext()) {
        StreamEvent event = addingEventChunk.next();
        addingEventChunkForCache.add((StreamEvent) generateEventWithRequiredFields(event, siddhiAppContext, cacheExpiryEnabled));
    }
    readWriteLock.writeLock().lock();
    try {
        super.add(addingEventChunkForCache);
        if (this.size() > maxSize) {
            this.deleteEntriesUsingCachePolicy(this.size() - maxSize);
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 90 with ComplexEventChunk

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

the class BatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
    ComplexEventChunk<StreamEvent> currentEventChunk = new ComplexEventChunk<StreamEvent>();
    synchronized (state) {
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        if (outputExpectsExpiredEvents) {
            if (state.expiredEventQueue.getFirst() != null) {
                while (state.expiredEventQueue.hasNext()) {
                    state.expiredEventQueue.next().setTimestamp(currentTime);
                }
                currentEventChunk.add(state.expiredEventQueue.getFirst());
                if (state.resetEvent != null) {
                    currentEventChunk.add(state.resetEvent);
                    state.resetEvent = null;
                }
            }
            state.expiredEventQueue.clear();
        }
        // check whether the streamEventChunk has next event before add into output stream event chunk
        ComplexEventChunk<StreamEvent> currentEventQueue = new ComplexEventChunk<>();
        int count = 0;
        if (streamEventChunk.hasNext()) {
            do {
                StreamEvent streamEvent = streamEventChunk.next();
                StreamEvent clonedStreamEventToProcess = streamEventCloner.copyStreamEvent(streamEvent);
                if (outputExpectsExpiredEvents) {
                    StreamEvent clonedStreamEventToExpire = streamEventCloner.copyStreamEvent(streamEvent);
                    clonedStreamEventToExpire.setType(StreamEvent.Type.EXPIRED);
                    state.expiredEventQueue.add(clonedStreamEventToExpire);
                }
                currentEventQueue.add(clonedStreamEventToProcess);
                count++;
                if (count == length) {
                    if (currentEventQueue.getFirst() != null) {
                        if (state.resetEvent != null) {
                            currentEventChunk.add(state.resetEvent);
                        }
                        state.resetEvent = streamEventCloner.copyStreamEvent(currentEventQueue.getFirst());
                        state.resetEvent.setType(ComplexEvent.Type.RESET);
                        currentEventChunk.add(currentEventQueue.getFirst());
                    }
                    count = 0;
                    currentEventQueue.clear();
                    if (currentEventChunk.getFirst() != null) {
                        streamEventChunks.add(currentEventChunk);
                        currentEventChunk = new ComplexEventChunk<StreamEvent>();
                    }
                }
            } while (streamEventChunk.hasNext());
            if (currentEventQueue.getFirst() != null) {
                if (state.resetEvent != null) {
                    currentEventChunk.add(state.resetEvent);
                }
                state.resetEvent = streamEventCloner.copyStreamEvent(currentEventQueue.getFirst());
                state.resetEvent.setType(ComplexEvent.Type.RESET);
                currentEventChunk.add(currentEventQueue.getFirst());
            }
            if (currentEventChunk.getFirst() != null) {
                streamEventChunks.add(currentEventChunk);
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> processStreamEventChunk : streamEventChunks) {
        nextProcessor.process(processStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

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