You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by cr...@apache.org on 2022/02/28 11:15:27 UTC
[dubbo] branch 3.0.6-release updated: netty4_extend (#9725)
This is an automated email from the ASF dual-hosted git repository.
crazyhzm pushed a commit to branch 3.0.6-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0.6-release by this push:
new 316d171 netty4_extend (#9725)
316d171 is described below
commit 316d1711bde3c6c22f53f0870da5a1b799e87124
Author: Owen.Cai <89...@qq.com>
AuthorDate: Mon Feb 28 19:15:09 2022 +0800
netty4_extend (#9725)
* netty4_extend
* fix compile error
---
.../remoting/transport/netty4/NettyClient.java | 18 +++++++-
.../remoting/transport/netty4/NettyServer.java | 54 ++++++++++++++++++----
2 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java
index e7b30d0..9c79404 100644
--- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java
+++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java
@@ -96,8 +96,16 @@ public class NettyClient extends AbstractClient {
*/
@Override
protected void doOpen() throws Throwable {
- final NettyClientHandler nettyClientHandler = new NettyClientHandler(getUrl(), this);
+ final NettyClientHandler nettyClientHandler = createNettyClientHandler();
bootstrap = new Bootstrap();
+ initBootstrap(nettyClientHandler);
+ }
+
+ protected NettyClientHandler createNettyClientHandler() {
+ return new NettyClientHandler(getUrl(), this);
+ }
+
+ protected void initBootstrap(NettyClientHandler nettyClientHandler) {
bootstrap.group(EVENT_LOOP_GROUP.get())
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
@@ -229,4 +237,12 @@ public class NettyClient extends AbstractClient {
public boolean canHandleIdle() {
return true;
}
+
+ protected EventLoopGroup getEventLoopGroup() {
+ return EVENT_LOOP_GROUP.get();
+ }
+
+ protected Bootstrap getBootstrap() {
+ return bootstrap;
+ }
}
diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java
index eea977e..4be34e1 100644
--- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java
+++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java
@@ -98,14 +98,36 @@ public class NettyServer extends AbstractServer {
protected void doOpen() throws Throwable {
bootstrap = new ServerBootstrap();
- bossGroup = NettyEventLoopFactory.eventLoopGroup(1, EVENT_LOOP_BOSS_POOL_NAME);
- workerGroup = NettyEventLoopFactory.eventLoopGroup(
+ bossGroup = createBossGroup();
+ workerGroup = createWorkerGroup();
+
+ final NettyServerHandler nettyServerHandler = createNettyServerHandler();
+ channels = nettyServerHandler.getChannels();
+
+ initServerBootstrap(nettyServerHandler);
+
+ // bind
+ ChannelFuture channelFuture = bootstrap.bind(getBindAddress());
+ channelFuture.syncUninterruptibly();
+ channel = channelFuture.channel();
+
+ }
+
+ protected EventLoopGroup createBossGroup() {
+ return NettyEventLoopFactory.eventLoopGroup(1, EVENT_LOOP_BOSS_POOL_NAME);
+ }
+
+ protected EventLoopGroup createWorkerGroup() {
+ return NettyEventLoopFactory.eventLoopGroup(
getUrl().getPositiveParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS),
EVENT_LOOP_WORKER_POOL_NAME);
+ }
- final NettyServerHandler nettyServerHandler = new NettyServerHandler(getUrl(), this);
- channels = nettyServerHandler.getChannels();
+ protected NettyServerHandler createNettyServerHandler() {
+ return new NettyServerHandler(getUrl(), this);
+ }
+ protected void initServerBootstrap(NettyServerHandler nettyServerHandler) {
boolean keepalive = getUrl().getParameter(KEEP_ALIVE_KEY, Boolean.FALSE);
bootstrap.group(bossGroup, workerGroup)
@@ -130,11 +152,6 @@ public class NettyServer extends AbstractServer {
.addLast("handler", nettyServerHandler);
}
});
- // bind
- ChannelFuture channelFuture = bootstrap.bind(getBindAddress());
- channelFuture.syncUninterruptibly();
- channel = channelFuture.channel();
-
}
@Override
@@ -205,4 +222,23 @@ public class NettyServer extends AbstractServer {
return channel.isActive();
}
+ protected EventLoopGroup getBossGroup() {
+ return bossGroup;
+ }
+
+ protected EventLoopGroup getWorkerGroup() {
+ return workerGroup;
+ }
+
+ protected ServerBootstrap getServerBootstrap() {
+ return bootstrap;
+ }
+
+ protected io.netty.channel.Channel getBossChannel() {
+ return channel;
+ }
+
+ protected Map<String, Channel> getServerChannels() {
+ return channels;
+ }
}