/** * Provide the parallelism count for pass-through query. In case of multiple user given values, * lowest one will be selected. Default parallelism value would be 1. * * @param annotation Source annotation * @return Parallelism count for pass-through query */ private int getSourceParallelism(Annotation annotation) { Set<Integer> parallelismSet = new HashSet<>(); List<Annotation> distAnnotations = annotation.getAnnotations( SiddhiTopologyCreatorConstants.DISTRIBUTED_IDENTIFIER); if (distAnnotations.size() > 0) { for (Annotation distAnnotation : distAnnotations) { if (distAnnotation.getElement(SiddhiTopologyCreatorConstants.PARALLEL_IDENTIFIER) != null) { parallelismSet.add(Integer.valueOf(distAnnotation.getElement( SiddhiTopologyCreatorConstants.PARALLEL_IDENTIFIER))); } else { return SiddhiTopologyCreatorConstants.DEFAULT_PARALLEL; } } } else { return SiddhiTopologyCreatorConstants.DEFAULT_PARALLEL; } return parallelismSet.stream().min(Comparator.comparing(Integer::intValue)).get(); } }
/** * Generates AnnotationConfig String for the given Siddhi Annotation * @param annotation Siddhi Annotation * @return String representing the Annotation */ public String generateAnnotationConfig(Annotation annotation) { StringBuilder annotationConfig = new StringBuilder(); annotationConfig.append("@"); annotationConfig.append(annotation.getName()); annotationConfig.append("("); List<String> annotationMembers = new ArrayList<>(); for (Element element : annotation.getElements()) { annotationMembers.add(element.toString()); } for (Annotation innerAnnotation : annotation.getAnnotations()) { annotationMembers.add(generateAnnotationConfig(innerAnnotation)); } annotationConfig.append(String.join(", ", annotationMembers)); annotationConfig.append(")"); preserveCodeSegment(annotation); return annotationConfig.toString(); }
protected void init(StreamDefinition streamDefinition, OptionHolder optionHolder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.siddhiAppContext = siddhiAppContext; uriOption = optionHolder.validateAndGetOption(Constants.FILE_URI); String append = optionHolder.validateAndGetStaticValue(Constants.APPEND, Constants.TRUE); properties = new HashMap<>(); properties.put(Constants.ACTION, Constants.WRITE); if (Constants.TRUE.equalsIgnoreCase(append)) { properties.put(Constants.APPEND, append); } String mapType = streamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements().get(0) .getValue(); addEventSeparator = optionHolder.isOptionExists(Constants.ADD_EVENT_SEPARATOR) ? Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(Constants.ADD_EVENT_SEPARATOR)) : !mapType.equalsIgnoreCase("csv"); }
/** * Generates config for a Mapper * @param mapAnnotation Siddhi annotation that contains details of a Siddhi Mapper * @return MapperConfig object * @throws DesignGenerationException Error while generating MapperConfig */ private MapperConfig generateMapperConfig(Annotation mapAnnotation) throws DesignGenerationException { String type = null; List<String> options = new ArrayList<>(); for (Element element : mapAnnotation.getElements()) { if (element.getKey().equalsIgnoreCase(TYPE)) { type = element.getValue(); } else { options.add(element.toString()); } } if (type == null) { throw new DesignGenerationException("Unable to find 'type' of the mapper"); } MapperPayloadOrAttribute payloadOrAttribute = null; if (!mapAnnotation.getAnnotations().isEmpty()) { payloadOrAttribute = generateMapperPayloadOrAttributes(mapAnnotation.getAnnotations().get(0)); } MapperConfig mapperConfig = new MapperConfig(type, options, payloadOrAttribute); preserveAndBindCodeSegment(mapAnnotation, mapperConfig); return mapperConfig; }
/** * The initialization method for {@link Sink}, which will be called before other methods and validate * the all configuration and getting the intial values. * * @param outputStreamDefinition containing stream definition bind to the {@link Sink} * @param optionHolder Option holder containing static and dynamic configuration related * to the {@link Sink} * @param configReader to read the sink related system configuration. * @param siddhiAppContext the context of the {@link org.wso2.siddhi.query.api.SiddhiApp} used to * get siddhi related utilty functions. */ @Override protected void init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { //read configurations this.messageIdOption = optionHolder.validateAndGetOption(HttpConstants.MESSAGE_ID); this.sourceId = optionHolder.validateAndGetStaticValue(HttpConstants.SOURCE_ID); this.httpHeaderOption = optionHolder.getOrCreateOption(HttpConstants.HEADERS, HttpConstants.DEFAULT_HEADER); this.mapType = outputStreamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements().get(0) .getValue(); }
for (Element el : streamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements()) { if (el.getKey().contains(REGULAR_EXPRESSION_GROUP)) { regexGroupMap.put(el.getKey()
for (Annotation sourceOrSinkAnnotation : sourceOrSinkAndConnectedElement.getKey().getAnnotations()) { if (MAP.equalsIgnoreCase(sourceOrSinkAnnotation.getName())) { map = generateMapperConfig(sourceOrSinkAnnotation);
this.siddhiAppContext = siddhiAppContext; this.streamID = siddhiAppContext.getName() + PORT_HOST_SEPARATOR + outputStreamDefinition.toString(); this.mapType = outputStreamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements().get(0) .getValue(); this.publisherURLOption = optionHolder.validateAndGetOption(HttpConstants.PUBLISHER_URL);