Search in sources :

Example 56 with StateEvent

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

the class OverwriteTableIndexOperatorForCache method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        ((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
    }
    return null;
}
Also used : IndexedEventHolder(io.siddhi.core.table.holder.IndexedEventHolder) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 57 with StateEvent

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

the class ExpressionWindowProcessor method processStreamEvent.

private void processStreamEvent(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime, StreamEvent streamEvent) {
    state.expiredEventQueue.add(streamEvent);
    StateEvent stateEventCurrent = new StateEvent(3, 0);
    stateEventCurrent.setEvent(0, streamEvent);
    stateEventCurrent.setEvent(1, state.expiredEventQueue.getFirst());
    stateEventCurrent.setEvent(2, streamEvent);
    if (!(Boolean) expressionExecutor.execute(stateEventCurrent)) {
        state.expiredEventQueue.reset();
        while (state.expiredEventQueue.hasNext()) {
            StreamEvent expiredEvent = state.expiredEventQueue.next();
            state.expiredEventQueue.remove();
            streamEventChunk.insertBeforeCurrent(expiredEvent);
            StateEvent stateEvent = new StateEvent(3, 0);
            stateEvent.setEvent(0, expiredEvent);
            StreamEvent firstEvent = state.expiredEventQueue.getFirst();
            if (firstEvent == null) {
                firstEvent = expiredEvent;
            }
            stateEvent.setEvent(1, firstEvent);
            stateEvent.setEvent(2, streamEvent);
            stateEvent.setType(ComplexEvent.Type.EXPIRED);
            expiredEvent.setTimestamp(currentTime);
            if ((Boolean) expressionExecutor.execute(stateEvent)) {
                break;
            }
        }
    }
}
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 58 with StateEvent

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

the class StreamPreStateProcessor method expireEvents.

@Override
public void expireEvents(long timestamp) {
    StreamPreState state = stateHolder.getState();
    lock.lock();
    try {
        StateEvent expiredStateEvent = null;
        for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (isExpired(stateEvent, timestamp)) {
                iterator.remove();
                if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
                    stateEvent.setType(ComplexEvent.Type.EXPIRED);
                    expiredStateEvent = stateEvent;
                }
            } else {
                break;
            }
        }
        for (Iterator<StateEvent> iterator = state.newAndEveryStateEventList.iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (isExpired(stateEvent, timestamp)) {
                iterator.remove();
                if (stateEvent.getType() != ComplexEvent.Type.EXPIRED) {
                    stateEvent.setType(ComplexEvent.Type.EXPIRED);
                    expiredStateEvent = stateEvent;
                }
            }
        }
        if (expiredStateEvent != null && withinEveryPreStateProcessor != null) {
            withinEveryPreStateProcessor.addEveryState(expiredStateEvent);
            withinEveryPreStateProcessor.updateState();
        }
    } finally {
        lock.unlock();
        stateHolder.returnState(state);
    }
}
Also used : StateEvent(io.siddhi.core.event.state.StateEvent)

Example 59 with StateEvent

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

the class StreamPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>();
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    StreamPreState state = stateHolder.getState();
    lock.lock();
    try {
        for (Iterator<StateEvent> iterator = state.pendingStateEventList.iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
            process(stateEvent);
            if (this.thisLastProcessor.isEventReturned()) {
                this.thisLastProcessor.clearProcessedEvent();
                returnEventChunk.add(stateEvent);
            }
            if (state.stateChanged) {
                iterator.remove();
            } else {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.setEvent(stateId, null);
                        break;
                    case SEQUENCE:
                        stateEvent.setEvent(stateId, null);
                        if (removeOnNoStateChange(stateType)) {
                            iterator.remove();
                        }
                        if (thisStatePostProcessor.callbackPreStateProcessor != null) {
                            thisStatePostProcessor.callbackPreStateProcessor.startStateReset();
                        }
                        break;
                }
            }
        }
    } finally {
        lock.unlock();
        stateHolder.returnState(state);
    }
    return returnEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 60 with StateEvent

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

the class StreamPreStateProcessor method init.

public void init() {
    StreamPreState state = stateHolder.getState();
    try {
        if (isStartState && (!state.initialized || this.thisStatePostProcessor.nextEveryStatePreProcessor != null || (stateType == StateInputStream.Type.SEQUENCE && this.thisStatePostProcessor.nextStatePreProcessor instanceof AbsentPreStateProcessor))) {
            // For 'every' sequence, the 'thisStatePostProcessor.nextEveryStatePreProcessor != null'
            // check is not enough
            StateEvent stateEvent = stateEventFactory.newInstance();
            addState(stateEvent);
            state.initialized = true;
        }
    } finally {
        stateHolder.returnState(state);
    }
}
Also used : 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