Skip to content

Commit d7b60c0

Browse files
address code review
Signed-off-by: marsishandsome <marsishandsome@gmail.com>
1 parent c0775f7 commit d7b60c0

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/main/java/org/tikv/common/util/ChannelFactory.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.tikv.common.util;
1717

1818
import io.grpc.ManagedChannel;
19-
import io.grpc.ManagedChannelBuilder;
2019
import io.grpc.netty.GrpcSslContexts;
2120
import io.grpc.netty.NettyChannelBuilder;
2221
import io.netty.handler.ssl.SslContext;
@@ -92,17 +91,19 @@ public ManagedChannel getChannel(String addressStr, HostMapping hostMapping) {
9291
} catch (Exception e) {
9392
throw new IllegalArgumentException("failed to get mapped address " + address, e);
9493
}
94+
9595
// Channel should be lazy without actual connection until first call
9696
// So a coarse grain lock is ok here
97+
NettyChannelBuilder builder =
98+
NettyChannelBuilder.forAddress(mappedAddr.getHost(), mappedAddr.getPort())
99+
.maxInboundMessageSize(maxFrameSize)
100+
.keepAliveTime(keepaliveTime, TimeUnit.SECONDS)
101+
.keepAliveTimeout(keepaliveTimeout, TimeUnit.SECONDS)
102+
.keepAliveWithoutCalls(true)
103+
.idleTimeout(60, TimeUnit.SECONDS);
104+
97105
if (sslContextBuilder == null) {
98-
return ManagedChannelBuilder.forAddress(mappedAddr.getHost(), mappedAddr.getPort())
99-
.maxInboundMessageSize(maxFrameSize)
100-
.keepAliveTime(keepaliveTime, TimeUnit.SECONDS)
101-
.keepAliveTimeout(keepaliveTimeout, TimeUnit.SECONDS)
102-
.keepAliveWithoutCalls(true)
103-
.usePlaintext(true)
104-
.idleTimeout(60, TimeUnit.SECONDS)
105-
.build();
106+
return builder.usePlaintext(true).build();
106107
} else {
107108
SslContext sslContext = null;
108109
try {
@@ -111,14 +112,7 @@ public ManagedChannel getChannel(String addressStr, HostMapping hostMapping) {
111112
logger.error("create ssl context failed!", e);
112113
return null;
113114
}
114-
return NettyChannelBuilder.forAddress(mappedAddr.getHost(), mappedAddr.getPort())
115-
.maxInboundMessageSize(maxFrameSize)
116-
.keepAliveTime(keepaliveTime, TimeUnit.SECONDS)
117-
.keepAliveTimeout(keepaliveTimeout, TimeUnit.SECONDS)
118-
.keepAliveWithoutCalls(true)
119-
.sslContext(sslContext)
120-
.idleTimeout(60, TimeUnit.SECONDS)
121-
.build();
115+
return builder.sslContext(sslContext).build();
122116
}
123117
});
124118
}

0 commit comments

Comments
 (0)