Search in sources :

Example 31 with StateEvent

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

the class AbsentStreamPreStateProcessor method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    if (!this.active) {
        // Every keyword is not used and already a pattern is processed
        return;
    }
    boolean notProcessed = true;
    long currentTime = complexEventChunk.getFirst().getTimestamp();
    if (currentTime >= this.lastArrivalTime + waitingTime) {
        synchronized (this) {
            // If the process method is called, it is guaranteed that the waitingTime is passed
            boolean initialize;
            initialize = isStartState && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty();
            if (initialize && stateType == StateInputStream.Type.SEQUENCE && thisStatePostProcessor.nextEveryStatePerProcessor == null && this.lastArrivalTime > 0) {
                // Sequence with no every but an event arrived
                initialize = false;
            }
            if (initialize) {
                // This is the first processor and no events received so far
                StateEvent stateEvent = stateEventPool.borrowEvent();
                addState(stateEvent);
            } else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
                this.resetState();
            }
            this.updateState();
            ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
            Iterator<StateEvent> iterator = pendingStateEventList.iterator();
            while (iterator.hasNext()) {
                StateEvent event = iterator.next();
                // Remove expired events based on within
                if (withinStates.size() > 0) {
                    if (isExpired(event, currentTime)) {
                        iterator.remove();
                        continue;
                    }
                }
                // Collect the events that came before the waiting time
                if (currentTime >= event.getTimestamp() + waitingTime) {
                    iterator.remove();
                    event.setTimestamp(currentTime);
                    retEventChunk.add(event);
                }
            }
            notProcessed = retEventChunk.getFirst() == null;
            while (retEventChunk.hasNext()) {
                StateEvent stateEvent = retEventChunk.next();
                retEventChunk.remove();
                sendEvent(stateEvent);
            }
        }
        this.lastArrivalTime = 0;
    }
    if (thisStatePostProcessor.nextEveryStatePerProcessor == this || (notProcessed && isStartState)) {
        // If every or (notProcessed and startState), schedule again
        long nextBreak;
        if (lastArrivalTime == 0) {
            nextBreak = currentTime + waitingTime;
        } else {
            nextBreak = lastArrivalTime + waitingTime;
        }
        this.scheduler.notifyAt(nextBreak);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 32 with StateEvent

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

the class AbsentStreamPreStateProcessor method processAndReturn.

@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
    if (!this.active) {
        return new ComplexEventChunk<>(false);
    }
    ComplexEventChunk<StateEvent> event = super.processAndReturn(complexEventChunk);
    StateEvent firstEvent = event.getFirst();
    if (firstEvent != null) {
        event = new ComplexEventChunk<>(false);
    }
    // Always return an empty event
    return event;
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 33 with StateEvent

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

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

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

the class LogicalPreStateProcessor method addEveryState.

@Override
public void addEveryState(StateEvent stateEvent) {
    StateEvent clonedEvent = stateEventCloner.copyStateEvent(stateEvent);
    clonedEvent.setEvent(stateId, null);
    newAndEveryStateEventList.add(clonedEvent);
    if (partnerStatePreProcessor != null) {
        clonedEvent.setEvent(partnerStatePreProcessor.stateId, null);
        partnerStatePreProcessor.newAndEveryStateEventList.add(clonedEvent);
    }
}
Also used : 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