Search in sources :

Example 71 with StreamEvent

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

the class CountPreStateProcessor 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();
    CountStreamPreState state = (CountStreamPreState) stateHolder.getState();
    lock.lock();
    try {
        for (Iterator<StateEvent> iterator = state.getPendingStateEventList().iterator(); iterator.hasNext(); ) {
            StateEvent stateEvent = iterator.next();
            if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 1)) {
                continue;
            }
            if (removeIfNextStateProcessed(stateEvent, iterator, stateId + 2)) {
                continue;
            }
            stateEvent.addEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
            state.successCondition = false;
            process(stateEvent);
            if (this.thisLastProcessor.isEventReturned()) {
                this.thisLastProcessor.clearProcessedEvent();
                returnEventChunk.add(stateEvent);
            }
            if (state.isStateChanged()) {
                iterator.remove();
            }
            if (!state.successCondition) {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.removeLastEvent(stateId);
                        break;
                    case SEQUENCE:
                        stateEvent.removeLastEvent(stateId);
                        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 72 with StreamEvent

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

the class StreamPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    thisStatePreProcessor.stateChanged();
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    if (nextProcessor != null) {
        complexEventChunk.reset();
        this.isEventReturned = true;
    }
    if (nextStatePreProcessor != null) {
        nextStatePreProcessor.addState(stateEvent);
    }
    if (nextEveryStatePreProcessor != null) {
        nextEveryStatePreProcessor.addEveryState(stateEvent);
    }
    if (callbackPreStateProcessor != null) {
        callbackPreStateProcessor.startStateReset();
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 73 with StreamEvent

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

the class AbsentLogicalPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    // Mark the state changed
    thisStatePreProcessor.stateChanged();
    // Update the timestamp
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    // This is the notification to AbsentStreamPreStateProcessor that this event has been processed
    this.isEventReturned = true;
    ((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Example 74 with StreamEvent

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

the class DeleteOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    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) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 75 with StreamEvent

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

the class InsertOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    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) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Aggregations

StreamEvent (io.siddhi.core.event.stream.StreamEvent)203 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)92 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)74 StateEvent (io.siddhi.core.event.state.StateEvent)52 ComplexEvent (io.siddhi.core.event.ComplexEvent)33 ArrayList (java.util.ArrayList)27 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)26 Map (java.util.Map)24 Event (io.siddhi.core.event.Event)23 Test (org.testng.annotations.Test)23 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)20 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Attribute (io.siddhi.query.api.definition.Attribute)17 HashMap (java.util.HashMap)17 Operation (io.siddhi.core.event.stream.Operation)12 LinkedList (java.util.LinkedList)12 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)11 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)10 HashSet (java.util.HashSet)10 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)8