Search in sources :

Example 1 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class ExpressionBatchWindowProcessor method processStreamEventAsStream.

private void processStreamEventAsStream(WindowState state, long currentTime, StreamEvent streamEvent, StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> streamEventChunks, boolean output) {
    StateEvent stateEventCurrent = new StateEvent(3, 0);
    stateEventCurrent.setEvent(0, streamEvent);
    if (state.expiredEventQueue.getFirst() != null) {
        stateEventCurrent.setEvent(1, state.expiredEventQueue.getFirst());
    } else {
        stateEventCurrent.setEvent(1, streamEvent);
    }
    stateEventCurrent.setEvent(2, streamEvent);
    ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
    if (output && state.currentEventQueue.getFirst() != null) {
        outputStreamEventChunk.add(state.currentEventQueue.getFirst());
        state.currentEventQueue.clear();
    }
    if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
        stateEventCurrent.setType(ComplexEvent.Type.RESET);
        expressionExecutor.execute(stateEventCurrent);
        stateEventCurrent.setType(ComplexEvent.Type.CURRENT);
        expressionExecutor.execute(stateEventCurrent);
        state.expiredEventQueue.reset();
        if (state.expiredEventQueue.getFirst() != null) {
            while (state.expiredEventQueue.hasNext()) {
                StreamEvent expiredEvent = state.expiredEventQueue.next();
                expiredEvent.setTimestamp(currentTime);
            }
            StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
            expiredEvent.setType(ComplexEvent.Type.EXPIRED);
            if (includeTriggeringEventExecutor != null && (Boolean) includeTriggeringEventExecutor.execute(streamEvent) || includeTriggeringEvent) {
                outputStreamEventChunk.add(streamEvent);
                if (output) {
                    outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
                    expiredEvent.setTimestamp(currentTime);
                    outputStreamEventChunk.add(expiredEvent);
                } else {
                    state.currentEventQueue.add(state.expiredEventQueue.getFirst());
                    state.currentEventQueue.add(expiredEvent);
                }
                state.expiredEventQueue.clear();
            } else {
                if (output) {
                    outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
                } else {
                    state.currentEventQueue.add(state.expiredEventQueue.getFirst());
                }
                outputStreamEventChunk.add(streamEvent);
                state.expiredEventQueue.clear();
                state.expiredEventQueue.add(expiredEvent);
            }
        } else if (output) {
            StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
            expiredEvent.setType(ComplexEvent.Type.EXPIRED);
            expiredEvent.setTimestamp(currentTime);
            outputStreamEventChunk.add(expiredEvent);
            streamEvent.setTimestamp(currentTime);
            outputStreamEventChunk.add(streamEvent);
        } else {
            state.currentEventQueue.add(streamEvent);
        }
        if (output) {
            streamEventChunks.add(outputStreamEventChunk);
        }
    } else {
        StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
        expiredEvent.setType(ComplexEvent.Type.EXPIRED);
        state.expiredEventQueue.add(expiredEvent);
        if (output) {
            outputStreamEventChunk.add(streamEvent);
            streamEventChunks.add(outputStreamEventChunk);
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 2 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class ExpressionBatchWindowProcessor method processStreamEvent.

private void processStreamEvent(WindowState state, long currentTime, StreamEvent streamEvent, StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
    StateEvent stateEventCurrent = new StateEvent(3, 0);
    stateEventCurrent.setEvent(0, streamEvent);
    if (state.currentEventQueue.getFirst() != null) {
        stateEventCurrent.setEvent(1, state.currentEventQueue.getFirst());
    } else {
        stateEventCurrent.setEvent(1, streamEvent);
    }
    stateEventCurrent.setEvent(2, streamEvent);
    if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
        stateEventCurrent.setType(ComplexEvent.Type.RESET);
        expressionExecutor.execute(stateEventCurrent);
        stateEventCurrent.setType(ComplexEvent.Type.CURRENT);
        expressionExecutor.execute(stateEventCurrent);
        ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<>();
        state.expiredEventQueue.reset();
        if (state.expiredEventQueue.getFirst() != null) {
            while (state.expiredEventQueue.hasNext()) {
                StreamEvent expiredEvent = state.expiredEventQueue.next();
                expiredEvent.setTimestamp(currentTime);
            }
            outputStreamEventChunk.add(state.expiredEventQueue.getFirst());
            state.expiredEventQueue.clear();
        }
        if (state.currentEventQueue.getFirst() != null) {
            while (state.currentEventQueue.hasNext()) {
                StreamEvent currentEvent = state.currentEventQueue.next();
                currentEvent.setTimestamp(currentTime);
                StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(currentEvent);
                expiredEvent.setType(ComplexEvent.Type.EXPIRED);
                state.expiredEventQueue.add(expiredEvent);
            }
            outputStreamEventChunk.add(state.currentEventQueue.getFirst());
            state.currentEventQueue.clear();
            if (includeTriggeringEventExecutor != null && (Boolean) includeTriggeringEventExecutor.execute(streamEvent) || includeTriggeringEvent) {
                outputStreamEventChunk.add(streamEvent);
                StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
                expiredEvent.setTimestamp(currentTime);
                expiredEvent.setType(ComplexEvent.Type.EXPIRED);
                state.expiredEventQueue.add(expiredEvent);
            } else {
                state.currentEventQueue.add(streamEvent);
            }
        } else {
            StreamEvent expiredEvent = streamEventCloner.copyStreamEvent(streamEvent);
            expiredEvent.setType(ComplexEvent.Type.EXPIRED);
            expiredEvent.setTimestamp(currentTime);
            outputStreamEventChunk.add(expiredEvent);
            streamEvent.setTimestamp(currentTime);
            outputStreamEventChunk.add(streamEvent);
        }
        streamEventChunks.add(outputStreamEventChunk);
    } else {
        state.currentEventQueue.add(streamEvent);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 3 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class IncrementalDataPurger method createStreamEvent.

/**
 * creating stream event method
 */
private StateEvent createStreamEvent(Object[] values, Long timestamp) {
    StreamEvent streamEvent = streamEventFactory.newInstance();
    streamEvent.setTimestamp(timestamp);
    streamEvent.setOutputData(values);
    StateEvent stateEvent = new StateEvent(2, 1);
    stateEvent.addEvent(0, streamEvent);
    return stateEvent;
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 4 with StateEvent

use of io.siddhi.core.event.state.StateEvent 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 5 with StateEvent

use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.

the class TestStoreForCacheMiss method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(int outputDataSize, StateEventFactory stateEventFactory) {
    StreamEvent streamEvent = new StreamEvent(outputDataSize, 0, outputDataSize);
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    stateEvent.addEvent(0, streamEvent);
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Aggregations

StateEvent (io.siddhi.core.event.state.StateEvent)70 StreamEvent (io.siddhi.core.event.stream.StreamEvent)48 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)36 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)26 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)19 ComplexEvent (io.siddhi.core.event.ComplexEvent)13 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)6 ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)5 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)5 HashMap (java.util.HashMap)5 Attribute (io.siddhi.query.api.definition.Attribute)4 Event (io.siddhi.core.event.Event)3 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)3 DatabaseRuntimeException (io.siddhi.core.exception.DatabaseRuntimeException)3 OnDemandQueryRuntimeException (io.siddhi.core.exception.OnDemandQueryRuntimeException)3 OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent (io.siddhi.core.util.OnDemandQueryRuntimeUtil.executeSelectorAndReturnStreamEvent)3 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2