Java Code Examples for io.siddhi.core.config.SiddhiAppContext#getSiddhiAppString()

The following examples show how to use io.siddhi.core.config.SiddhiAppContext#getSiddhiAppString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamJunction.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public StreamJunction(StreamDefinition streamDefinition, ExecutorService executorService, int bufferSize,
                      StreamJunction faultStreamJunction, SiddhiAppContext siddhiAppContext) {
    this.streamDefinition = streamDefinition;
    this.bufferSize = bufferSize;
    this.batchSize = bufferSize;
    this.executorService = executorService;
    this.siddhiAppContext = siddhiAppContext;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_STREAMS, null);
    }
    this.faultStreamJunction = faultStreamJunction;
    if (faultStreamJunction != null) {
        StreamDefinition faultStreamDefinition = faultStreamJunction.getStreamDefinition();
        StreamEventFactory faultStreamEventFactory = new StreamEventFactory(0, 0,
                faultStreamDefinition.getAttributeList().size());
        faultStreamEventConverter = new FaultStreamEventConverter(faultStreamEventFactory);
    }
    try {
        Annotation asyncAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ASYNC,
                streamDefinition.getAnnotations());
        if (asyncAnnotation != null) {
            async = true;
            String bufferSizeString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_BUFFER_SIZE);
            if (bufferSizeString != null) {
                this.bufferSize = Integer.parseInt(bufferSizeString);
            }
            String workersString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_WORKERS);
            if (workersString != null) {
                this.workers = Integer.parseInt(workersString);
                if (workers <= 0) {
                    throw new SiddhiAppCreationException("Annotation element '" +
                            SiddhiConstants.ANNOTATION_ELEMENT_WORKERS + "' cannot be negative or zero, " +
                            "but found, '" + workers + "'.", asyncAnnotation.getQueryContextStartIndex(),
                            asyncAnnotation.getQueryContextEndIndex(), siddhiAppContext.getName(),
                            siddhiAppContext.getSiddhiAppString());
                }
            }
            String batchSizeString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_MAX_BATCH_SIZE);
            if (batchSizeString != null) {
                this.batchSize = Integer.parseInt(batchSizeString);
                if (batchSize <= 0) {
                    throw new SiddhiAppCreationException("Annotation element '" +
                            SiddhiConstants.ANNOTATION_ELEMENT_MAX_BATCH_SIZE + "' cannot be negative or zero, " +
                            "but found, '" + batchSize + "'.", asyncAnnotation.getQueryContextStartIndex(),
                            asyncAnnotation.getQueryContextEndIndex(), siddhiAppContext.getName(),
                            siddhiAppContext.getSiddhiAppString());
                }
            }
        }
        Annotation onErrorAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ON_ERROR,
                streamDefinition.getAnnotations());
        if (onErrorAnnotation != null) {
            this.onErrorAction = OnErrorAction.valueOf(onErrorAnnotation
                    .getElement(SiddhiConstants.ANNOTATION_ELEMENT_ACTION).toUpperCase());
        }
    } catch (DuplicateAnnotationException e) {
        throw new DuplicateAnnotationException(e.getMessageWithOutContext() + " for the same Stream " +
                streamDefinition.getId(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(),
                siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
    }
    isTraceEnabled = log.isTraceEnabled();
}
 
Example 2
Source File: PartitionRuntimeImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public PartitionRuntimeImpl(ConcurrentMap<String, AbstractDefinition> streamDefinitionMap,
                            ConcurrentMap<String, AbstractDefinition> windowDefinitionMap,
                            ConcurrentMap<String, StreamJunction> streamJunctionMap,
                            Partition partition, int partitionIndex, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    if (partition.getPartitionTypeMap().isEmpty()) {
        throw new SiddhiAppCreationException("Partition must have at least one partition executor. " +
                "But found none.");
    }
    try {
        Element element = AnnotationHelper.getAnnotationElement("info", "name",
                partition.getAnnotations());
        if (element != null) {
            this.partitionName = element.getValue();
        }
    } catch (DuplicateAnnotationException e) {
        throw new DuplicateAnnotationException(e.getMessageWithOutContext() + " for the same Query " +
                partition.toString(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(),
                siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
    }
    if (partitionName == null) {
        this.partitionName = "partition_" + partitionIndex;
    }

    Annotation purge = AnnotationHelper.getAnnotation(SiddhiConstants.NAMESPACE_PURGE, partition.getAnnotations());
    if (purge != null) {
        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE) != null) {
            String purgeEnable = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE);
            if (!("true".equalsIgnoreCase(purgeEnable) || "false".equalsIgnoreCase(purgeEnable))) {
                throw new SiddhiAppCreationException("Invalid value for enable: " + purgeEnable + "." +
                        " Please use 'true' or 'false'");
            } else {
                purgingEnabled = Boolean.parseBoolean(purgeEnable);
            }
        } else {
            throw new SiddhiAppCreationException("Annotation @" + SiddhiConstants.NAMESPACE_PURGE +
                    " is missing element '" + SiddhiConstants.ANNOTATION_ELEMENT_ENABLE + "'");
        }
        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD) != null) {
            String purgeIdle = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD);
            purgeIdlePeriod = Expression.Time.timeToLong(purgeIdle);

        } else {
            throw new SiddhiAppCreationException("Annotation @" + SiddhiConstants.NAMESPACE_PURGE +
                    " is missing element '" + SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD + "'");
        }

        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL) != null) {
            String interval = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL);
            purgeExecutionInterval = Expression.Time.timeToLong(interval);
        }
    }
    this.partition = partition;
    this.streamDefinitionMap = streamDefinitionMap;
    this.windowDefinitionMap = windowDefinitionMap;
    this.streamJunctionMap = streamJunctionMap;

    this.stateHolder = siddhiAppContext.generateStateHolder(partitionName, () -> new PartitionState());
}
 
Example 3
Source File: ExceptionUtil.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public static void populateQueryContext(Throwable t, SiddhiElement siddhiElement,
                                        SiddhiAppContext siddhiAppContext,
                                        SiddhiQueryContext siddhiQueryContext) {
    String siddhiAppString = null;
    if (siddhiQueryContext instanceof SiddhiOnDemandQueryContext &&
            ((SiddhiOnDemandQueryContext) siddhiQueryContext).getOnDemandQueryString() != null) {
        siddhiAppString = ((SiddhiOnDemandQueryContext) siddhiQueryContext).getOnDemandQueryString();
    } else if (siddhiAppContext != null) {
        siddhiAppString = siddhiAppContext.getSiddhiAppString();
    }

    if (siddhiElement != null) {
        if (siddhiAppContext != null) {
            if (t instanceof SiddhiAppContextException) {
                ((SiddhiAppContextException) t).setQueryContextIndexIfAbsent(
                        siddhiElement.getQueryContextStartIndex(),
                        siddhiElement.getQueryContextEndIndex(), siddhiAppContext.getName(),
                        siddhiAppString);
            } else {
                throw new SiddhiAppCreationException(t.getMessage(), t, siddhiElement.getQueryContextStartIndex(),
                        siddhiElement.getQueryContextEndIndex(), siddhiAppContext.getName(),
                        siddhiAppString);
            }
        } else {
            if (t instanceof SiddhiAppContextException) {
                ((SiddhiAppContextException) t).setQueryContextIndexIfAbsent(
                        siddhiElement.getQueryContextStartIndex(),
                        siddhiElement.getQueryContextEndIndex(), null, null);
            } else {
                throw new SiddhiAppCreationException(t.getMessage(), t, siddhiElement.getQueryContextStartIndex(),
                        siddhiElement.getQueryContextEndIndex(), null, null);
            }
        }
    } else {
        if (siddhiAppContext != null) {
            if (t instanceof SiddhiAppContextException) {
                ((SiddhiAppContextException) t).setQueryContextIndexIfAbsent(
                        null, null, siddhiAppContext.getName(),
                        siddhiAppString);
            } else {
                throw new SiddhiAppCreationException(t.getMessage(), t, null, null, siddhiAppContext.getName(),
                        siddhiAppString);
            }
        } else {
            if (!(t instanceof SiddhiAppContextException)) {
                throw new SiddhiAppCreationException(t.getMessage(), t, null, null, null, null);
            }
        }
    }
}