Search in sources :

Example 6 with SnapshotableStreamEventQueue

use of io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue in project siddhi by wso2.

the class SnapshotableEventQueueOperator method delete.

@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, Object storeEvents) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    deletingEventChunk.reset();
    while (deletingEventChunk.hasNext()) {
        StateEvent deletingEvent = deletingEventChunk.next();
        try {
            storeEventQueue.reset();
            while (storeEventQueue.hasNext()) {
                StreamEvent storeEvent = storeEventQueue.next();
                deletingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(deletingEvent)) {
                    storeEventQueue.remove();
                }
            }
        } finally {
            deletingEvent.setEvent(storeEventPosition, null);
        }
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 7 with SnapshotableStreamEventQueue

use of io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue in project siddhi by wso2.

the class SnapshotableEventQueueOperator method contains.

@Override
public boolean contains(StateEvent matchingEvent, Object storeEvents) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    try {
        storeEventQueue.reset();
        while (storeEventQueue.hasNext()) {
            StreamEvent storeEvent = storeEventQueue.next();
            matchingEvent.setEvent(storeEventPosition, storeEvent);
            if ((Boolean) expressionExecutor.execute(matchingEvent)) {
                return true;
            }
        }
        return false;
    } finally {
        matchingEvent.setEvent(storeEventPosition, null);
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 8 with SnapshotableStreamEventQueue

use of io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue in project siddhi by wso2.

the class SnapshotableEventQueueOperator method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    updatingEventChunk.reset();
    while (updatingEventChunk.hasNext()) {
        StateEvent updatingEvent = updatingEventChunk.next();
        try {
            storeEventQueue.reset();
            while (storeEventQueue.hasNext()) {
                StreamEvent storeEvent = storeEventQueue.next();
                updatingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(updatingEvent)) {
                    for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                        Object value = entry.getValue().execute(updatingEvent);
                        storeEvent.setOutputData(value, entry.getKey());
                    }
                    storeEventQueue.overwrite(storeEvent);
                }
            }
        } finally {
            updatingEvent.setEvent(storeEventPosition, null);
        }
    }
}
Also used : ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 9 with SnapshotableStreamEventQueue

use of io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue in project siddhi by wso2.

the class SnapshotableEventQueueOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    SnapshotableStreamEventQueue storeEventQueue = (SnapshotableStreamEventQueue) storeEvents;
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            storeEventQueue.reset();
            while (storeEventQueue.hasNext()) {
                StreamEvent storeEvent = storeEventQueue.next();
                overwritingOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(overwritingOrAddingEvent)) {
                    for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                        storeEvent.setOutputData(entry.getValue().execute(overwritingOrAddingEvent), entry.getKey());
                    }
                    storeEventQueue.overwrite(storeEvent);
                    updated = true;
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(overwritingOrAddingEvent);
            }
        } finally {
            overwritingOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)

Example 10 with SnapshotableStreamEventQueue

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

Aggregations

SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)12 StreamEvent (io.siddhi.core.event.stream.StreamEvent)11 Map (java.util.Map)8 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)5 Operation (io.siddhi.core.event.stream.Operation)5 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)5 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)5 StreamEventClonerHolder (io.siddhi.core.event.stream.holder.StreamEventClonerHolder)5 Snapshot (io.siddhi.core.util.snapshot.state.Snapshot)5 SnapshotStateList (io.siddhi.core.util.snapshot.state.SnapshotStateList)5 Attribute (io.siddhi.query.api.definition.Attribute)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Test (org.testng.annotations.Test)5 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)3 StateEvent (io.siddhi.core.event.state.StateEvent)3 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)3 OperationNotSupportedException (io.siddhi.core.exception.OperationNotSupportedException)1 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)1 IndexedEventHolder (io.siddhi.core.table.holder.IndexedEventHolder)1