当前位置: 首页>>代码示例>>Java>>正文


Java GrpcSslContexts.forClient方法代码示例

本文整理汇总了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;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:47,代码来源:CentralConnection.java


注:本文中的io.grpc.netty.GrpcSslContexts.forClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。