本文整理汇总了Java中io.grpc.netty.GrpcSslContexts.forClient方法的典型用法代码示例。如果您正苦于以下问题:Java GrpcSslContexts.forClient方法的具体用法?Java GrpcSslContexts.forClient怎么用?Java GrpcSslContexts.forClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.netty.GrpcSslContexts
的用法示例。
在下文中一共展示了GrpcSslContexts.forClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CentralConnection
import io.grpc.netty.GrpcSslContexts; //导入方法依赖的package包/类
CentralConnection(String collectorAddress, @Nullable String collectorAuthority, File confDir,
@Nullable File sharedConfDir, AtomicBoolean inConnectionFailure) throws SSLException {
ParsedCollectorAddress parsedCollectorAddress = parseCollectorAddress(collectorAddress);
eventLoopGroup = EventLoopGroups.create("Glowroot-GRPC-Worker-ELG");
channelExecutor =
Executors.newSingleThreadExecutor(ThreadFactories.create("Glowroot-GRPC-Executor"));
String authority;
if (collectorAuthority != null) {
authority = collectorAuthority;
} else if (parsedCollectorAddress.addresses().size() == 1) {
authority = parsedCollectorAddress.addresses().get(0).getHostName();
} else if (!parsedCollectorAddress.https()) {
authority = "dummy-service-authority";
} else {
throw new IllegalStateException("collector.authority is required when using client"
+ " side load balancing to connect to a glowroot central cluster over HTTPS");
}
NettyChannelBuilder builder = NettyChannelBuilder
.forTarget("dummy-target")
.nameResolverFactory(new SimpleNameResolverFactory(
parsedCollectorAddress.addresses(), authority))
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
.eventLoopGroup(eventLoopGroup)
.executor(channelExecutor)
// aggressive keep alive, shouldn't even be used since gauge data is sent every
// 5 seconds and keep alive will only kick in after 30 seconds of not hearing back
// from the server
.keepAliveTime(30, SECONDS);
if (parsedCollectorAddress.https()) {
SslContextBuilder sslContext = GrpcSslContexts.forClient();
File trustCertCollectionFile = getTrustCertCollectionFile(confDir, sharedConfDir);
if (trustCertCollectionFile != null) {
sslContext.trustManager(trustCertCollectionFile);
}
channel = builder.sslContext(sslContext.build())
.negotiationType(NegotiationType.TLS)
.build();
} else {
channel = builder.negotiationType(NegotiationType.PLAINTEXT)
.build();
}
retryExecutor = Executors.newSingleThreadScheduledExecutor(
ThreadFactories.create("Glowroot-Collector-Retry"));
this.inConnectionFailure = inConnectionFailure;
this.collectorAddress = collectorAddress;
}