io.siddhi.core.stream.input.source.SourceEventListener Java Examples

The following examples show how to use io.siddhi.core.stream.input.source.SourceEventListener. 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: TestTrpInMemorySource.java    From siddhi-map-json with Apache License 2.0 5 votes vote down vote up
@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 #2
Source File: KafkaMultiDCSource.java    From siddhi-io-kafka with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: SourceSynchronizer.java    From siddhi-io-kafka with Apache License 2.0 5 votes vote down vote up
public SourceSynchronizer(SourceEventListener eventListener, String[] bootstrapServers, int maxBufferSize,
                          int bufferFlushInterval) {
    this.eventListener = eventListener;
    this.bootstrapServers[0] = bootstrapServers[0];
    this.bootstrapServers[1] = bootstrapServers[1];
    this.maxBufferSize = maxBufferSize;
    this.bufferInterval = bufferFlushInterval;

    perSourceReceivedSeqNo.put(bootstrapServers[0], -1L);
    perSourceReceivedSeqNo.put(bootstrapServers[1], -1L);
}
 
Example #4
Source File: KafkaSource.java    From siddhi-io-kafka with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: KafkaConsumerThread.java    From siddhi-io-kafka with Apache License 2.0 5 votes vote down vote up
KafkaConsumerThread(SourceEventListener sourceEventListener, String[] topics, String[] partitions,
                    Properties props, boolean isPartitionWiseThreading, boolean isBinaryMessage,
                    boolean enableOffsetCommit, boolean enableAsyncCommit) {
    this.consumer = new KafkaConsumer<>(props);
    this.sourceEventListener = sourceEventListener;
    this.topics = topics;
    this.partitions = partitions;
    this.isPartitionWiseThreading = isPartitionWiseThreading;
    this.isBinaryMessage = isBinaryMessage;
    this.enableOffsetCommit = enableOffsetCommit;
    this.enableAutoCommit = Boolean.parseBoolean(props.getProperty(ADAPTOR_ENABLE_AUTO_COMMIT, "true"));
    this.consumerThreadId = buildId();
    this.enableAsyncCommit = enableAsyncCommit;
    lock = new ReentrantLock();
    condition = lock.newCondition();
    if (null != partitions) {
        for (String topic : topics) {
            for (String partition1 : partitions) {
                TopicPartition partition = new TopicPartition(topic, Integer.parseInt(partition1));
                LOG.info("Adding partition " + partition1 + " for topic: " + topic);
                partitionsList.add(partition);
            }
            LOG.info("Adding partitions " + Arrays.toString(partitions) + " for topic: " + topic);
            consumer.assign(partitionsList);
        }
    } else {
        consumer.subscribe(Arrays.asList(topics));
    }
    consumerClosed = false;
    LOG.info("Subscribed for topics: " + Arrays.toString(topics));
}
 
Example #6
Source File: TestTrpInMemorySource.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: TestDepInMemorySource.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@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;
}