Search in sources :

Example 6 with ComplexEventPopulater

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

the class StreamEventPopulaterFactory method constructEventPopulator.

/**
 * Constructs StreamEventPopulater according to MetaStateEvent and to be mapped attributes
 *
 * @param metaStreamEvent       info for populating the StreamEvent
 * @param streamEventChainIndex StreamEvent chain index
 * @param attributes            mapped attributes
 * @return StateEventPopulater
 */
public static ComplexEventPopulater constructEventPopulator(MetaStreamEvent metaStreamEvent, int streamEventChainIndex, List<Attribute> attributes) {
    List<StreamMappingElement> streamMappingElements = new ArrayList<StreamMappingElement>();
    for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) {
        Attribute attribute = attributes.get(i);
        StreamMappingElement streamMappingElement = new StreamMappingElement();
        streamMappingElement.setFromPosition(i);
        int index = metaStreamEvent.getOutputData().indexOf(attribute);
        if (index > -1) {
            streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, OUTPUT_DATA_INDEX, index });
        } else {
            index = metaStreamEvent.getOnAfterWindowData().indexOf(attribute);
            if (index > -1) {
                streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, ON_AFTER_WINDOW_DATA_INDEX, index });
            } else {
                index = metaStreamEvent.getBeforeWindowData().indexOf(attribute);
                if (index > -1) {
                    streamMappingElement.setToPosition(new int[] { streamEventChainIndex, 0, BEFORE_WINDOW_DATA_INDEX, index });
                } else {
                    streamMappingElement.setToPosition(null);
                }
            }
        }
        streamMappingElements.add(streamMappingElement);
    }
    return new SelectiveComplexEventPopulater(streamMappingElements);
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList)

Example 7 with ComplexEventPopulater

use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater 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 8 with ComplexEventPopulater

use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater 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 9 with ComplexEventPopulater

use of org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater 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)

Example 10 with ComplexEventPopulater

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

the class WindowWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        WindowWindowProcessor streamProcessor = new WindowWindowProcessor(window);
        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)4 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)4 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)3 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)3 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)2 ComplexEventPopulater (org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater)2 IncrementalAggregateCompileCondition (org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition)2 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 StateEventCloner (org.wso2.siddhi.core.event.state.StateEventCloner)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1 FindStoreQueryRuntime (org.wso2.siddhi.core.query.FindStoreQueryRuntime)1 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)1 JoinProcessor (org.wso2.siddhi.core.query.input.stream.join.JoinProcessor)1 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)1 Processor (org.wso2.siddhi.core.query.processor.Processor)1