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


Java NettyChannelBuilder.sslContext方法代码示例

本文整理汇总了Java中io.grpc.netty.NettyChannelBuilder.sslContext方法的典型用法代码示例。如果您正苦于以下问题:Java NettyChannelBuilder.sslContext方法的具体用法?Java NettyChannelBuilder.sslContext怎么用?Java NettyChannelBuilder.sslContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.netty.NettyChannelBuilder的用法示例。


在下文中一共展示了NettyChannelBuilder.sslContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: defaultChannelBuilder

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
private ManagedChannelBuilder<?> defaultChannelBuilder() {
  NettyChannelBuilder channelBuilder = NettyChannelBuilder.forTarget("etcd");

  if (builder.sslContext() != null) {
    channelBuilder.sslContext(builder.sslContext());
  } else {
    channelBuilder.usePlaintext(true);
  }

  channelBuilder.nameResolverFactory(
      forEndpoints(
        Optional.ofNullable(builder.authority()).orElse("etcd"),
        builder.endpoints(),
        Optional.ofNullable(builder.uriResolverLoader())
            .orElseGet(URIResolverLoader::defaultLoader)
      )
  );

  if (builder.loadBalancerFactory() != null) {
    channelBuilder.loadBalancerFactory(builder.loadBalancerFactory());
  }

  channelBuilder.intercept(new AuthTokenInterceptor());

  return channelBuilder;
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:27,代码来源:ClientConnectionManager.java

示例2: newChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
/**
 * Create a new gRPC {@link ManagedChannel}.
 *
 * @throws IOException in case the channel can't be constructed.
 */
public static ManagedChannel newChannel(String target, AuthAndTLSOptions options)
    throws IOException {
  Preconditions.checkNotNull(target);
  Preconditions.checkNotNull(options);

  final SslContext sslContext =
      options.tlsEnabled ? createSSlContext(options.tlsCertificate) : null;

  try {
    NettyChannelBuilder builder =
        NettyChannelBuilder.forTarget(target)
            .negotiationType(options.tlsEnabled ? NegotiationType.TLS : NegotiationType.PLAINTEXT)
            .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance());
    if (sslContext != null) {
      builder.sslContext(sslContext);
      if (options.tlsAuthorityOverride != null) {
        builder.overrideAuthority(options.tlsAuthorityOverride);
      }
    }
    return builder.build();
  } catch (RuntimeException e) {
    // gRPC might throw all kinds of RuntimeExceptions: StatusRuntimeException,
    // IllegalStateException, NullPointerException, ...
    String message = "Failed to connect to '%s': %s";
    throw new IOException(String.format(message, target, e.getMessage()));
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:33,代码来源:GoogleAuthUtils.java

示例3: newNettyClientChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
private static NettyChannelBuilder newNettyClientChannel(Transport transport,
    SocketAddress address, boolean tls, boolean testca, int flowControlWindow,
    boolean useDefaultCiphers) throws IOException {
  NettyChannelBuilder builder =
      NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow);
  if (tls) {
    builder.negotiationType(NegotiationType.TLS);
    SslContext sslContext = null;
    if (testca) {
      File cert = TestUtils.loadCert("ca.pem");
      SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient().trustManager(cert);
      if (transport == Transport.NETTY_NIO) {
        sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.JDK);
      } else {
        // Native transport with OpenSSL
        sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.OPENSSL);
      }
      if (useDefaultCiphers) {
        sslContextBuilder.ciphers(null);
      }
      sslContext = sslContextBuilder.build();
    }
    builder.sslContext(sslContext);
  } else {
    builder.negotiationType(NegotiationType.PLAINTEXT);
  }

  DefaultThreadFactory tf = new DefaultThreadFactory("client-elg-", true /*daemon */);
  switch (transport) {
    case NETTY_NIO:
      builder
          .eventLoopGroup(new NioEventLoopGroup(0, tf))
          .channelType(NioSocketChannel.class);
      break;

    case NETTY_EPOLL:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollSocketChannel.class);
      break;

    case NETTY_UNIX_DOMAIN_SOCKET:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollDomainSocketChannel.class);
      break;

    default:
      // Should never get here.
      throw new IllegalArgumentException("Unsupported transport: " + transport);
  }
  return builder;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:56,代码来源:Utils.java


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