Search in sources :

Example 6 with StateEvent

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

the class JoinProcessor method process.

/**
 * Process the handed StreamEvent.
 *
 * @param complexEventChunk event chunk to be processed
 */
@Override
public void process(ComplexEventChunk complexEventChunk) {
    if (trigger) {
        ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<StateEvent>(true);
        StateEvent joinStateEvent = new StateEvent(2, 0);
        StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
        complexEventChunk.clear();
        while (nextEvent != null) {
            StreamEvent streamEvent = nextEvent;
            nextEvent = streamEvent.getNext();
            streamEvent.setNext(null);
            joinLockWrapper.lock();
            try {
                ComplexEvent.Type eventType = streamEvent.getType();
                if (eventType == ComplexEvent.Type.TIMER) {
                    continue;
                } else if (eventType == ComplexEvent.Type.RESET) {
                    if (!leftJoinProcessor) {
                        returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
                    } else {
                        returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
                    }
                } else {
                    joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
                    StreamEvent foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
                    joinStateEvent.setEvent(matchingStreamIndex, null);
                    if (foundStreamEvent == null) {
                        if (outerJoinProcessor && !leftJoinProcessor) {
                            returnEventChunk.add(joinEventBuilder(null, streamEvent, eventType));
                        } else if (outerJoinProcessor && leftJoinProcessor) {
                            returnEventChunk.add(joinEventBuilder(streamEvent, null, eventType));
                        }
                    } else {
                        while (foundStreamEvent != null) {
                            StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
                            foundStreamEvent.setNext(null);
                            if (!leftJoinProcessor) {
                                returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
                            } else {
                                returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
                            }
                            foundStreamEvent = nextFoundStreamEvent;
                        }
                    }
                }
            } finally {
                joinLockWrapper.unlock();
            }
            if (returnEventChunk.getFirst() != null) {
                selector.process(returnEventChunk);
                returnEventChunk.clear();
            }
        }
    } else {
        if (preJoinProcessor) {
            joinLockWrapper.lock();
            try {
                nextProcessor.process(complexEventChunk);
            } finally {
                joinLockWrapper.unlock();
            }
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 7 with StateEvent

use of org.wso2.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<>(false);
    if (!this.active) {
        return returnEventChunk;
    }
    complexEventChunk.reset();
    // Sure only one will be sent
    StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
    this.lock.lock();
    try {
        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;
            }
            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.nextEveryStatePerProcessor != 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.pendingStateEventList.remove(stateEvent);
                }
            }
            if (!stateChanged) {
                switch(stateType) {
                    case PATTERN:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        break;
                    case SEQUENCE:
                        stateEvent.setEvent(stateId, currentStreamEvent);
                        iterator.remove();
                        break;
                }
            }
        }
    } finally {
        this.lock.unlock();
    }
    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 8 with StateEvent

use of org.wso2.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(org.wso2.siddhi.core.event.state.StateEvent)

Example 9 with StateEvent

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

the class StreamPreStateProcessor method init.

public void init() {
    if (isStartState && (!initialized || this.thisStatePostProcessor.nextEveryStatePerProcessor != null || (stateType == StateInputStream.Type.SEQUENCE && this.thisStatePostProcessor.nextStatePerProcessor instanceof AbsentPreStateProcessor))) {
        // For 'every' sequence, the 'thisStatePostProcessor.nextEveryStatePerProcessor != null' check is not enough
        StateEvent stateEvent = stateEventPool.borrowEvent();
        addState(stateEvent);
        initialized = true;
    }
}
Also used : StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 10 with StateEvent

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

the class OutputCallback method constructMatchingStateEventChunk.

protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventPool stateEventPool, int matchingStreamIndex, StreamEventPool streamEventPool, StreamEventConverter streamEventConverter) {
    ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<StateEvent>(matchingComplexEventChunk.isBatch());
    while (matchingComplexEventChunk.hasNext()) {
        ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
        matchingComplexEventChunk.remove();
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (convertToStreamEvent) {
            StreamEvent borrowEvent = streamEventPool.borrowEvent();
            streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
            stateEvent.addEvent(matchingStreamIndex, borrowEvent);
        } else {
            stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
        }
        stateEventChunk.add(stateEvent);
    }
    return stateEventChunk;
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)38 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)34 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)31 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)9 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)7 ArrayList (java.util.ArrayList)6 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)6 HashMap (java.util.HashMap)5 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)5 HashSet (java.util.HashSet)3 Event (org.wso2.siddhi.core.event.Event)3 Collection (java.util.Collection)2 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)2 StoreQueryRuntimeException (org.wso2.siddhi.core.exception.StoreQueryRuntimeException)2 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)2 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 Table (org.wso2.siddhi.core.table.Table)2 IncrementalDataAggregator (org.wso2.siddhi.core.aggregation.IncrementalDataAggregator)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1