Search in sources :

Example 71 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalAggregationProcessor method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    ComplexEventChunk<StreamEvent> streamEventChunk = new ComplexEventChunk<>(complexEventChunk.isBatch());
    try {
        int noOfEvents = 0;
        if (latencyTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
            latencyTrackerInsert.markIn();
        }
        while (complexEventChunk.hasNext()) {
            ComplexEvent complexEvent = complexEventChunk.next();
            StreamEvent borrowedEvent = streamEventPool.borrowEvent();
            for (int i = 0; i < incomingExpressionExecutors.size(); i++) {
                ExpressionExecutor expressionExecutor = incomingExpressionExecutors.get(i);
                Object outputData = expressionExecutor.execute(complexEvent);
                if (expressionExecutor instanceof IncrementalUnixTimeFunctionExecutor && outputData == null) {
                    throw new SiddhiAppRuntimeException("Cannot retrieve the timestamp of event");
                }
                borrowedEvent.setOutputData(outputData, i);
            }
            streamEventChunk.add(borrowedEvent);
            noOfEvents++;
        }
        incrementalExecutor.execute(streamEventChunk);
        if (throughputTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
            throughputTrackerInsert.eventsIn(noOfEvents);
        }
    } finally {
        if (latencyTrackerInsert != null && siddhiAppContext.isStatsEnabled()) {
            latencyTrackerInsert.markOut();
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) IncrementalUnixTimeFunctionExecutor(org.wso2.siddhi.core.executor.incremental.IncrementalUnixTimeFunctionExecutor)

Example 72 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalDataAggregator method process.

private void process(StreamEvent streamEvent, BaseIncrementalValueStore baseIncrementalValueStore) {
    List<ExpressionExecutor> expressionExecutors = baseIncrementalValueStore.getExpressionExecutors();
    for (int i = 0; i < expressionExecutors.size(); i++) {
        // keeping timestamp value location as null
        ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
        baseIncrementalValueStore.setValue(expressionExecutor.execute(streamEvent), i + 1);
    }
    baseIncrementalValueStore.setProcessed(true);
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor)

Example 73 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalExecutor method sendTimerEvent.

private void sendTimerEvent(String timeZone) {
    if (getNextExecutor() != null) {
        StreamEvent timerEvent = streamEventPool.borrowEvent();
        timerEvent.setType(ComplexEvent.Type.TIMER);
        timerEvent.setTimestamp(IncrementalTimeConverterUtil.getPreviousStartTime(startTimeOfAggregates, this.duration, timeZone));
        ComplexEventChunk<StreamEvent> timerStreamEventChunk = new ComplexEventChunk<>(true);
        timerStreamEventChunk.add(timerEvent);
        next.execute(timerStreamEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 74 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalExecutor method execute.

@Override
public void execute(ComplexEventChunk streamEventChunk) {
    LOG.debug("Event Chunk received by " + this.duration + " incremental executor: " + streamEventChunk.toString());
    streamEventChunk.reset();
    while (streamEventChunk.hasNext()) {
        StreamEvent streamEvent = (StreamEvent) streamEventChunk.next();
        streamEventChunk.remove();
        String timeZone = getTimeZone(streamEvent);
        long timestamp = getTimestamp(streamEvent, timeZone);
        startTimeOfAggregates = IncrementalTimeConverterUtil.getStartTimeOfAggregates(timestamp, duration, timeZone);
        if (isRootAndLoadedFromTable) {
            // arise when replaying data.
            if (timestamp < nextEmitTime) {
                continue;
            } else {
                isRootAndLoadedFromTable = false;
            }
        }
        if (bufferSize > 0 && isRoot) {
            try {
                mutex.acquire();
                dispatchBufferedAggregateEvents(startTimeOfAggregates);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new SiddhiAppRuntimeException("Error when dispatching events from buffer", e);
            } finally {
                mutex.release();
            }
            if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
                if (!eventOlderThanBuffer) {
                    processAggregates(streamEvent);
                } else if (!ignoreEventsOlderThanBuffer) {
                    // Incoming event is older than buffer
                    startTimeOfAggregates = minTimestampInBuffer;
                    processAggregates(streamEvent);
                }
            }
        } else {
            if (timestamp >= nextEmitTime) {
                nextEmitTime = IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone);
                dispatchAggregateEvents(startTimeOfAggregates);
                if (!isProcessingOnExternalTime) {
                    sendTimerEvent(timeZone);
                }
            }
            if (streamEvent.getType() == ComplexEvent.Type.CURRENT) {
                if (nextEmitTime == IncrementalTimeConverterUtil.getNextEmitTime(timestamp, duration, timeZone)) {
                    // This condition checks whether incoming event belongs to current processing event's time slot
                    processAggregates(streamEvent);
                } else if (!ignoreEventsOlderThanBuffer) {
                    // Incoming event is older than current processing event.
                    startTimeOfAggregates = minTimestampInBuffer;
                    processAggregates(streamEvent);
                }
            }
        }
    }
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Example 75 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class IncrementalExecutor method process.

private void process(StreamEvent streamEvent, BaseIncrementalValueStore baseIncrementalValueStore) {
    List<ExpressionExecutor> expressionExecutors = baseIncrementalValueStore.getExpressionExecutors();
    for (int i = 0; i < expressionExecutors.size(); i++) {
        // keeping timestamp value location as null
        ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
        baseIncrementalValueStore.setValue(expressionExecutor.execute(streamEvent), i + 1);
    }
    baseIncrementalValueStore.setProcessed(true);
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5