Search in sources :

Example 61 with StateEvent

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

the class StreamPreStateProcessor method addEveryState.

@Override
public void addEveryState(StateEvent stateEvent) {
    lock.lock();
    try {
        StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
        clonedEvent.setType(ComplexEvent.Type.CURRENT);
        for (int i = stateId; i < clonedEvent.getStreamEvents().length; i++) {
            clonedEvent.setEvent(i, null);
        }
        StreamPreState state = stateHolder.getState();
        try {
            state.newAndEveryStateEventList.add(clonedEvent);
        } finally {
            stateHolder.returnState(state);
        }
    } finally {
        lock.unlock();
    }
}
Also used : StateEvent(io.siddhi.core.event.state.StateEvent)

Example 62 with StateEvent

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

the class AbsentLogicalPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>();
    StreamPreState state = stateHolder.getState();
    try {
        if (!((LogicalStreamPreState) state).active) {
            return returnEventChunk;
        }
        complexEventChunk.reset();
        // Sure only one will be sent
        StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
        this.lock.lock();
        try {
            for (Iterator<StateEvent> iterator = state.getPendingStateEventList().iterator(); iterator.hasNext(); ) {
                StateEvent stateEvent = iterator.next();
                if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                    iterator.remove();
                    continue;
                }
                StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
                stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
                process(stateEvent);
                if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePreProcessor != null)) {
                    // Reset to the original state after processing
                    stateEvent.setEvent(stateId, currentStreamEvent);
                }
                if (this.thisLastProcessor.isEventReturned()) {
                    this.thisLastProcessor.clearProcessedEvent();
                    // The event has passed the filter condition. So remove from being an absent candidate.
                    iterator.remove();
                    if (stateType == StateInputStream.Type.SEQUENCE) {
                        partnerStatePreProcessor.getPendingStateEventList().remove(stateEvent);
                    }
                }
                if (!state.isStateChanged()) {
                    switch(stateType) {
                        case PATTERN:
                            stateEvent.setEvent(stateId, currentStreamEvent);
                            break;
                        case SEQUENCE:
                            stateEvent.setEvent(stateId, currentStreamEvent);
                            iterator.remove();
                            break;
                    }
                }
            }
        } finally {
            this.lock.unlock();
        }
        return returnEventChunk;
    } finally {
        stateHolder.returnState(state);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 63 with StateEvent

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

the class AbsentLogicalPreStateProcessor method addEveryState.

@Override
public void addEveryState(StateEvent stateEvent) {
    StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
    clonedEvent.setType(ComplexEvent.Type.CURRENT);
    if (clonedEvent.getStreamEvent(stateId) != null) {
        // Set the timestamp of the last arrived event
        clonedEvent.setTimestamp(clonedEvent.getStreamEvent(stateId).getTimestamp());
    }
    clonedEvent.setEvent(stateId, null);
    clonedEvent.setEvent(partnerStatePreProcessor.stateId, null);
    StreamPreState state = stateHolder.getState();
    try {
        // Start state takes events from newAndEveryStateEventList
        state.getNewAndEveryStateEventList().add(clonedEvent);
        partnerStatePreProcessor.addEventToNewAndEveryStateEventList(clonedEvent);
    } finally {
        stateHolder.returnState(state);
    }
}
Also used : StateEvent(io.siddhi.core.event.state.StateEvent)

Example 64 with StateEvent

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

the class LogicalPreStateProcessor 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.getPendingStateEventList().iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                iterator.remove();
                continue;
            }
            stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
            process(stateEvent);
            if (this.thisLastProcessor.isEventReturned()) {
                this.thisLastProcessor.clearProcessedEvent();
                returnEventChunk.add(stateEvent);
            }
            if (state.isStateChanged()) {
                iterator.remove();
            } else {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.setEvent(stateId, null);
                        break;
                    case SEQUENCE:
                        stateEvent.setEvent(stateId, null);
                        iterator.remove();
                        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 65 with StateEvent

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

the class StreamPostStateProcessor method process.

/**
 * Process the handed StreamEvent
 *
 * @param complexEventChunk event chunk to be processed
 */
@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    if (complexEventChunk.hasNext()) {
        // one one event will be coming
        StateEvent stateEvent = (StateEvent) complexEventChunk.next();
        process(stateEvent, complexEventChunk);
    }
    complexEventChunk.clear();
}
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