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

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit 3ac121a3bc96893da6d64af83c0ac0d74cd76ebc
Author: Lei Zhang <[email protected]>
AuthorDate: Tue Nov 12 22:16:01 2019 +0800

    SCB-1585 Polishing
---
 .../servicecomb/pack/alpha/server/GrpcStartable.java | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git 
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/GrpcStartable.java
 
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/GrpcStartable.java
index 139b33b..4760bac 100644
--- 
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/GrpcStartable.java
+++ 
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/GrpcStartable.java
@@ -62,23 +62,13 @@ public class GrpcStartable implements ServerStartable {
     try {
       OptionalInt unusedPort = findUnusedPort(serverConfig);
       if(unusedPort.isPresent()){
+        serverBuilder = getServerBuilder(unusedPort.getAsInt());
         if (serverConfig.isSslEnable()){
-          serverBuilder = NettyServerBuilder.forAddress(
-                  new InetSocketAddress(serverConfig.getHost(), 
unusedPort.getAsInt()))
-              .channelType(NioServerSocketChannel.class)
-              .bossEventLoopGroup(new NioEventLoopGroup(1))
-              .workerEventLoopGroup(new NioEventLoopGroup());
-
           try {
             ((NettyServerBuilder) 
serverBuilder).sslContext(getSslContextBuilder(serverConfig).build());
           } catch (SSLException e) {
             throw new IllegalStateException("Unable to setup grpc to use 
SSL.", e);
           }
-        } else {
-          serverBuilder = NettyServerBuilder.forPort(unusedPort.getAsInt())
-              .channelType(NioServerSocketChannel.class)
-              .bossEventLoopGroup(new NioEventLoopGroup(1))
-              .workerEventLoopGroup(new NioEventLoopGroup());
         }
         Arrays.stream(services).forEach(serverBuilder::addService);
         server = serverBuilder.build();
@@ -110,6 +100,14 @@ public class GrpcStartable implements ServerStartable {
     return this.serverConfig;
   }
 
+  private ServerBuilder getServerBuilder(int port) {
+    return NettyServerBuilder.forAddress(
+        new InetSocketAddress(serverConfig.getHost(), port))
+        .channelType(NioServerSocketChannel.class)
+        .bossEventLoopGroup(new NioEventLoopGroup(1))
+        .workerEventLoopGroup(new NioEventLoopGroup());
+  }
+
   private SslContextBuilder getSslContextBuilder(GrpcServerConfig config) {
 
     Properties prop = new Properties();

Reply via email to