Search in sources :

Example 6 with SiddhiAppRuntimeException

use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class SumIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    Attribute sum;
    Expression sumInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Sum incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.DOUBLE);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("double"));
        returnType = Attribute.Type.DOUBLE;
    } else if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.LONG);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("long"));
        returnType = Attribute.Type.LONG;
    } else {
        throw new SiddhiAppRuntimeException("Sum aggregation cannot be executed on attribute type " + attributeType.toString());
    }
    this.baseAttributes = new Attribute[] { sum };
    // Original attribute names
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue };
    assert baseAttributes.length == baseAttributesInitialValues.length;
}
Also used : ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Attribute(org.wso2.siddhi.query.api.definition.Attribute) Expression(org.wso2.siddhi.query.api.expression.Expression) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Example 7 with SiddhiAppRuntimeException

use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class PassThroughSourceMapper method mapAndProcess.

@Override
protected void mapAndProcess(Object eventObject, InputEventHandler inputEventHandler) throws InterruptedException {
    if (eventObject != null) {
        if (eventObject instanceof Event[]) {
            inputEventHandler.sendEvents((Event[]) eventObject);
        } else if (eventObject instanceof Event) {
            inputEventHandler.sendEvent((Event) eventObject);
        } else if (eventObject instanceof Object[]) {
            Event event = new Event(-1, (Object[]) eventObject);
            inputEventHandler.sendEvent(event);
        } else {
            throw new SiddhiAppRuntimeException("Event object must be either Event[], Event or Object[] " + "but found " + eventObject.getClass().getCanonicalName());
        }
    }
}
Also used : SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) Event(org.wso2.siddhi.core.event.Event)

Example 8 with SiddhiAppRuntimeException

use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException 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 9 with SiddhiAppRuntimeException

use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException 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 10 with SiddhiAppRuntimeException

use of org.wso2.siddhi.core.exception.SiddhiAppRuntimeException in project siddhi by wso2.

the class TableWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        TableWindowProcessor streamProcessor = new TableWindowProcessor(table);
        streamProcessor.inputDefinition = inputDefinition;
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
        ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
        for (int i = 0; i < attributeExpressionLength; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
        }
        streamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
        streamProcessor.attributeExpressionLength = attributeExpressionLength;
        streamProcessor.additionalAttributes = additionalAttributes;
        streamProcessor.complexEventPopulater = complexEventPopulater;
        streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        streamProcessor.start();
        return streamProcessor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Aggregations

SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)13 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)7 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)6 ReturnAttribute (org.wso2.siddhi.annotation.ReturnAttribute)3 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)3 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)3 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)3 Attribute (org.wso2.siddhi.query.api.definition.Attribute)3 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)2 IncrementalDataAggregator (org.wso2.siddhi.core.aggregation.IncrementalDataAggregator)1 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)1 Event (org.wso2.siddhi.core.event.Event)1 IncrementalUnixTimeFunctionExecutor (org.wso2.siddhi.core.executor.incremental.IncrementalUnixTimeFunctionExecutor)1 Table (org.wso2.siddhi.core.table.Table)1 TimePeriod (org.wso2.siddhi.query.api.aggregation.TimePeriod)1 Expression (org.wso2.siddhi.query.api.expression.Expression)1