Search in sources :

Example 66 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk 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 67 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk 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 68 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk 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 69 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class InsertIntoStreamCallback method send.

@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    complexEventChunk.reset();
    while (complexEventChunk.hasNext()) {
        ComplexEvent complexEvent = complexEventChunk.next();
        if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
            complexEvent.setType(ComplexEvent.Type.CURRENT);
        }
    }
    publisher.send(complexEventChunk.getFirst());
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 70 with ComplexEventChunk

use of org.wso2.siddhi.core.event.ComplexEventChunk in project siddhi by wso2.

the class OutputRateLimiter method sendToCallBacks.

protected void sendToCallBacks(ComplexEventChunk complexEventChunk) {
    if (siddhiAppContext.isStatsEnabled() && latencyTracker != null) {
        latencyTracker.markOut();
    }
    if (lockWrapper != null) {
        lockWrapper.unlock();
    }
    if (!queryCallbacks.isEmpty()) {
        for (QueryCallback callback : queryCallbacks) {
            callback.receiveStreamEvent(complexEventChunk);
        }
    }
    if (outputCallback != null && complexEventChunk.getFirst() != null) {
        complexEventChunk.reset();
        int noOfEvents = 0;
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                complexEvent.setType(ComplexEvent.Type.CURRENT);
                noOfEvents++;
            } else if (complexEvent.getType() == ComplexEvent.Type.RESET) {
                complexEventChunk.remove();
            } else {
                noOfEvents++;
            }
        }
        if (complexEventChunk.getFirst() != null) {
            outputCallback.send(complexEventChunk, noOfEvents);
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)72 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)69 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)44 ArrayList (java.util.ArrayList)30 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)26 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)19 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)17 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)13 Map (java.util.Map)12 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 HashMap (java.util.HashMap)6 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)5 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)4 Collection (java.util.Collection)3 Event (org.wso2.siddhi.core.event.Event)3 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)3 Table (org.wso2.siddhi.core.table.Table)3 Iterator (java.util.Iterator)2 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2