Search in sources :

Example 26 with StateEvent

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

the class JoinProcessor method joinEventBuilder.

/**
 * Join the given two event streams.
 *
 * @param leftStream event left stream
 * @param rightStream event right stream
 * @param type complex event type
 * @return StateEvent state event
 */
public StateEvent joinEventBuilder(StreamEvent leftStream, StreamEvent rightStream, ComplexEvent.Type type) {
    StateEvent returnEvent = stateEventPool.borrowEvent();
    returnEvent.setEvent(0, leftStream);
    returnEvent.setEvent(1, rightStream);
    returnEvent.setType(type);
    if (!leftJoinProcessor) {
        returnEvent.setTimestamp(rightStream.getTimestamp());
    } else {
        returnEvent.setTimestamp(leftStream.getTimestamp());
    }
    return returnEvent;
}
Also used : StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 27 with StateEvent

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

Example 28 with StateEvent

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

the class AbsentLogicalPreStateProcessor method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    if (!this.active) {
        return;
    }
    this.lock.lock();
    boolean notProcessed = true;
    try {
        long currentTime = complexEventChunk.getFirst().getTimestamp();
        if (currentTime >= this.lastArrivalTime + waitingTime) {
            ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>(false);
            Iterator<StateEvent> iterator;
            if (isStartState && stateType == StateInputStream.Type.SEQUENCE && newAndEveryStateEventList.isEmpty() && pendingStateEventList.isEmpty()) {
                StateEvent stateEvent = stateEventPool.borrowEvent();
                addState(stateEvent);
            } else if (stateType == StateInputStream.Type.SEQUENCE && !newAndEveryStateEventList.isEmpty()) {
                this.resetState();
            }
            this.updateState();
            iterator = pendingStateEventList.iterator();
            while (iterator.hasNext()) {
                StateEvent stateEvent = iterator.next();
                // Remove expired events based on within
                if (withinStates.size() > 0) {
                    if (isExpired(stateEvent, currentTime)) {
                        iterator.remove();
                        continue;
                    }
                }
                // Collect the events that came before the waiting time
                if (waitingTimePassed(currentTime, stateEvent)) {
                    iterator.remove();
                    if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
                        // OR Partner not received
                        stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
                        retEventChunk.add(stateEvent);
                    } else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
                        // AND partner received but didn't send out
                        retEventChunk.add(stateEvent);
                    } else if (logicalType == LogicalStateElement.Type.AND && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) == null) {
                        // AND partner didn't receive
                        // Let the partner to process or not
                        stateEvent.addEvent(stateId, streamEventPool.borrowEvent());
                    }
                }
            }
            retEventChunk.reset();
            notProcessed = retEventChunk.getFirst() == null;
            while (retEventChunk.hasNext()) {
                StateEvent stateEvent = retEventChunk.next();
                retEventChunk.remove();
                sendEvent(stateEvent);
            }
            this.lastArrivalTime = 0;
        }
    } finally {
        this.lock.unlock();
    }
    if (thisStatePostProcessor.nextEveryStatePerProcessor != null || (notProcessed && isStartState)) {
        // If every or (notProcessed and startState), schedule again
        long nextBreak;
        if (lastArrivalTime == 0) {
            nextBreak = siddhiAppContext.getTimestampGenerator().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 29 with StateEvent

use of org.wso2.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);
    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);
    // Start state takes events from newAndEveryStateEventList
    newAndEveryStateEventList.add(clonedEvent);
    partnerStatePreProcessor.newAndEveryStateEventList.add(clonedEvent);
}
Also used : StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 30 with StateEvent

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

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