Search in sources :

Example 1 with ConfigReader

use of org.wso2.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class CoalesceFunctionExecutor method init.

@Override
public void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    if (attributeExpressionExecutors.length == 0) {
        throw new SiddhiAppValidationException("Coalesce must have at least one parameter");
    }
    Attribute.Type type = attributeExpressionExecutors[0].getReturnType();
    for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) {
        if (type != expressionExecutor.getReturnType()) {
            throw new SiddhiAppValidationException("Coalesce cannot have parameters with different type");
        }
    }
    returnType = type;
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 2 with ConfigReader

use of org.wso2.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class FunctionExecutor method cloneExecutor.

@Override
public ExpressionExecutor cloneExecutor(String key) {
    try {
        FunctionExecutor functionExecutor = this.getClass().newInstance();
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeSize];
        for (int i = 0; i < attributeSize; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors[i].cloneExecutor(key);
        }
        functionExecutor.elementId = elementId + "-" + key;
        functionExecutor.functionId = functionId;
        functionExecutor.initExecutor(innerExpressionExecutors, siddhiAppContext, queryName, configReader);
        return functionExecutor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException)

Example 3 with ConfigReader

use of org.wso2.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class AbstractStreamProcessor method cloneProcessor.

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

Example 4 with ConfigReader

use of org.wso2.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class LogStreamProcessor method init.

/**
 * The init method of the StreamFunction
 *
 * @param inputDefinition              the incoming stream definition
 * @param attributeExpressionExecutors the executors for the function parameters
 * @param siddhiAppContext         siddhi app context
 * @param configReader this hold the {@link LogStreamProcessor} configuration reader.
 * @return the additional output attributes introduced by the function
 */
@Override
protected List<Attribute> init(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    int inputExecutorLength = attributeExpressionExecutors.length;
    if (inputExecutorLength == 1) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
            logMessageExpressionExecutor = attributeExpressionExecutors[0];
        } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.BOOL) {
            isLogEventExpressionExecutor = attributeExpressionExecutors[0];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'isEventLogged (Bool)' " + "or 'logMessage (String)' or 'isEventLogged (Bool), logMessage (String)' or 'priority " + "(String), isEventLogged (Bool), logMessage (String)', but its 1st attribute is " + attributeExpressionExecutors[0].getReturnType());
        }
    } else if (inputExecutorLength == 2) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.BOOL) {
            logMessageExpressionExecutor = attributeExpressionExecutors[0];
            isLogEventExpressionExecutor = attributeExpressionExecutors[1];
        } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING && attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
            if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
                logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
            } else {
                logPriorityExpressionExecutor = attributeExpressionExecutors[0];
            }
            logMessageExpressionExecutor = attributeExpressionExecutors[1];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'logMessage (String), " + "isEventLogged (Bool)' or 'priority (String), logMessage (String)', but its returning are '" + attributeExpressionExecutors[0].getReturnType() + ", " + attributeExpressionExecutors[1].getReturnType() + "'");
        }
    } else if (inputExecutorLength == 3) {
        if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.STRING) {
            if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
                logPriority = LogPriority.valueOf(((String) attributeExpressionExecutors[0].execute(null)).toUpperCase());
            } else {
                logPriorityExpressionExecutor = attributeExpressionExecutors[0];
            }
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 1st attribute is returning " + attributeExpressionExecutors[0].getReturnType());
        }
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.STRING) {
            logMessageExpressionExecutor = attributeExpressionExecutors[1];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 2nd attribute is returning " + attributeExpressionExecutors[1].getReturnType());
        }
        if (attributeExpressionExecutors[2].getReturnType() == Attribute.Type.BOOL) {
            isLogEventExpressionExecutor = attributeExpressionExecutors[2];
        } else {
            throw new SiddhiAppValidationException("Input attribute is expected to be 'priority (String), " + "logMessage (String), isEventLogged (Bool)', but its 3rd attribute is returning " + attributeExpressionExecutors[2].getReturnType());
        }
    } else if (inputExecutorLength > 3) {
        throw new SiddhiAppValidationException("Input parameters for Log can be logMessage (String), " + "isEventLogged (Bool), but there are " + attributeExpressionExecutors.length + " in the input!");
    }
    logPrefix = siddhiAppContext.getName() + ": ";
    return new ArrayList<Attribute>();
}
Also used : ArrayList(java.util.ArrayList) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 5 with ConfigReader

use of org.wso2.siddhi.core.util.config.ConfigReader in project siddhi by wso2.

the class AggregateWindowProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        AggregateWindowProcessor streamProcessor = new AggregateWindowProcessor(aggregationRuntime, within, per);
        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

SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)12 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)11 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)10 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)10 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 ConfigReader (org.wso2.siddhi.core.util.config.ConfigReader)7 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)6 Attribute (org.wso2.siddhi.query.api.definition.Attribute)6 Extension (org.wso2.siddhi.query.api.extension.Extension)6 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)4 ArrayList (java.util.ArrayList)3 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)3 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)2 WindowProcessor (org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor)2 Table (org.wso2.siddhi.core.table.Table)2 ReturnAttribute (org.wso2.siddhi.annotation.ReturnAttribute)1 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)1 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)1