io.siddhi.core.util.transport.OptionHolder Java Examples
The following examples show how to use
io.siddhi.core.util.transport.OptionHolder.
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: JsonSinkMapper.java From siddhi-map-json with Apache License 2.0 | 6 votes |
@Override public void mapAndSend(Event[] events, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) { StringBuilder sb = new StringBuilder(); if (payloadTemplateBuilderMap == null) { String jsonString = constructJsonForDefaultMapping(events); sb.append(jsonString); } else { sb.append(constructJsonForCustomMapping(events, payloadTemplateBuilderMap.get(payloadTemplateBuilderMap.keySet().iterator().next()))); } if (!isJsonValidationEnabled) { sinkListener.publish(sb.toString()); } else if (isValidJson(sb.toString())) { sinkListener.publish(sb.toString()); } else { log.error("Invalid json string : " + sb.toString() + ". Hence dropping the message."); } }
Example #2
Source File: PartitionedDistributionStrategy.java From siddhi with Apache License 2.0 | 6 votes |
/** * Initialize the Distribution strategy with the information it will require to make decisions. * * @param streamDefinition The stream attached to the sink this DistributionStrategy is used in * @param transportOptionHolder Sink options of the sink which uses this DistributionStrategy * @param destinationOptionHolders The list of options under @destination of the relevant sink. * @param configReader This hold the {@link PartitionedDistributionStrategy} configuration reader. */ @Override public void init(StreamDefinition streamDefinition, OptionHolder transportOptionHolder, OptionHolder distributionOptionHolder, List<OptionHolder> destinationOptionHolders, ConfigReader configReader) { totalDestinationCount = destinationOptionHolders.size(); String partitionKey = distributionOptionHolder.validateAndGetStaticValue(SiddhiConstants .PARTITION_KEY_FIELD_KEY); if (partitionKey == null || partitionKey.isEmpty()) { throw new SiddhiAppValidationException("PartitionKey is required for partitioned distribution " + "strategy."); } try { int partitionKeyFieldPosition = streamDefinition.getAttributePosition(partitionKey); partitionOption = new Option(partitionKeyFieldPosition); } catch (AttributeNotExistException e) { throw new SiddhiAppValidationException("Could not find partition key attribute", e); } }
Example #3
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 6 votes |
private static List<OptionHolder> createDestinationOptionHolders(Annotation distributionAnnotation, StreamDefinition streamDefinition, Sink clientTransport, SiddhiAppContext siddhiAppContext) { io.siddhi.annotation.Extension sinkExt = clientTransport.getClass().getAnnotation(io.siddhi.annotation.Extension.class); List<OptionHolder> destinationOptHolders = new ArrayList<>(); distributionAnnotation.getAnnotations().stream() .filter(annotation -> annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_DESTINATION)) .forEach(destinationAnnotation -> destinationOptHolders.add(constructOptionHolder(streamDefinition, updateAnnotationRef(destinationAnnotation, SiddhiConstants.ANNOTATION_DESTINATION, siddhiAppContext), sinkExt, clientTransport.getSupportedDynamicOptions(), true))); return destinationOptHolders; }
Example #4
Source File: JsonSinkMapper.java From siddhi-map-json with Apache License 2.0 | 6 votes |
/** * Initialize the mapper and the mapping configurations. * * @param streamDefinition The stream definition * @param optionHolder Option holder containing static and dynamic options * @param payloadTemplateBuilderMap Unmapped list of payloads for reference */ @Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, ConfigReader mapperConfigReader, SiddhiAppContext siddhiAppContext) { this.attributeNameArray = streamDefinition.getAttributeNameArray(); this.enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, null); this.isJsonValidationEnabled = Boolean.parseBoolean(optionHolder .validateAndGetStaticValue(JSON_VALIDATION_IDENTIFIER, "false")); //if @payload() is added there must be at least 1 element in it, otherwise a SiddhiParserException raised if (payloadTemplateBuilderMap != null && payloadTemplateBuilderMap.size() != 1) { throw new SiddhiAppCreationException("Json sink-mapper does not support multiple @payload mappings, " + "error at the mapper of '" + streamDefinition.getId() + "'"); } if (payloadTemplateBuilderMap != null && payloadTemplateBuilderMap.get(payloadTemplateBuilderMap.keySet().iterator().next()).isObjectMessage()) { throw new SiddhiAppCreationException("Json sink-mapper does not support object @payload mappings, " + "error at the mapper of '" + streamDefinition.getId() + "'"); } }
Example #5
Source File: Sink.java From siddhi with Apache License 2.0 | 6 votes |
public final void initOnlyTransport(StreamDefinition streamDefinition, OptionHolder transportOptionHolder, ConfigReader sinkConfigReader, String type, DistributedTransport.ConnectionCallback connectionCallback, Map<String, String> deploymentProperties, SiddhiAppContext siddhiAppContext) { this.type = type; this.streamDefinition = streamDefinition; this.connectionCallback = connectionCallback; this.siddhiAppContext = siddhiAppContext; init(streamDefinition, transportOptionHolder, sinkConfigReader, siddhiAppContext); scheduledExecutorService = siddhiAppContext.getScheduledExecutorService(); serviceDeploymentInfo = exposeServiceDeploymentInfo(); if (serviceDeploymentInfo != null) { serviceDeploymentInfo.addDeploymentProperties(deploymentProperties); } else if (!deploymentProperties.isEmpty()) { throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties + "' are defined for sink '" + type + "' which does not expose a service"); } }
Example #6
Source File: TestSinkOptionSinkMapper.java From siddhi with Apache License 2.0 | 6 votes |
@Override public void mapAndSend(Event[] events, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) { for (Event event : events) { String topic = topicOption.getValue(event); if (mapType) { for (TemplateBuilder templateBuilder : payloadTemplateBuilderMap.values()) { sinkListener.publish(new Event(System.currentTimeMillis(), new Object[]{sinkType, topic, templateBuilder.isObjectMessage() + "-" + templateBuilder.getType().toString()})); } } else { //to change the topic as topic is picked from the original event event.getData()[0] = sinkType; sinkListener.publish(new Event(System.currentTimeMillis(), new Object[]{sinkType, topic, prefix})); } } }
Example #7
Source File: Source.java From siddhi with Apache License 2.0 | 5 votes |
public final void init(String sourceType, OptionHolder transportOptionHolder, SourceMapper sourceMapper, String[] transportPropertyNames, ConfigReader configReader, String mapType, OptionHolder mapOptionHolder, List<AttributeMapping> attributeMappings, List<AttributeMapping> transportMappings, ConfigReader mapperConfigReader, SourceHandler sourceHandler, StreamDefinition streamDefinition, Map<String, String> deploymentProperties, SiddhiAppContext siddhiAppContext) { this.type = sourceType; sourceMapper.init(streamDefinition, mapType, mapOptionHolder, attributeMappings, sourceType, (this instanceof SourceSyncCallback) ? (SourceSyncCallback) this : null, transportMappings, sourceHandler, transportOptionHolder, mapperConfigReader, siddhiAppContext); this.mapper = sourceMapper; this.streamDefinition = streamDefinition; this.siddhiAppContext = siddhiAppContext; StateFactory<S> stateFactory = init(sourceMapper, transportOptionHolder, transportPropertyNames, configReader, siddhiAppContext); stateHolder = siddhiAppContext.generateStateHolder(streamDefinition.getId() + "-" + this.getClass().getName(), stateFactory); scheduledExecutorService = siddhiAppContext.getScheduledExecutorService(); serviceDeploymentInfo = exposeServiceDeploymentInfo(); if (serviceDeploymentInfo != null) { serviceDeploymentInfo.addDeploymentProperties(deploymentProperties); } else if (!deploymentProperties.isEmpty()) { throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties + "' are defined for source '" + sourceType + "' which does not expose a service"); } }
Example #8
Source File: SourceMapper.java From siddhi with Apache License 2.0 | 5 votes |
public final void init(StreamDefinition streamDefinition, String mapType, OptionHolder mapOptionHolder, List<AttributeMapping> attributeMappings, String sourceType, SourceSyncCallback sourceSyncCallback, List<AttributeMapping> transportMappings, SourceHandler sourceHandler, OptionHolder sourceOptionHolder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamDefinition = streamDefinition; this.mapType = mapType; this.sourceType = sourceType; this.transportMappings = transportMappings; this.sourceOptionHolder = sourceOptionHolder; if (sourceHandler != null) { sourceHandler.initSourceHandler(siddhiAppContext.getName(), sourceSyncCallback, streamDefinition, siddhiAppContext); } this.sourceHandler = sourceHandler; this.siddhiAppContext = siddhiAppContext; if (siddhiAppContext.getStatisticsManager() != null) { this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext, streamDefinition.getId(), SiddhiConstants.METRIC_INFIX_SOURCES, sourceType); this.mapperLatencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext, streamDefinition.getId(), SiddhiConstants.METRIC_INFIX_SOURCE_MAPPERS, sourceType + SiddhiConstants.METRIC_DELIMITER + mapType); } if (configReader != null && configReader.getAllConfigs().size() != 0) { if (configReader.getAllConfigs().containsKey(ENABLE_EVENT_COUNT_LOGGER) && configReader.getAllConfigs().get(ENABLE_EVENT_COUNT_LOGGER).toLowerCase().equals(TRUE)) { logEventCount = true; this.receivedEventCounter = new ReceivedEventCounter(); if (configReader.getAllConfigs().containsKey(LOGGING_DURATION)) { loggingDuration = Integer.parseInt(configReader.getAllConfigs().get(LOGGING_DURATION)); } receivedEventCounter.init(siddhiAppContext, streamDefinition, loggingDuration); } } init(streamDefinition, mapOptionHolder, attributeMappings, configReader, siddhiAppContext); }
Example #9
Source File: InMemorySource.java From siddhi with Apache License 2.0 | 5 votes |
@Override public StateFactory<State> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.sourceEventListener = sourceEventListener; String topic = optionHolder.validateAndGetStaticValue(TOPIC_KEY, "input inMemory source"); this.subscriber = new InMemoryBroker.Subscriber() { @Override public void onMessage(Object event) { if (paused) { pauseLock.lock(); try { while (paused) { unpaused.await(); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } finally { pauseLock.unlock(); } } sourceEventListener.onEvent(event, null); } @Override public String getTopic() { return topic; } }; return null; }
Example #10
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 5 votes |
private static OutputGroupDeterminer constructOutputGroupDeterminer(OptionHolder transportOptHolder, OptionHolder distributedOptHolder, StreamDefinition streamDef, int destinationCount) { OutputGroupDeterminer groupDeterminer = null; if (distributedOptHolder != null) { String strategy = distributedOptHolder.validateAndGetStaticValue(SiddhiConstants.DISTRIBUTION_STRATEGY_KEY); if (strategy.equalsIgnoreCase(SiddhiConstants.DISTRIBUTION_STRATEGY_PARTITIONED)) { String partitionKeyField = distributedOptHolder.validateAndGetStaticValue(SiddhiConstants .PARTITION_KEY_FIELD_KEY); int partitioningFieldIndex = streamDef.getAttributePosition(partitionKeyField); groupDeterminer = new PartitionedGroupDeterminer(partitioningFieldIndex, destinationCount); } } if (groupDeterminer == null) { List<Option> dynamicTransportOptions = new ArrayList<Option>(transportOptHolder.getDynamicOptionsKeys() .size()); for (String option : transportOptHolder.getDynamicOptionsKeys()) { dynamicTransportOptions.add(transportOptHolder.validateAndGetOption(option)); } if (dynamicTransportOptions.size() > 0) { groupDeterminer = new DynamicOptionGroupDeterminer(dynamicTransportOptions); } } return groupDeterminer; }
Example #11
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 5 votes |
private static OptionHolder constructOptionHolder(StreamDefinition streamDefinition, Annotation annotation, io.siddhi.annotation.Extension extension, String[] supportedDynamicOptions, boolean supportDeploymentOptions) { List<String> supportedDynamicOptionList = new ArrayList<>(); if (supportedDynamicOptions != null) { supportedDynamicOptionList = Arrays.asList(supportedDynamicOptions); } Map<String, String> options = new HashMap<>(); Map<String, String> dynamicOptions = new HashMap<>(); for (Element element : annotation.getElements()) { if (element.getKey().startsWith("dep:")) { if (!supportDeploymentOptions) { throw new SiddhiAppCreationException("DeploymentOption is not supported by '" + extension.namespace() + ":" + extension.name() + "', but a deployment property '" + element.getKey() + "' is configured", annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex()); } } if (Pattern.matches("(.*?)\\{\\{.*?\\}\\}(.*?)", element.getValue())) { if (supportedDynamicOptionList.contains(element.getKey())) { dynamicOptions.put(element.getKey(), element.getValue()); } else { throw new SiddhiAppCreationException("'" + element.getKey() + "' is not a supported " + "DynamicOption " + "for the Extension '" + extension.namespace() + ":" + extension.name() + "', it only supports following as its DynamicOptions: " + supportedDynamicOptionList, annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex()); } } else { options.put(element.getKey(), element.getValue()); } } return new OptionHolder(streamDefinition, options, dynamicOptions, extension); }
Example #12
Source File: TestAsyncInMemory.java From siddhi with Apache License 2.0 | 5 votes |
@Override protected StateFactory<State> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { this.siddhiAppContext = siddhiAppContext; optionHolder.validateAndGetOption(TOPIC_KEY); super.init(outputStreamDefinition, optionHolder, sinkConfigReader, siddhiAppContext); return null; }
Example #13
Source File: LogSink.java From siddhi with Apache License 2.0 | 5 votes |
@Override protected StateFactory<State> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { String defaultPrefix = siddhiAppContext.getName() + " : " + outputStreamDefinition.getId(); logPrefix = optionHolder.validateAndGetStaticValue(PREFIX, defaultPrefix); logPriority = LogPriority.valueOf(optionHolder.validateAndGetStaticValue(PRIORITY, "INFO") .toUpperCase()); return null; }
Example #14
Source File: TestFailingInMemorySink2.java From siddhi with Apache License 2.0 | 5 votes |
@Override protected StateFactory<State> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { optionHolder.validateAndGetOption(TOPIC_KEY); optionHolder.validateAndGetOption(TEST_KEY); super.init(outputStreamDefinition, optionHolder, sinkConfigReader, siddhiAppContext); return null; }
Example #15
Source File: TestSinkOptionSinkMapper.java From siddhi with Apache License 2.0 | 5 votes |
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, ConfigReader mapperConfigReader, SiddhiAppContext siddhiAppContext) { topicOption = sinkOptionHolder.validateAndGetOption("topic"); prefix = sinkOptionHolder.validateAndGetStaticValue("prefix"); mapType = Boolean.valueOf(optionHolder.validateAndGetStaticValue("mapType", "false")); }
Example #16
Source File: TestSinkOptionSinkMapper.java From siddhi with Apache License 2.0 | 5 votes |
@Override public void mapAndSend(Event event, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) { String topic = topicOption.getValue(event); if (mapType) { for (TemplateBuilder templateBuilder : payloadTemplateBuilderMap.values()) { sinkListener.publish(new Event(System.currentTimeMillis(), new Object[]{sinkType, topic, templateBuilder.isObjectMessage() + "-" + templateBuilder.getType().toString()})); } } else { //to change the topic as topic is picked from the original event event.getData()[0] = sinkType; sinkListener.publish(new Event(System.currentTimeMillis(), new Object[]{sinkType, topic, prefix})); } }
Example #17
Source File: TestTrpSourceMapper.java From siddhi with Apache License 2.0 | 5 votes |
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, List<AttributeMapping> attributeMappingList, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamDefinition = streamDefinition; this.optionHolder = optionHolder; this.attributeMappingList = attributeMappingList; this.configReader = configReader; this.siddhiAppContext = siddhiAppContext; }
Example #18
Source File: TestTrpInMemorySource.java From siddhi with Apache License 2.0 | 5 votes |
@Override public StateFactory<State> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { super.init(sourceEventListener, optionHolder, requestedTransportPropertyNames, configReader, siddhiAppContext); symbol = optionHolder.validateAndGetStaticValue("prop1"); price = optionHolder.validateAndGetStaticValue("prop2"); fail = optionHolder.validateAndGetStaticValue("fail", "false"); this.sourceEventListener = sourceEventListener; String topic = optionHolder.validateAndGetStaticValue(TOPIC_KEY, "input inMemory source"); this.subscriber = new InMemoryBroker.Subscriber() { @Override public void onMessage(Object event) { if (fail.equals("true")) { sourceEventListener.onEvent(event, new String[]{symbol}); } else { if (requestedTransportPropertyNames.length == 2 && requestedTransportPropertyNames[0].equals("symbol") && requestedTransportPropertyNames[1].equals("price")) { sourceEventListener.onEvent(event, new String[]{symbol, price}); } } } @Override public String getTopic() { return topic; } }; return null; }
Example #19
Source File: SinkMapper.java From siddhi with Apache License 2.0 | 5 votes |
public final void init(StreamDefinition streamDefinition, String type, OptionHolder mapOptionHolder, List<Element> unmappedPayloadList, Sink sink, ConfigReader mapperConfigReader, LatencyTracker mapperLatencyTracker, OptionHolder sinkOptionHolder, SiddhiAppContext siddhiAppContext) { this.mapperLatencyTracker = mapperLatencyTracker; this.siddhiAppContext = siddhiAppContext; sink.setTrpDynamicOptions(trpDynamicOptions); this.sinkListener = sink; this.sinkType = sink.getType(); this.sinkOptionHolder = sinkOptionHolder; this.optionHolder = mapOptionHolder; this.type = type; buildMapperTemplate(streamDefinition, unmappedPayloadList); init(streamDefinition, mapOptionHolder, templateBuilderMap, mapperConfigReader, siddhiAppContext); }
Example #20
Source File: TestDepInMemorySource.java From siddhi with Apache License 2.0 | 5 votes |
@Override public StateFactory<State> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { super.init(sourceEventListener, optionHolder, requestedTransportPropertyNames, configReader, siddhiAppContext); symbol = optionHolder.validateAndGetStaticValue("prop1"); price = optionHolder.validateAndGetStaticValue("prop2"); fail = optionHolder.validateAndGetStaticValue("fail", "false"); this.sourceEventListener = sourceEventListener; String topic = optionHolder.validateAndGetStaticValue(TOPIC_KEY, "input inMemory source"); this.subscriber = new InMemoryBroker.Subscriber() { @Override public void onMessage(Object event) { if (fail.equals("true")) { sourceEventListener.onEvent(event, new String[]{symbol}); } else { if (requestedTransportPropertyNames.length == 2 && requestedTransportPropertyNames[0].equals("symbol") && requestedTransportPropertyNames[1].equals("price")) { sourceEventListener.onEvent(event, new String[]{symbol, price}); } } } @Override public String getTopic() { return topic; } }; return null; }
Example #21
Source File: TestOptionInMemorySink.java From siddhi with Apache License 2.0 | 5 votes |
@Override protected StateFactory<State> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { topicPrefix = (String) siddhiAppContext.getAttributes().get("TopicPrefix"); topicOption = optionHolder.validateAndGetOption(TOPIC_KEY); return null; }
Example #22
Source File: KafkaSource.java From siddhi-io-kafka with Apache License 2.0 | 5 votes |
@Override public StateFactory<KafkaSourceState> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] strings, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.siddhiAppContext = siddhiAppContext; this.optionHolder = optionHolder; this.sourceEventListener = sourceEventListener; bootstrapServers = optionHolder.validateAndGetStaticValue(ADAPTOR_SUBSCRIBER_ZOOKEEPER_CONNECT_SERVERS); groupID = optionHolder.validateAndGetStaticValue(ADAPTOR_SUBSCRIBER_GROUP_ID); threadingOption = optionHolder.validateAndGetStaticValue(THREADING_OPTION); String partitionList = optionHolder.validateAndGetStaticValue(ADAPTOR_SUBSCRIBER_PARTITION_NO_LIST, null); partitions = (partitionList != null) ? partitionList.split(KafkaIOUtils.HEADER_SEPARATOR) : null; String topicList = optionHolder.validateAndGetStaticValue(ADAPTOR_SUBSCRIBER_TOPIC); topics = topicList.split(KafkaIOUtils.HEADER_SEPARATOR); seqEnabled = optionHolder.validateAndGetStaticValue(SEQ_ENABLED, "false").equalsIgnoreCase("true"); optionalConfigs = optionHolder.validateAndGetStaticValue(ADAPTOR_OPTIONAL_CONFIGURATION_PROPERTIES, null); isBinaryMessage = Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(IS_BINARY_MESSAGE, "false")); enableOffsetCommit = Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(ADAPTOR_ENABLE_OFFSET_COMMIT, "true")); enableAsyncCommit = Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(ADAPTOR_ENABLE_ASYNC_COMMIT, "true")); topicOffsetMapConfig = optionHolder.validateAndGetStaticValue(TOPIC_OFFSET_MAP, null); if (PARTITION_WISE.equals(threadingOption) && null == partitions) { throw new SiddhiAppValidationException("Threading option is selected as 'partition.wise' but " + "there are no partitions given"); } return () -> new KafkaSourceState(seqEnabled); }
Example #23
Source File: KafkaSink.java From siddhi-io-kafka with Apache License 2.0 | 5 votes |
@Override protected StateFactory<KafkaSinkState> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { bootstrapServers = optionHolder.validateAndGetStaticValue(KAFKA_BROKER_LIST); optionalConfigs = optionHolder.validateAndGetStaticValue(KAFKA_OPTIONAL_CONFIGURATION_PROPERTIES, null); topicOption = optionHolder.validateAndGetOption(KAFKA_PUBLISH_TOPIC); partitionOption = optionHolder.getOrCreateOption(KAFKA_PARTITION_NO, null); sequenceId = optionHolder.validateAndGetStaticValue(SEQ_ID, null); isBinaryMessage = Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(IS_BINARY_MESSAGE, "false")); isSequenced = sequenceId != null; keyOption = optionHolder.getOrCreateOption(KAFKA_MESSAGE_KEY, null); return () -> new KafkaSinkState(isSequenced); }
Example #24
Source File: KafkaMultiDCSource.java From siddhi-io-kafka with Apache License 2.0 | 5 votes |
private OptionHolder createOptionHolders(String server, OptionHolder originalOptionHolder) { Map<String, String> options = new HashMap<>(); options.put(KafkaSource.ADAPTOR_SUBSCRIBER_ZOOKEEPER_CONNECT_SERVERS, server); options.put(KafkaSource.ADAPTOR_SUBSCRIBER_GROUP_ID, UUID.randomUUID().toString()); options.put(KafkaSource.THREADING_OPTION, KafkaSource.SINGLE_THREADED); options.put(KafkaSource.SEQ_ENABLED, "false"); String partition = originalOptionHolder.validateAndGetStaticValue(KAFKA_PARTITION_NO, "0"); options.put(KafkaSource.ADAPTOR_SUBSCRIBER_PARTITION_NO_LIST, partition); String topic = originalOptionHolder.validateAndGetStaticValue(KAFKA_TOPIC); options.put(KafkaSource.ADAPTOR_SUBSCRIBER_TOPIC, topic); String optionalConfigs = originalOptionHolder.validateAndGetStaticValue( KafkaSource.ADAPTOR_OPTIONAL_CONFIGURATION_PROPERTIES, null); options.put(KafkaSource.ADAPTOR_OPTIONAL_CONFIGURATION_PROPERTIES, optionalConfigs); String isBinaryMessage = originalOptionHolder.validateAndGetStaticValue(KafkaSource.IS_BINARY_MESSAGE, "false"); options.put(KafkaSource.IS_BINARY_MESSAGE, isBinaryMessage); Extension extension = KafkaSource.class.getAnnotation(io.siddhi.annotation.Extension.class); OptionHolder holder = new OptionHolder(eventListener.getStreamDefinition(), options, new HashMap<>(), extension); return holder; }
Example #25
Source File: KafkaMultiDCSource.java From siddhi-io-kafka with Apache License 2.0 | 5 votes |
@Override public StateFactory<KafkaMultiDCSourceState> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] transportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.eventListener = sourceEventListener; String serverList = optionHolder.validateAndGetStaticValue(KafkaSource .ADAPTOR_SUBSCRIBER_ZOOKEEPER_CONNECT_SERVERS); boolean isBinaryMessage = Boolean.parseBoolean( optionHolder.validateAndGetStaticValue(KafkaSource.IS_BINARY_MESSAGE, "false")); bootstrapServers = serverList.split(","); if (bootstrapServers.length != 2) { throw new SiddhiAppValidationException("There should be two servers listed in " + "'bootstrap.servers' configuration to ensure fault tolerant kafka messaging."); } synchronizer = new SourceSynchronizer(sourceEventListener, bootstrapServers, 1000, 10); LOG.info("Initializing kafka source for bootstrap server :" + bootstrapServers[0]); Interceptor interceptor = new Interceptor(bootstrapServers[0], synchronizer, isBinaryMessage); OptionHolder options = createOptionHolders(bootstrapServers[0], optionHolder); KafkaSource source = new KafkaSource(); stateFactories.put(bootstrapServers[0], source.init(interceptor, options, transportPropertyNames, configReader, siddhiAppContext)); sources.put(bootstrapServers[0], source); LOG.info("Initializing kafka source for bootstrap server :" + bootstrapServers[1]); interceptor = new Interceptor(bootstrapServers[1], synchronizer, isBinaryMessage); options = createOptionHolders(bootstrapServers[1], optionHolder); source = new KafkaSource(); stateFactories.put(bootstrapServers[1], source.init(interceptor, options, transportPropertyNames, configReader, siddhiAppContext)); sources.put(bootstrapServers[1], source); return new KafkaMultiDCSourceStateFactory(stateFactories); }
Example #26
Source File: KafkaMultiDCSink.java From siddhi-io-kafka with Apache License 2.0 | 5 votes |
@Override protected StateFactory<KafkaSinkState> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { StateFactory<KafkaSinkState> stateStateFactory = super.init(outputStreamDefinition, optionHolder, sinkConfigReader, siddhiAppContext); topic = optionHolder.validateAndGetStaticValue(KAFKA_PUBLISH_TOPIC); partitionNo = Integer.parseInt(optionHolder.validateAndGetStaticValue(KAFKA_PARTITION_NO, "0")); if (bootstrapServers.split(",").length != 2) { throw new SiddhiAppValidationException("There should be two servers listed in 'bootstrap.servers' " + "configuration"); } return stateStateFactory; }
Example #27
Source File: TestTrpInMemorySource.java From siddhi-map-json with Apache License 2.0 | 5 votes |
@Override public StateFactory<State> init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { super.init(sourceEventListener, optionHolder, requestedTransportPropertyNames, configReader, siddhiAppContext); symbol = optionHolder.validateAndGetStaticValue("prop1"); price = optionHolder.validateAndGetStaticValue("prop2"); fail = optionHolder.validateAndGetStaticValue("fail", "false"); this.sourceEventListener = sourceEventListener; String topic = optionHolder.validateAndGetStaticValue(TOPIC_KEY, "input inMemory source"); this.subscriber = new InMemoryBroker.Subscriber() { @Override public void onMessage(Object event) { if (fail.equals("true")) { sourceEventListener.onEvent(event, new String[]{symbol}); } else { if (requestedTransportPropertyNames.length == 1 && requestedTransportPropertyNames[0].equals("symbol")) { sourceEventListener.onEvent(event, new String[]{symbol, price}); } } } @Override public String getTopic() { return topic; } }; return null; }
Example #28
Source File: JsonSourceMapper.java From siddhi-map-json with Apache License 2.0 | 5 votes |
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, List<AttributeMapping> attributeMappingList, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamDefinition = streamDefinition; this.streamAttributes = this.streamDefinition.getAttributeList(); this.streamAttributesSize = this.streamDefinition.getAttributeList().size(); this.failOnMissingAttribute = Boolean.parseBoolean(optionHolder. validateAndGetStaticValue(FAIL_ON_MISSING_ATTRIBUTE_IDENTIFIER, "true")); this.factory = new JsonFactory(); if (attributeMappingList != null && attributeMappingList.size() > 0) { this.mappingPositions = new MappingPositionData[attributeMappingList.size()]; isCustomMappingEnabled = true; enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, DEFAULT_ENCLOSING_ELEMENT); for (int i = 0; i < attributeMappingList.size(); i++) { AttributeMapping attributeMapping = attributeMappingList.get(i); String attributeName = attributeMapping.getName(); int position = this.streamDefinition.getAttributePosition(attributeName); this.mappingPositions[i] = new MappingPositionData(position, attributeMapping.getMapping()); } } else { this.mappingPositions = new MappingPositionData[streamAttributesSize]; for (int i = 0; i < streamAttributesSize; i++) { this.mappingPositions[i] = new MappingPositionData(i, DEFAULT_JSON_MAPPING_PREFIX + this .streamDefinition.getAttributeList().get(i).getName()); } } }
Example #29
Source File: JsonSinkMapper.java From siddhi-map-json with Apache License 2.0 | 5 votes |
@Override public void mapAndSend(Event event, OptionHolder optionHolder, Map<String, TemplateBuilder> payloadTemplateBuilderMap, SinkListener sinkListener) { StringBuilder sb = null; if (payloadTemplateBuilderMap == null) { String jsonString = constructJsonForDefaultMapping(event); if (jsonString != null) { sb = new StringBuilder(); sb.append(jsonString); } } else { sb = new StringBuilder(); sb.append(constructJsonForCustomMapping(event, payloadTemplateBuilderMap.get(payloadTemplateBuilderMap.keySet().iterator().next()))); } if (sb != null) { if (!isJsonValidationEnabled) { sinkListener.publish(sb.toString()); } else if (isValidJson(sb.toString())) { sinkListener.publish(sb.toString()); } else { log.error("Invalid json string : " + sb.toString() + ". Hence dropping the message."); } } }
Example #30
Source File: DefinitionParserHelper.java From siddhi with Apache License 2.0 | 4 votes |
public static void addEventSource(StreamDefinition streamDefinition, ConcurrentMap<String, List<Source>> eventSourceMap, SiddhiAppContext siddhiAppContext) { for (Annotation sourceAnnotation : streamDefinition.getAnnotations()) { if (SiddhiConstants.ANNOTATION_SOURCE.equalsIgnoreCase(sourceAnnotation.getName())) { try { sourceAnnotation = updateAnnotationRef(sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE, siddhiAppContext); Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sourceAnnotation.getAnnotations()); if (mapAnnotation == null) { mapAnnotation = Annotation.annotation(SiddhiConstants.ANNOTATION_MAP).element(SiddhiConstants .ANNOTATION_ELEMENT_TYPE, "passThrough"); } final String sourceType = sourceAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE); if (sourceType == null) { throw new SiddhiAppCreationException( "Attribute 'type' does not exist for annotation '" + sourceAnnotation + "'", sourceAnnotation, siddhiAppContext); } final String mapType = mapAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE); if (mapType == null) { throw new SiddhiAppCreationException( "Attribute 'type' does not exist for annotation '" + mapAnnotation + "'", mapAnnotation, siddhiAppContext); } SourceHandlerManager sourceHandlerManager = siddhiAppContext.getSiddhiContext(). getSourceHandlerManager(); SourceHandler sourceHandler = null; if (sourceHandlerManager != null) { sourceHandler = sourceHandlerManager.generateSourceHandler(sourceType); } // load input transport extension Extension sourceExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SOURCE, sourceType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE); Source source = (Source) SiddhiClassLoader.loadExtensionImplementation(sourceExtension, SourceExecutorExtensionHolder.getInstance(siddhiAppContext)); ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager() .generateConfigReader(sourceExtension.getNamespace(), sourceExtension.getName()); // load input mapper extension Extension mapperExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_MAP, mapType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE_MAPPER); SourceMapper sourceMapper = (SourceMapper) SiddhiClassLoader.loadExtensionImplementation( mapperExtension, SourceMapperExecutorExtensionHolder.getInstance(siddhiAppContext)); ConfigReader mapperConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager() .generateConfigReader(mapperExtension.getNamespace(), mapperExtension.getName()); validateSourceMapperCompatibility(streamDefinition, sourceType, mapType, source, sourceMapper, sourceAnnotation); io.siddhi.annotation.Extension sourceExt = source.getClass().getAnnotation(io.siddhi.annotation.Extension.class); OptionHolder sourceOptionHolder = constructOptionHolder(streamDefinition, sourceAnnotation, sourceExt, null, true); Map<String, String> deploymentProperties = createDeploymentProperties(sourceAnnotation, sourceExt); OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sourceMapper.getClass().getAnnotation(io.siddhi.annotation.Extension.class), null, false); AttributesHolder attributesHolder = getAttributeMappings(mapAnnotation, mapType, streamDefinition); String[] transportPropertyNames = getTransportPropertyNames(attributesHolder); source.init(sourceType, sourceOptionHolder, sourceMapper, transportPropertyNames, configReader, mapType, mapOptionHolder, attributesHolder.payloadMappings, attributesHolder.transportMappings, mapperConfigReader, sourceHandler, streamDefinition, deploymentProperties, siddhiAppContext); if (sourceHandlerManager != null) { sourceHandlerManager.registerSourceHandler(sourceHandler.getId(), sourceHandler); } List<Source> eventSources = eventSourceMap.get(streamDefinition.getId()); if (eventSources == null) { eventSources = new ArrayList<>(); eventSources.add(source); eventSourceMap.put(streamDefinition.getId(), eventSources); } else { eventSources.add(source); } } catch (Throwable t) { ExceptionUtil.populateQueryContext(t, sourceAnnotation, siddhiAppContext); throw t; } } } }