You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/02/05 07:09:04 UTC

[GitHub] [incubator-inlong] luchunliang opened a new pull request #2395: [INLONG-2377] DataProxy support new protocol format source.

luchunliang opened a new pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395


   ### Title Name: [INLONG-2377][Inlong-DataProxy] DataProxy support new protocol format source.
   
   Fixes #2377 
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] codecov-commenter commented on pull request #2395: [INLONG-2377] DataProxy support new protocol format source.

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#issuecomment-1030572901


   # [Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2395](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (416636a) into [master](https://codecov.io/gh/apache/incubator-inlong/commit/5f10edaa92a83d83f5ea16ef2b7c23a558e6e245?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5f10eda) will **increase** coverage by `0.04%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-inlong/pull/2395/graphs/tree.svg?width=650&height=150&src=pr&token=1EUK92O9K2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #2395      +/-   ##
   ============================================
   + Coverage     12.49%   12.54%   +0.04%     
   - Complexity     1212     1217       +5     
   ============================================
     Files           420      420              
     Lines         36240    36240              
     Branches       5670     5670              
   ============================================
   + Hits           4527     4545      +18     
   + Misses        30914    30886      -28     
   - Partials        799      809      +10     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../tubemq/corebase/policies/FlowCtrlRuleHandler.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybFJ1bGVIYW5kbGVyLmphdmE=) | `34.07% <0.00%> (+1.10%)` | :arrow_up: |
   | [.../inlong/tubemq/corebase/policies/FlowCtrlItem.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybEl0ZW0uamF2YQ==) | `38.88% <0.00%> (+2.22%)` | :arrow_up: |
   | [...ong/tubemq/manager/service/ClusterServiceImpl.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL3NlcnZpY2UvQ2x1c3RlclNlcnZpY2VJbXBsLmphdmE=) | `52.94% <0.00%> (+2.94%)` | :arrow_up: |
   | [...inlong/tubemq/manager/service/TaskServiceImpl.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL3NlcnZpY2UvVGFza1NlcnZpY2VJbXBsLmphdmE=) | `8.53% <0.00%> (+4.87%)` | :arrow_up: |
   | [...nlong/tubemq/corebase/policies/FlowCtrlResult.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybFJlc3VsdC5qYXZh) | `60.00% <0.00%> (+60.00%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [67b5039...416636a](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804385411



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpChannelPipelineFactory.java
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.conf.Configurable;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * InlongTcpChannelPipelineFactory
+ */
+public class InlongTcpChannelPipelineFactory implements ChannelPipelineFactory, Configurable {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpChannelPipelineFactory.class);
+    private static final int DEFAULT_READ_IDLE_TIME = 70 * 60 * 1000;
+    private SourceContext sourceContext;
+    private String messageHandlerName;
+    private Timer timer = new HashedWheelTimer();
+
+    /**
+     * get server factory
+     *
+     * @param sourceContext
+     */
+    public InlongTcpChannelPipelineFactory(SourceContext sourceContext) {
+        this.sourceContext = sourceContext;
+    }
+
+    @Override
+    public ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline cp = Channels.pipeline();
+        return addMessageHandlersTo(cp);
+    }
+
+    /**
+     * get message handlers
+     * 
+     * @param  cp
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public ChannelPipeline addMessageHandlersTo(ChannelPipeline cp) {
+        cp.addLast("messageDecoder", new LengthFieldBasedFrameDecoder(
+                sourceContext.getMaxMsgLength(), 0, 4, -4, 0, true));

Review comment:
       a series of magic number




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804443959



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");

Review comment:
       magic number 16 \*1024\*1024




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804442750



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();

Review comment:
       please remove useless code




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r805462149



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();

Review comment:
       fixed it.




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804385411



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpChannelPipelineFactory.java
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.conf.Configurable;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * InlongTcpChannelPipelineFactory
+ */
+public class InlongTcpChannelPipelineFactory implements ChannelPipelineFactory, Configurable {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpChannelPipelineFactory.class);
+    private static final int DEFAULT_READ_IDLE_TIME = 70 * 60 * 1000;
+    private SourceContext sourceContext;
+    private String messageHandlerName;
+    private Timer timer = new HashedWheelTimer();
+
+    /**
+     * get server factory
+     *
+     * @param sourceContext
+     */
+    public InlongTcpChannelPipelineFactory(SourceContext sourceContext) {
+        this.sourceContext = sourceContext;
+    }
+
+    @Override
+    public ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline cp = Channels.pipeline();
+        return addMessageHandlersTo(cp);
+    }
+
+    /**
+     * get message handlers
+     * 
+     * @param  cp
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public ChannelPipeline addMessageHandlersTo(ChannelPipeline cp) {
+        cp.addLast("messageDecoder", new LengthFieldBasedFrameDecoder(
+                sourceContext.getMaxMsgLength(), 0, 4, -4, 0, true));

Review comment:
       a series magic number




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] codecov-commenter edited a comment on pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#issuecomment-1030572901


   # [Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2395](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (431841a) into [master](https://codecov.io/gh/apache/incubator-inlong/commit/5f10edaa92a83d83f5ea16ef2b7c23a558e6e245?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5f10eda) will **increase** coverage by `0.05%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-inlong/pull/2395/graphs/tree.svg?width=650&height=150&src=pr&token=1EUK92O9K2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #2395      +/-   ##
   ============================================
   + Coverage     12.49%   12.54%   +0.05%     
   - Complexity     1212     1220       +8     
   ============================================
     Files           420      420              
     Lines         36240    36255      +15     
     Branches       5670     5674       +4     
   ============================================
   + Hits           4527     4550      +23     
   + Misses        30914    30895      -19     
   - Partials        799      810      +11     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...inlong/tubemq/manager/controller/TubeMQResult.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL2NvbnRyb2xsZXIvVHViZU1RUmVzdWx0LmphdmE=) | `60.00% <0.00%> (-3.16%)` | :arrow_down: |
   | [...long/tubemq/manager/service/MasterServiceImpl.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL3NlcnZpY2UvTWFzdGVyU2VydmljZUltcGwuamF2YQ==) | `5.79% <0.00%> (-0.87%)` | :arrow_down: |
   | [...ager/controller/cluster/request/AddClusterReq.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL2NvbnRyb2xsZXIvY2x1c3Rlci9yZXF1ZXN0L0FkZENsdXN0ZXJSZXEuamF2YQ==) | `75.00% <0.00%> (ø)` | |
   | [.../tubemq/corebase/policies/FlowCtrlRuleHandler.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybFJ1bGVIYW5kbGVyLmphdmE=) | `34.07% <0.00%> (+1.10%)` | :arrow_up: |
   | [.../inlong/tubemq/corebase/policies/FlowCtrlItem.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybEl0ZW0uamF2YQ==) | `38.88% <0.00%> (+2.22%)` | :arrow_up: |
   | [...inlong/tubemq/manager/service/TaskServiceImpl.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL3NlcnZpY2UvVGFza1NlcnZpY2VJbXBsLmphdmE=) | `8.53% <0.00%> (+4.87%)` | :arrow_up: |
   | [.../manager/controller/cluster/ClusterController.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL2NvbnRyb2xsZXIvY2x1c3Rlci9DbHVzdGVyQ29udHJvbGxlci5qYXZh) | `26.08% <0.00%> (+5.15%)` | :arrow_up: |
   | [...ong/tubemq/manager/service/ClusterServiceImpl.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtbWFuYWdlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9tYW5hZ2VyL3NlcnZpY2UvQ2x1c3RlclNlcnZpY2VJbXBsLmphdmE=) | `55.55% <0.00%> (+5.55%)` | :arrow_up: |
   | [...nlong/tubemq/corebase/policies/FlowCtrlResult.java](https://codecov.io/gh/apache/incubator-inlong/pull/2395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-aW5sb25nLXR1YmVtcS90dWJlbXEtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW5sb25nL3R1YmVtcS9jb3JlYmFzZS9wb2xpY2llcy9GbG93Q3RybFJlc3VsdC5qYXZh) | `60.00% <0.00%> (+60.00%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [67b5039...431841a](https://codecov.io/gh/apache/incubator-inlong/pull/2395?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804438549



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       ditto
   




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r805461853



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpChannelPipelineFactory.java
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.conf.Configurable;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * InlongTcpChannelPipelineFactory
+ */
+public class InlongTcpChannelPipelineFactory implements ChannelPipelineFactory, Configurable {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpChannelPipelineFactory.class);
+    private static final int DEFAULT_READ_IDLE_TIME = 70 * 60 * 1000;
+    private SourceContext sourceContext;
+    private String messageHandlerName;
+    private Timer timer = new HashedWheelTimer();
+
+    /**
+     * get server factory
+     *
+     * @param sourceContext
+     */
+    public InlongTcpChannelPipelineFactory(SourceContext sourceContext) {
+        this.sourceContext = sourceContext;
+    }
+
+    @Override
+    public ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline cp = Channels.pipeline();
+        return addMessageHandlersTo(cp);
+    }
+
+    /**
+     * get message handlers
+     * 
+     * @param  cp
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public ChannelPipeline addMessageHandlersTo(ChannelPipeline cp) {
+        cp.addLast("messageDecoder", new LengthFieldBasedFrameDecoder(
+                sourceContext.getMaxMsgLength(), 0, 4, -4, 0, true));

Review comment:
       fixed it

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");
+
+            trafficClass = context.getInteger(ConfigConstants.TRAFFIC_CLASS, 0);
+            Preconditions.checkArgument((trafficClass == 0 || trafficClass == 96),
+                    "trafficClass must be == 0 or == 96");
+
+            msgFactoryName = context.getString(ConfigConstants.MSG_FACTORY_NAME,
+                    InlongTcpChannelPipelineFactory.class.getName());
+            msgFactoryName = msgFactoryName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(msgFactoryName),
+                    "msgFactoryName is empty");
+
+            messageHandlerName = context.getString(ConfigConstants.MESSAGE_HANDLER_NAME,
+                    InlongTcpChannelHandler.class.getName());
+            messageHandlerName = messageHandlerName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(messageHandlerName),
+                    "messageHandlerName is empty");
+
+            if (this.pipelineFactoryConfigurable != null) {
+                this.pipelineFactoryConfigurable.configure(context);
+            }
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       fixed it.




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r805463082



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");
+
+            trafficClass = context.getInteger(ConfigConstants.TRAFFIC_CLASS, 0);
+            Preconditions.checkArgument((trafficClass == 0 || trafficClass == 96),
+                    "trafficClass must be == 0 or == 96");
+
+            msgFactoryName = context.getString(ConfigConstants.MSG_FACTORY_NAME,
+                    InlongTcpChannelPipelineFactory.class.getName());
+            msgFactoryName = msgFactoryName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(msgFactoryName),
+                    "msgFactoryName is empty");
+
+            messageHandlerName = context.getString(ConfigConstants.MESSAGE_HANDLER_NAME,
+                    InlongTcpChannelHandler.class.getName());
+            messageHandlerName = messageHandlerName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(messageHandlerName),
+                    "messageHandlerName is empty");
+
+            if (this.pipelineFactoryConfigurable != null) {
+                this.pipelineFactoryConfigurable.configure(context);
+            }
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       fixed it.




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r805461914



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();

Review comment:
       fixed it.

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       fixed it.




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804436636



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();

Review comment:
       do not print exception directly




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804445177



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");
+
+            trafficClass = context.getInteger(ConfigConstants.TRAFFIC_CLASS, 0);
+            Preconditions.checkArgument((trafficClass == 0 || trafficClass == 96),
+                    "trafficClass must be == 0 or == 96");
+
+            msgFactoryName = context.getString(ConfigConstants.MSG_FACTORY_NAME,
+                    InlongTcpChannelPipelineFactory.class.getName());
+            msgFactoryName = msgFactoryName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(msgFactoryName),
+                    "msgFactoryName is empty");
+
+            messageHandlerName = context.getString(ConfigConstants.MESSAGE_HANDLER_NAME,
+                    InlongTcpChannelHandler.class.getName());
+            messageHandlerName = messageHandlerName.trim();
+            Preconditions.checkArgument(StringUtils.isNotBlank(messageHandlerName),
+                    "messageHandlerName is empty");
+
+            if (this.pipelineFactoryConfigurable != null) {
+                this.pipelineFactoryConfigurable.configure(context);
+            }
+        } catch (Throwable t) {
+            t.printStackTrace();

Review comment:
       ditto




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804443959



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");

Review comment:
       202-206 and 208-212 can be abstracted to a function




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] imvan commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
imvan commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r804443959



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpSource.java
##########
@@ -0,0 +1,237 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.EventDrivenSource;
+import org.apache.flume.FlumeException;
+import org.apache.flume.conf.Configurable;
+import org.apache.flume.source.AbstractSource;
+import org.apache.inlong.dataproxy.base.NamedThreadFactory;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.util.ThreadNameDeterminer;
+import org.jboss.netty.util.ThreadRenamingRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Inlong tcp source
+ */
+public class InlongTcpSource extends AbstractSource implements Configurable, EventDrivenSource {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpSource.class);
+
+    protected ChannelGroup allChannels;
+    protected SourceContext sourceContext;
+
+    protected ServerBootstrap serverBootstrap = null;
+    protected int port;
+    protected String host = null;
+    protected String msgFactoryName;
+    protected String messageHandlerName;
+
+    private boolean tcpNoDelay = true;
+    private boolean keepAlive = true;
+    private int receiveBufferSize;
+    private int highWaterMark;
+    private int sendBufferSize;
+    private int trafficClass;
+
+    private Channel nettyChannel = null;
+
+    private Configurable pipelineFactoryConfigurable = null;
+
+    /**
+     * Constructor
+     */
+    public InlongTcpSource() {
+        super();
+        allChannels = new DefaultChannelGroup();
+    }
+
+    /**
+     * start
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Override
+    public synchronized void start() {
+        try {
+            LOG.info("start " + this.getName());
+
+            ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
+            ChannelFactory factory = new NioServerSocketChannelFactory(
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyBoss-threadGroup")),
+                    1,
+                    Executors.newCachedThreadPool(
+                            new NamedThreadFactory("tcpSource-nettyWorker-threadGroup")),
+                    this.sourceContext.getMaxThreads());
+            LOG.info("Set max workers : {} ;", this.sourceContext.getMaxThreads());
+            ChannelPipelineFactory pipelineFactory = null;
+
+            serverBootstrap = new ServerBootstrap(factory);
+            serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
+            serverBootstrap.setOption("child.keepAlive", keepAlive);
+            serverBootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
+            serverBootstrap.setOption("child.sendBufferSize", sendBufferSize);
+            serverBootstrap.setOption("child.trafficClass", trafficClass);
+            serverBootstrap.setOption("child.writeBufferHighWaterMark", highWaterMark);
+            LOG.info("load msgFactory=" + msgFactoryName
+                    + " and messageHandlerName=" + messageHandlerName);
+            try {
+                Class<? extends ChannelPipelineFactory> clazz = (Class<? extends ChannelPipelineFactory>) Class
+                        .forName(msgFactoryName);
+
+                Constructor ctor = clazz.getConstructor(SourceContext.class);
+
+                LOG.info("Using channel processor:{}", getChannelProcessor().getClass().getName());
+                pipelineFactory = (ChannelPipelineFactory) ctor.newInstance(sourceContext);
+                if (pipelineFactory instanceof Configurable) {
+                    this.pipelineFactoryConfigurable = ((Configurable) pipelineFactory);
+                    this.pipelineFactoryConfigurable.configure(sourceContext.getParentContext());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                LOG.error(
+                        "Inlong Tcp Source start error, fail to construct ChannelPipelineFactory with name {}, ex {}",
+                        msgFactoryName, e);
+                stop();
+                throw new FlumeException(e.getMessage(), e);
+            }
+
+            serverBootstrap.setPipelineFactory(pipelineFactory);
+
+            try {
+                if (host == null) {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(port));
+                } else {
+                    nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port));
+                }
+            } catch (Exception e) {
+                LOG.error("Inlong TCP Source error bind host {} port {},program will exit!", host,
+                        port);
+                System.exit(-1);
+            }
+
+            allChannels.add(nettyChannel);
+
+            LOG.info("Inlong TCP Source started at host {}, port {}", host, port);
+            super.start();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
+    /**
+     * stop
+     */
+    @Override
+    public synchronized void stop() {
+        LOG.info("[STOP SOURCE]{} stopping...", super.toString());
+        if (allChannels != null && !allChannels.isEmpty()) {
+            try {
+                allChannels.unbind().awaitUninterruptibly();
+                allChannels.close().awaitUninterruptibly();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source netty server stop ex", e);
+            } finally {
+                allChannels.clear();
+            }
+        }
+
+        if (serverBootstrap != null) {
+            try {
+                serverBootstrap.releaseExternalResources();
+            } catch (Exception e) {
+                LOG.warn("Inlong TCP Source serverBootstrap stop ex ", e);
+            } finally {
+                serverBootstrap = null;
+            }
+        }
+
+//        super.stop();
+        LOG.info("[STOP SOURCE]{} stopped", super.getName());
+    }
+
+    /**
+     * configure
+     * 
+     * @param context
+     */
+    @Override
+    public void configure(Context context) {
+        try {
+            LOG.info("context is {}", context);
+            this.sourceContext = new SourceContext(this, allChannels, context);
+            // start
+            this.sourceContext.start();
+
+            tcpNoDelay = context.getBoolean(ConfigConstants.TCP_NO_DELAY, true);
+            keepAlive = context.getBoolean(ConfigConstants.KEEP_ALIVE, true);
+            highWaterMark = context.getInteger(ConfigConstants.HIGH_WATER_MARK, 64 * 1024);
+            receiveBufferSize = context.getInteger(ConfigConstants.RECEIVE_BUFFER_SIZE, 1024 * 64);
+            if (receiveBufferSize > 16 * 1024 * 1024) {
+                receiveBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(receiveBufferSize > 0, "receiveBufferSize must be > 0");
+
+            sendBufferSize = context.getInteger(ConfigConstants.SEND_BUFFER_SIZE, 1024 * 64);
+            if (sendBufferSize > 16 * 1024 * 1024) {
+                sendBufferSize = 16 * 1024 * 1024;
+            }
+            Preconditions.checkArgument(sendBufferSize > 0, "sendBufferSize must be > 0");

Review comment:
       magic number 16*1024*1024




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395#discussion_r805461853



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/source/tcp/InlongTcpChannelPipelineFactory.java
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.dataproxy.source.tcp;
+
+import java.lang.reflect.Constructor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.flume.Context;
+import org.apache.flume.conf.Configurable;
+import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.source.SourceContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * InlongTcpChannelPipelineFactory
+ */
+public class InlongTcpChannelPipelineFactory implements ChannelPipelineFactory, Configurable {
+
+    public static final Logger LOG = LoggerFactory.getLogger(InlongTcpChannelPipelineFactory.class);
+    private static final int DEFAULT_READ_IDLE_TIME = 70 * 60 * 1000;
+    private SourceContext sourceContext;
+    private String messageHandlerName;
+    private Timer timer = new HashedWheelTimer();
+
+    /**
+     * get server factory
+     *
+     * @param sourceContext
+     */
+    public InlongTcpChannelPipelineFactory(SourceContext sourceContext) {
+        this.sourceContext = sourceContext;
+    }
+
+    @Override
+    public ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline cp = Channels.pipeline();
+        return addMessageHandlersTo(cp);
+    }
+
+    /**
+     * get message handlers
+     * 
+     * @param  cp
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public ChannelPipeline addMessageHandlersTo(ChannelPipeline cp) {
+        cp.addLast("messageDecoder", new LengthFieldBasedFrameDecoder(
+                sourceContext.getMaxMsgLength(), 0, 4, -4, 0, true));

Review comment:
       fixed it




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-inlong] dockerzhang merged pull request #2395: [INLONG-2377] DataProxy support PB compression protocol format source.

Posted by GitBox <gi...@apache.org>.
dockerzhang merged pull request #2395:
URL: https://github.com/apache/incubator-inlong/pull/2395


   


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org