luchunliang commented on a change in pull request #2186: URL: https://github.com/apache/incubator-inlong/pull/2186#discussion_r787431021
########## File path: inlong-sdk/sort-sdk/src/main/java/org/apache/inlong/sdk/sort/impl/tube/InLongTubeFetcherImpl.java ########## @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.inlong.sdk.sort.impl.tube; + +import com.google.common.base.Splitter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; +import java.util.concurrent.TimeUnit; +import org.apache.inlong.sdk.sort.api.ClientContext; +import org.apache.inlong.sdk.sort.api.InLongTopicFetcher; +import org.apache.inlong.sdk.sort.api.SysConstants; +import org.apache.inlong.sdk.sort.entity.InLongMessage; +import org.apache.inlong.sdk.sort.entity.InLongTopic; +import org.apache.inlong.sdk.sort.entity.MessageRecord; +import org.apache.inlong.sdk.sort.util.StringUtil; +import org.apache.inlong.tubemq.client.config.ConsumerConfig; +import org.apache.inlong.tubemq.client.config.TubeClientConfig; +import org.apache.inlong.tubemq.client.consumer.ConsumerResult; +import org.apache.inlong.tubemq.client.consumer.PullMessageConsumer; +import org.apache.inlong.tubemq.corebase.Message; +import org.apache.inlong.tubemq.corebase.TErrCodeConstants; +import org.apache.pulsar.shade.org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InLongTubeFetcherImpl extends InLongTopicFetcher { + + private static final Logger LOG = LoggerFactory.getLogger(InLongTubeFetcherImpl.class); + private PullMessageConsumer messageConsumer; + + private volatile boolean stopConsume = false; + private volatile Thread fetchThread; + private long sleepTime = 0L; + private int emptyPollTimes = 0; + + public InLongTubeFetcherImpl(InLongTopic inLongTopic, ClientContext context) { + super(inLongTopic, context); + } + + @Override + public boolean init(Object object) { + TubeConsumerCreater tubeConsumerCreater = (TubeConsumerCreater) object; + TubeClientConfig tubeClientConfig = tubeConsumerCreater.getTubeClientConfig(); + try { + ConsumerConfig consumerConfig = new ConsumerConfig(tubeClientConfig.getMasterInfo(), + context.getConfig().getSortTaskId()); + + messageConsumer = tubeConsumerCreater.getMessageSessionFactory().createPullConsumer(consumerConfig); + if (messageConsumer != null) { + TreeSet<String> filters = null; + if (inLongTopic.getProperties() != null && inLongTopic.getProperties().containsKey( + SysConstants.TUBE_TOPIC_FILTER_KEY)) { + filters = (TreeSet<String>) inLongTopic.getProperties().get(SysConstants.TUBE_TOPIC_FILTER_KEY); + + } + messageConsumer.subscribe(inLongTopic.getTopic(), filters); + messageConsumer.completeSubscribe(); + + String threadName = "sort_sdk_fetch_thread_" + StringUtil + .formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"); + this.fetchThread = new Thread(new Fetcher(), threadName); + this.fetchThread.start(); + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); Review comment: Please use logger to log exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
