-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-11700][SDK] Optimize TCP message reporting Sender implementat…
…ion (#11701) Co-authored-by: gosonzhang <[email protected]>
- Loading branch information
1 parent
bfbeae2
commit 16084cc
Showing
10 changed files
with
1,462 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/tcp/ClientHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.dataproxy.network.tcp; | ||
|
||
import org.apache.inlong.common.msg.MsgType; | ||
import org.apache.inlong.sdk.dataproxy.network.tcp.codec.DecodeObject; | ||
import org.apache.inlong.sdk.dataproxy.utils.LogCounter; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.SimpleChannelInboundHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* TCP client handler class | ||
* | ||
* Used to process TCP response message. | ||
*/ | ||
public class ClientHandler extends SimpleChannelInboundHandler<DecodeObject> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ClientHandler.class); | ||
private static final LogCounter exceptCnt = new LogCounter(10, 100000, 60 * 1000L); | ||
private static final LogCounter thrownCnt = new LogCounter(10, 100000, 60 * 1000L); | ||
|
||
private final TcpClientMgr tcpClientMgr; | ||
|
||
public ClientHandler(TcpClientMgr tcpClientMgr) { | ||
this.tcpClientMgr = tcpClientMgr; | ||
} | ||
|
||
@Override | ||
public void channelRead0(ChannelHandlerContext ctx, DecodeObject decObject) { | ||
if (decObject.getMsgType() != MsgType.MSG_BIN_HEARTBEAT) { | ||
tcpClientMgr.feedbackMsgResponse(ctx.channel().toString(), decObject); | ||
} | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { | ||
if (exceptCnt.shouldPrint()) { | ||
logger.warn("ClientHandler({})'s channel {} has error!", | ||
tcpClientMgr.getSenderId(), ctx.channel(), e); | ||
} | ||
try { | ||
tcpClientMgr.setChannelFrozen(ctx.channel().toString()); | ||
} catch (Throwable ex) { | ||
if (thrownCnt.shouldPrint()) { | ||
logger.warn("ClientHandler({}) exceptionCaught throw exception", | ||
tcpClientMgr.getSenderId(), ex); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void channelInactive(ChannelHandlerContext ctx) throws Exception { | ||
ctx.fireChannelInactive(); | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("ClientHandler({}) channelDisconnected {}", | ||
tcpClientMgr.getSenderId(), ctx.channel()); | ||
} | ||
try { | ||
tcpClientMgr.notifyChannelDisconnected(ctx.channel().toString()); | ||
} catch (Throwable ex) { | ||
if (thrownCnt.shouldPrint()) { | ||
logger.warn("ClientHandler({}) channelInactive throw exception", | ||
tcpClientMgr.getSenderId(), ex); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("ClientHandler({}) channelUnregistered {}", | ||
tcpClientMgr.getSenderId(), ctx.channel()); | ||
} | ||
try { | ||
tcpClientMgr.notifyChannelDisconnected(ctx.channel().toString()); | ||
} catch (Throwable ex) { | ||
if (thrownCnt.shouldPrint()) { | ||
logger.warn("ClientHandler({}) channelUnregistered throw exception", | ||
tcpClientMgr.getSenderId(), ex); | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/tcp/ClientPipelineFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.dataproxy.network.tcp; | ||
|
||
import org.apache.inlong.sdk.dataproxy.network.tcp.codec.ProtocolDecoder; | ||
import org.apache.inlong.sdk.dataproxy.network.tcp.codec.ProtocolEncoder; | ||
|
||
import io.netty.channel.ChannelInitializer; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; | ||
|
||
/** | ||
* TCP client Pipeline Factory class | ||
* | ||
* Used to build TCP pipeline | ||
*/ | ||
public class ClientPipelineFactory extends ChannelInitializer<SocketChannel> { | ||
|
||
private final TcpClientMgr tcpClientMgr; | ||
|
||
public ClientPipelineFactory(TcpClientMgr tcpClientMgr) { | ||
this.tcpClientMgr = tcpClientMgr; | ||
} | ||
|
||
@Override | ||
public void initChannel(SocketChannel ch) throws Exception { | ||
|
||
// Setup channel except for the SsHandler for TLS enabled connections | ||
|
||
ch.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder( | ||
65536, 0, 4, 0, 0)); | ||
|
||
ch.pipeline().addLast("contentDecoder", new ProtocolDecoder()); | ||
ch.pipeline().addLast("contentEncoder", new ProtocolEncoder()); | ||
ch.pipeline().addLast("handler", new ClientHandler(tcpClientMgr)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/tcp/SendQos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.dataproxy.network.tcp; | ||
|
||
/** | ||
* Send Qos class | ||
* | ||
* Used to identify different send type | ||
*/ | ||
public enum SendQos { | ||
|
||
NO_ACK, // only request, without response | ||
SOURCE_ACK, // request and return a response upon receipt by DataProxy, default | ||
SINK_ACK // request, and return a response after successful forwarding of the request by DataProxy | ||
} |
Oops, something went wrong.