Search in sources :

Example 36 with Processor

use of org.wso2.siddhi.core.query.processor.Processor 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 37 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.

the class LogStreamProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        switch(attributeExpressionLength) {
            case 0:
                log.info(logPrefix + complexEvent);
                break;
            case 1:
                if (isLogEventExpressionExecutor != null) {
                    if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                        log.info(logPrefix + complexEvent);
                    } else {
                        log.info(logPrefix + "Event Arrived");
                    }
                } else {
                    log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
                }
                break;
            case 2:
                if (isLogEventExpressionExecutor != null) {
                    if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                        log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent);
                    } else {
                        log.info(logPrefix + logMessageExpressionExecutor.execute(complexEvent));
                    }
                } else {
                    LogPriority tempLogPriority = logPriority;
                    if (logPriorityExpressionExecutor != null) {
                        tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
                    }
                    String message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
                    logMessage(tempLogPriority, message);
                }
                break;
            default:
                String message;
                if ((Boolean) isLogEventExpressionExecutor.execute(complexEvent)) {
                    message = logPrefix + logMessageExpressionExecutor.execute(complexEvent) + ", " + complexEvent;
                } else {
                    message = logPrefix + logMessageExpressionExecutor.execute(complexEvent);
                }
                LogPriority tempLogPriority = logPriority;
                if (logPriorityExpressionExecutor != null) {
                    tempLogPriority = LogPriority.valueOf((String) logPriorityExpressionExecutor.execute(complexEvent));
                }
                logMessage(tempLogPriority, message);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 38 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.

the class StreamFunctionProcessor method processEventChunk.

@Override
protected void processEventChunk(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    while (streamEventChunk.hasNext()) {
        ComplexEvent complexEvent = streamEventChunk.next();
        Object[] outputData;
        switch(attributeExpressionLength) {
            case 0:
                outputData = process((Object) null);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            case 1:
                outputData = process(attributeExpressionExecutors[0].execute(complexEvent));
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
                break;
            default:
                Object[] inputData = new Object[attributeExpressionLength];
                for (int i = 0; i < attributeExpressionLength; i++) {
                    inputData[i] = attributeExpressionExecutors[i].execute(complexEvent);
                }
                outputData = process(inputData);
                complexEventPopulater.populateComplexEvent(complexEvent, outputData);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 39 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.

the class CronWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
            streamEventChunk.remove();
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 40 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.

the class ExternalTimeBatchWindowProcessor method flushToOutputChunk.

private void flushToOutputChunk(StreamEventCloner streamEventCloner, List<ComplexEventChunk<StreamEvent>> complexEventChunks, long currentTime, boolean preserveCurrentEvents) {
    ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<StreamEvent>(true);
    if (outputExpectsExpiredEvents) {
        if (expiredEventChunk.getFirst() != null) {
            // mark the timestamp for the expiredType event
            expiredEventChunk.reset();
            while (expiredEventChunk.hasNext()) {
                StreamEvent expiredEvent = expiredEventChunk.next();
                expiredEvent.setTimestamp(currentTime);
            }
            // add expired event to newEventChunk.
            newEventChunk.add(expiredEventChunk.getFirst());
        }
    }
    if (expiredEventChunk != null) {
        expiredEventChunk.clear();
    }
    if (currentEventChunk.getFirst() != null) {
        // add reset event in front of current events
        resetEvent.setTimestamp(currentTime);
        newEventChunk.add(resetEvent);
        resetEvent = null;
        // move to expired events
        if (preserveCurrentEvents || storeExpiredEvents) {
            currentEventChunk.reset();
            while (currentEventChunk.hasNext()) {
                StreamEvent currentEvent = currentEventChunk.next();
                StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                expiredEventChunk.add(toExpireEvent);
            }
        }
        // add current event chunk to next processor
        newEventChunk.add(currentEventChunk.getFirst());
    }
    currentEventChunk.clear();
    if (newEventChunk.getFirst() != null) {
        complexEventChunks.add(newEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)15 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)11 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)6 Processor (org.wso2.siddhi.core.query.processor.Processor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)5 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)5 Test (org.testng.annotations.Test)4 API (org.wso2.carbon.apimgt.core.models.API)4 Label (org.wso2.carbon.apimgt.core.models.Label)4 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)4 WindowProcessor (org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor)4 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)3 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)3 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 SchedulingProcessor (org.wso2.siddhi.core.query.processor.SchedulingProcessor)3