Search in sources :

Example 91 with StreamEvent

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

the class AbsentStreamPostStateProcessor method process.

/**
 * This method just mark the state changed but does not send the stateEvent to the next processors.
 *
 * @param stateEvent        the state event
 * @param complexEventChunk the ComplexEventChunk
 */
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    // Mark the state changed
    thisStatePreProcessor.stateChanged();
    // Update the timestamp
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    // This is the notification to AbsentStreamPreStateProcessor that this event has been processed
    this.isEventReturned = true;
    if (thisStatePreProcessor.isStartState) {
        if (nextEveryStatePerProcessor != null && nextEveryStatePerProcessor == thisStatePreProcessor) {
            // nextEveryStatePerProcessor refers the AbsentStreamPreStateProcessor
            nextEveryStatePerProcessor.addEveryState(stateEvent);
        }
    }
    ((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 92 with StreamEvent

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

the class CountPostStateProcessor method process.

protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    int streamEvents = 1;
    while (streamEvent.getNext() != null) {
        streamEvents++;
        streamEvent = streamEvent.getNext();
    }
    ((CountPreStateProcessor) thisStatePreProcessor).successCondition();
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    if (streamEvents >= minCount) {
        if (thisStatePreProcessor.stateType == StateInputStream.Type.SEQUENCE) {
            if (nextStatePerProcessor != null) {
                nextStatePerProcessor.addState(stateEvent);
            }
            if (streamEvents != maxCount) {
                thisStatePreProcessor.addState(stateEvent);
            }
        } else if (streamEvents == minCount) {
            processMinCountReached(stateEvent, complexEventChunk);
        }
        if (streamEvents == maxCount) {
            thisStatePreProcessor.stateChanged();
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 93 with StreamEvent

use of org.wso2.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>(false);
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    for (Iterator<StateEvent> iterator = pendingStateEventList.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));
        successCondition = false;
        process(stateEvent);
        if (this.thisLastProcessor.isEventReturned()) {
            this.thisLastProcessor.clearProcessedEvent();
            returnEventChunk.add(stateEvent);
        }
        if (stateChanged) {
            iterator.remove();
        }
        if (!successCondition) {
            switch(stateType) {
                case PATTERN:
                    stateEvent.removeLastEvent(stateId);
                    break;
                case SEQUENCE:
                    stateEvent.removeLastEvent(stateId);
                    iterator.remove();
                    break;
            }
        }
    }
    return returnEventChunk;
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 94 with StreamEvent

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

the class LogicalPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(false);
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
        StateEvent stateEvent = iterator.next();
        if (withinStates.size() > 0) {
            if (isExpired(stateEvent, streamEvent.getTimestamp())) {
                iterator.remove();
                continue;
            }
        }
        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 (stateChanged) {
            iterator.remove();
        } else {
            switch(stateType) {
                case PATTERN:
                    stateEvent.setEvent(stateId, null);
                    break;
                case SEQUENCE:
                    stateEvent.setEvent(stateId, null);
                    iterator.remove();
                    break;
            }
        }
    }
    return returnEventChunk;
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 95 with StreamEvent

use of org.wso2.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 (nextStatePerProcessor != null) {
        nextStatePerProcessor.addState(stateEvent);
    }
    if (nextEveryStatePerProcessor != null) {
        nextEveryStatePerProcessor.addEveryState(stateEvent);
    }
    if (callbackPreStateProcessor != null) {
        callbackPreStateProcessor.startStateReset();
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5