pjfanning commented on code in PR #539:
URL: https://github.com/apache/incubator-pekko/pull/539#discussion_r1285186114


##########
multi-node-testkit/src/main/scala/org/apache/pekko/remote/testconductor/RemoteConnection.scala:
##########
@@ -94,44 +95,88 @@ private[pekko] case object Client extends Role
  */
 private[pekko] case object Server extends Role
 
+/**
+ * INTERNAL API.
+ */
+private[pekko] trait RemoteConnection {
+
+  /**
+   * The channel future associated with this connection.
+   */
+  def channelFuture: ChannelFuture
+
+  /**
+   * Shutdown the connection and release the resources.
+   */
+  def shutdown(): Unit
+}
+
 /**
  * INTERNAL API.
  */
 private[pekko] object RemoteConnection {
-  def apply(role: Role, sockaddr: InetSocketAddress, poolSize: Int, handler: 
ChannelUpstreamHandler): Channel = {
+  def apply(
+      role: Role,
+      sockaddr: InetSocketAddress,
+      poolSize: Int,
+      handler: ChannelInboundHandler): RemoteConnection = {
     role match {
       case Client =>
-        val socketfactory =
-          new NioClientSocketChannelFactory(Executors.newCachedThreadPool, 
Executors.newCachedThreadPool, poolSize)
-        val bootstrap = new ClientBootstrap(socketfactory)
-        bootstrap.setPipelineFactory(new TestConductorPipelineFactory(handler))
-        bootstrap.setOption("tcpNoDelay", true)
-        bootstrap.connect(sockaddr).getChannel
+        val bootstrap = new Bootstrap()
+        val eventLoopGroup = new NioEventLoopGroup(poolSize)
+        val cf = bootstrap
+          .group(eventLoopGroup)
+          .channel(classOf[NioSocketChannel])
+          .handler(new TestConductorPipelineFactory(handler))
+          .option[java.lang.Boolean](ChannelOption.TCP_NODELAY, true)
+          .option[java.lang.Boolean](ChannelOption.SO_KEEPALIVE, true)
+          .connect(sockaddr)
+        new RemoteConnection {
+          override def channelFuture: ChannelFuture = cf
+
+          override def shutdown(): Unit = {
+            try {
+              channelFuture.channel().close().sync()
+              eventLoopGroup.shutdownGracefully(1L, 1L, TimeUnit.SECONDS)
+            } catch {
+              case NonFatal(_) => // silence this one to not make tests look 
like they failed, it's not really critical
+            }
+          }
+        }
+
       case Server =>
-        val socketfactory =
-          new NioServerSocketChannelFactory(Executors.newCachedThreadPool, 
Executors.newCachedThreadPool, poolSize)
-        val bootstrap = new ServerBootstrap(socketfactory)
-        bootstrap.setPipelineFactory(new TestConductorPipelineFactory(handler))
-        bootstrap.setOption("reuseAddress", !Helpers.isWindows)
-        bootstrap.setOption("child.tcpNoDelay", true)
-        bootstrap.bind(sockaddr)
+        val bootstrap = new ServerBootstrap()
+        val parentEventLoopGroup = new NioEventLoopGroup(poolSize)
+        val childEventLoopGroup = new NioEventLoopGroup(poolSize)
+        val cf = bootstrap
+          .group(parentEventLoopGroup, childEventLoopGroup)
+          .channel(classOf[NioServerSocketChannel])
+          .childHandler(new TestConductorPipelineFactory(handler))
+          .option[java.lang.Boolean](ChannelOption.SO_REUSEADDR, 
!Helpers.isWindows)
+          .option[java.lang.Integer](ChannelOption.SO_BACKLOG, 2048)
+          .childOption[java.lang.Boolean](ChannelOption.TCP_NODELAY, true)
+          .childOption[java.lang.Boolean](ChannelOption.SO_KEEPALIVE, true)
+          .bind(sockaddr)
+          .sync()
+
+        new RemoteConnection {
+          override def channelFuture: ChannelFuture = cf
+
+          override def shutdown(): Unit = {
+            try {
+              channelFuture.channel().close().sync()
+              parentEventLoopGroup.shutdownGracefully(1L, 1L, TimeUnit.SECONDS)

Review Comment:
   I agree with @mdedetrich - this would be better as a setting in 
reference.conf



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to