Search in sources :

Example 1 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project siddhi by wso2.

the class SiddhiAnnotationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    // Iterate over all @Extension annotated elements.
    for (Element element : roundEnv.getElementsAnnotatedWith(Extension.class)) {
        // Check if a class has been annotated with @Extension.
        if (element.getKind() == ElementKind.CLASS) {
            String superClass = getMatchingSuperClass(element, new String[] { AnnotationConstants.SINK_MAPPER_SUPER_CLASS, AnnotationConstants.SINK_SUPER_CLASS, AnnotationConstants.FUNCTION_EXECUTOR_SUPER_CLASS, AnnotationConstants.AGGREGATION_ATTRIBUTE_SUPER_CLASS, AnnotationConstants.DISTRIBUTION_STRATEGY_SUPER_CLASS, AnnotationConstants.STREAM_PROCESSOR_SUPER_CLASS, AnnotationConstants.STREAM_FUNCTION_PROCESSOR_SUPER_CLASS, AnnotationConstants.STORE_SUPER_CLASS, AnnotationConstants.SOURCE_SUPER_CLASS, AnnotationConstants.SOURCE_MAPPER_SUPER_CLASS, AnnotationConstants.WINDOW_PROCESSOR_CLASS, AnnotationConstants.SCRIPT_SUPER_CLASS, AnnotationConstants.INCREMENTAL_ATTRIBUTE_AGGREGATOR_SUPER_CLASS });
            AbstractAnnotationProcessor abstractAnnotationProcessor = null;
            Extension annotation = element.getAnnotation(Extension.class);
            String name = annotation.name();
            String description = annotation.description();
            String namespace = annotation.namespace();
            Parameter[] parameters = annotation.parameters();
            ReturnAttribute[] returnAttributes = annotation.returnAttributes();
            SystemParameter[] systemParameters = annotation.systemParameter();
            Example[] examples = annotation.examples();
            String extensionClassFullName = element.asType().toString();
            if (superClass != null) {
                switch(superClass) {
                    case AnnotationConstants.DISTRIBUTION_STRATEGY_SUPER_CLASS:
                        abstractAnnotationProcessor = new DistributionStrategyValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.SINK_MAPPER_SUPER_CLASS:
                        abstractAnnotationProcessor = new SinkMapperValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.SINK_SUPER_CLASS:
                        abstractAnnotationProcessor = new SinkValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.FUNCTION_EXECUTOR_SUPER_CLASS:
                        abstractAnnotationProcessor = new FunctionExecutorValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.AGGREGATION_ATTRIBUTE_SUPER_CLASS:
                        abstractAnnotationProcessor = new AggregationAttributeValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.STREAM_PROCESSOR_SUPER_CLASS:
                        abstractAnnotationProcessor = new StreamProcessorValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.SOURCE_SUPER_CLASS:
                        abstractAnnotationProcessor = new SourceValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.SOURCE_MAPPER_SUPER_CLASS:
                        abstractAnnotationProcessor = new SourceMapperValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.STORE_SUPER_CLASS:
                        abstractAnnotationProcessor = new StoreValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.STREAM_FUNCTION_PROCESSOR_SUPER_CLASS:
                        abstractAnnotationProcessor = new StreamFunctionProcessorValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.WINDOW_PROCESSOR_CLASS:
                        abstractAnnotationProcessor = new WindowProcessorValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.SCRIPT_SUPER_CLASS:
                        abstractAnnotationProcessor = new ScriptValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    case AnnotationConstants.INCREMENTAL_ATTRIBUTE_AGGREGATOR_SUPER_CLASS:
                        abstractAnnotationProcessor = new IncrementalAggregationAttributeValidationAnnotationProcessor(extensionClassFullName);
                        break;
                    default:
                        // Throw error if no matching super class.
                        showBuildError(MessageFormat.format("Default switch case executed as there is no " + "matching super class option for @{0}.", superClass), element);
                        break;
                }
                if (abstractAnnotationProcessor != null) {
                    try {
                        abstractAnnotationProcessor.basicParameterValidation(name, description, namespace);
                        abstractAnnotationProcessor.parameterValidation(parameters);
                        abstractAnnotationProcessor.returnAttributesValidation(returnAttributes);
                        abstractAnnotationProcessor.systemParametersValidation(systemParameters);
                        abstractAnnotationProcessor.examplesValidation(examples);
                    } catch (AnnotationValidationException e) {
                        showBuildError(e.getMessage(), element);
                    }
                } else {
                    showBuildError(MessageFormat.format("Error while validation, " + "abstractAnnotationProcessor cannot be null.", superClass), element);
                }
            } else {
                // Throw error if no matching super class.
                showBuildError("Class does not have a matching Siddhi Extension super class.", element);
            }
        } else {
            // Throw error if the element returned is method or package.
            showBuildError(MessageFormat.format("Only classes can be annotated with @{0}.", Extension.class.getCanonicalName()), element);
        }
    }
    // Returning false since this processor only validates.
    return false;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) AnnotationValidationException(org.wso2.siddhi.annotation.util.AnnotationValidationException) ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Example(org.wso2.siddhi.annotation.Example) SystemParameter(org.wso2.siddhi.annotation.SystemParameter) Extension(org.wso2.siddhi.annotation.Extension) Parameter(org.wso2.siddhi.annotation.Parameter) SystemParameter(org.wso2.siddhi.annotation.SystemParameter)

Example 2 with Parameter

use of org.wso2.siddhi.annotation.Parameter 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 3 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project siddhi by wso2.

the class ExternalTimeBatchWindowProcessor method process.

/**
 * Here an assumption is taken:
 * Parameter: timestamp: The time which the window determines as current time and will act upon,
 * the value of this parameter should be monotonically increasing.
 * from https://docs.wso2.com/display/CEP400/Inbuilt+Windows#InbuiltWindows-externalTime
 */
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    // event incoming trigger process. No events means no action
    if (streamEventChunk.getFirst() == null) {
        return;
    }
    List<ComplexEventChunk<StreamEvent>> complexEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
    synchronized (this) {
        initTiming(streamEventChunk.getFirst());
        StreamEvent nextStreamEvent = streamEventChunk.getFirst();
        while (nextStreamEvent != null) {
            StreamEvent currStreamEvent = nextStreamEvent;
            nextStreamEvent = nextStreamEvent.getNext();
            if (currStreamEvent.getType() == ComplexEvent.Type.TIMER) {
                if (lastScheduledTime <= currStreamEvent.getTimestamp()) {
                    // implies that there have not been any more events after this schedule has been done.
                    if (!flushed) {
                        flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
                        flushed = true;
                    } else {
                        if (currentEventChunk.getFirst() != null) {
                            appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, true);
                        }
                    }
                    // rescheduling to emit the current batch after expiring it if no further events arrive.
                    lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
                    scheduler.notifyAt(lastScheduledTime);
                }
                continue;
            } else if (currStreamEvent.getType() != ComplexEvent.Type.CURRENT) {
                continue;
            }
            long currentEventTime = (Long) timestampExpressionExecutor.execute(currStreamEvent);
            if (lastCurrentEventTime < currentEventTime) {
                lastCurrentEventTime = currentEventTime;
            }
            if (currentEventTime < endTime) {
                cloneAppend(streamEventCloner, currStreamEvent);
            } else {
                if (flushed) {
                    appendToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
                    flushed = false;
                } else {
                    flushToOutputChunk(streamEventCloner, complexEventChunks, lastCurrentEventTime, false);
                }
                // update timestamp, call next processor
                endTime = findEndTime(lastCurrentEventTime, startTime, timeToKeep);
                cloneAppend(streamEventCloner, currStreamEvent);
                // triggering the last batch expiration.
                if (schedulerTimeout > 0) {
                    lastScheduledTime = siddhiAppContext.getTimestampGenerator().currentTime() + schedulerTimeout;
                    scheduler.notifyAt(lastScheduledTime);
                }
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> complexEventChunk : complexEventChunks) {
        nextProcessor.process(complexEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 4 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project siddhi by wso2.

the class TimeBatchWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    this.siddhiAppContext = siddhiAppContext;
    if (outputExpectsExpiredEvents) {
        this.expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
    }
    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else if (attributeExpressionExecutors.length == 2) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("Time window's parameter attribute should be either " + "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " + "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
        // start time
        isStartTimeEnabled = true;
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else {
            startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        }
    } else {
        throw new SiddhiAppValidationException("Time window should only have one or two parameters. " + "(<int|long|time> windowTime), but found " + attributeExpressionExecutors.length + " input " + "attributes");
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 5 with Parameter

use of org.wso2.siddhi.annotation.Parameter in project siddhi by wso2.

the class TimeLengthWindowProcessor method init.

@Override
protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    expiredEventChunk = new ComplexEventChunk<StreamEvent>(false);
    if (attributeExpressionExecutors.length == 2) {
        length = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue();
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("TimeLength window's first parameter attribute should " + "be either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("TimeLength window should have constant parameter " + "attributes but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("TimeLength window should only have two parameters (<int> " + "windowTime,<int> windowLength), but found " + attributeExpressionExecutors.length + " input " + "attributes");
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)19 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)8 List (java.util.List)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)7 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)7 Parameter (org.apache.axis2.description.Parameter)6 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)6