You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/11/22 17:49:04 UTC

[ignite-3] 02/02: Update ClientHandlerModule

This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch ignite-15307
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit b9406ebbb63abd3e02157edebc9d4f03d03786d1
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Nov 22 20:48:56 2021 +0300

    Update ClientHandlerModule
---
 .../ignite/client/handler/ClientHandlerModule.java | 38 ++++++----------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
index 6708ec5..697efa6 100644
--- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
+++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
@@ -17,22 +17,16 @@
 
 package org.apache.ignite.client.handler;
 
-import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
 import java.net.BindException;
 import java.net.SocketAddress;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.client.proto.ClientMessageDecoder;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
 import org.apache.ignite.internal.manager.IgniteComponent;
-import org.apache.ignite.internal.network.netty.ConnectionManager;
 import org.apache.ignite.internal.processors.query.calcite.QueryProcessor;
 import org.apache.ignite.lang.IgniteException;
 import org.apache.ignite.lang.IgniteLogger;
@@ -57,13 +51,10 @@ public class ClientHandlerModule implements IgniteComponent {
     private volatile Channel channel;
 
     /** Processor. */
-    private QueryProcessor processor;
-    
-    /** Connection manager. */
-    private ConnectionManager connectionManager;
+    private final QueryProcessor processor;
     
     /** Netty bootstrap factory. */
-    private NettyBootstrapFactory bootstrapFactory;
+    private final NettyBootstrapFactory bootstrapFactory;
     
     /**
      * Constructor.
@@ -138,14 +129,10 @@ public class ClientHandlerModule implements IgniteComponent {
 
         int port = 0;
         Channel ch = null;
-
-        // TODO: Reuse Netty infrastructure from network module IGNITE-15307.
-        EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
-        ServerBootstrap b = new ServerBootstrap();
-
-        b.group(eventLoopGroup)
-                .channel(NioServerSocketChannel.class)
-                .childHandler(new ChannelInitializer<>() {
+    
+        var bootstrap = bootstrapFactory.createServerBootstrap();
+    
+        bootstrap.childHandler(new ChannelInitializer<>() {
                     @Override
                     protected void initChannel(Channel ch) {
                         ch.pipeline().addLast(
@@ -153,21 +140,18 @@ public class ClientHandlerModule implements IgniteComponent {
                                 new ClientInboundMessageHandler(igniteTables, processor));
                     }
                 })
-                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectTimeout())
-                .childOption(ChannelOption.SO_KEEPALIVE, true)
-                .childOption(ChannelOption.TCP_NODELAY, true);
-
+                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectTimeout());
+    
         for (int portCandidate = desiredPort; portCandidate <= desiredPort + portRange; portCandidate++) {
-            ChannelFuture bindRes = b.bind(portCandidate).await();
+            ChannelFuture bindRes = bootstrap.bind(portCandidate).await();
 
             if (bindRes.isSuccess()) {
                 ch = bindRes.channel();
-                ch.closeFuture().addListener((ChannelFutureListener) fut -> eventLoopGroup.shutdownGracefully());
+                ch.closeFuture();
 
                 port = portCandidate;
                 break;
             } else if (!(bindRes.cause() instanceof BindException)) {
-                eventLoopGroup.shutdownGracefully();
                 throw new IgniteException(bindRes.cause());
             }
         }
@@ -178,8 +162,6 @@ public class ClientHandlerModule implements IgniteComponent {
 
             LOG.error(msg);
 
-            eventLoopGroup.shutdownGracefully();
-
             throw new IgniteException(msg);
         }