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


Java NettyChannelBuilder.build方法代码示例

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


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

示例1: before

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
/**
 * Before the test has started, create the server and channel.
 */
@Override
protected void before() throws Throwable {
    serviceRegistry = new MutableHandlerRegistry();

    NettyServerBuilder serverBuilder = NettyServerBuilder
            .forPort(0)
            .fallbackHandlerRegistry(serviceRegistry);

    if (useDirectExecutor) {
        serverBuilder.directExecutor();
    }

    configureServerBuilder.accept(serverBuilder);
    server = serverBuilder.build().start();
    port = server.getPort();

    NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress("localhost", port).usePlaintext(true);
    configureChannelBuilder.accept(channelBuilder);
    channel = channelBuilder.build();
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:24,代码来源:NettyGrpcServerRule.java

示例2: createChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
@Override
protected ManagedChannel createChannel() {
  try {
    NettyChannelBuilder builder = NettyChannelBuilder
        .forAddress(TestUtils.testServerAddress(getPort()))
        .flowControlWindow(65 * 1024)
        .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
        .sslContext(GrpcSslContexts
            .forClient()
            .keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key"))
            .trustManager(TestUtils.loadX509Cert("ca.pem"))
            .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
            .sslProvider(SslProvider.OPENSSL)
            .build());
    io.grpc.internal.TestingAccessor.setStatsImplementation(
        builder, createClientCensusStatsModule());
    return builder.build();
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:Http2NettyTest.java

示例3: initCache

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
private static LoadingCache<UserAuth, String> initCache() {
  try {
    currentAuth = ApprcHolder.get().currentAuth();
    URI uri = new URI(currentAuth.getApiserver());
    logger.info(String.format("Connecting to apiserver: %s  host: %s  port: %s",
        currentAuth.getApiserver(), uri.getHost(), uri.getPort()));
    NettyChannelBuilder builder = NettyChannelBuilder
        .forAddress(uri.getHost(), uri.getPort())
        .nameResolverFactory(new DnsNameResolverProvider());
    if (useTLS(currentAuth)) {
      File trustCertCollectionFile = null;
      builder
          .sslContext(GrpcSslContexts.forClient().trustManager(trustCertCollectionFile).build())
          .negotiationType(NegotiationType.TLS);
    } else {
      builder.negotiationType(NegotiationType.PLAINTEXT);
    }
    channel = builder.build();
    return CacheBuilder.newBuilder()
        .expireAfterAccess(DESCRIPTOR.getAuthCacheTtl(), TimeUnit.SECONDS)
        .build(
            new CacheLoader<UserAuth, String>() {
              @Override
              public String load(UserAuth key) throws Exception {
                if (isToken(key.getSecret())) {
                  return checkToken(key.getUsername(),
                      key.getSecret().substring(BEARER_PREFIX.length()));
                }
                return checkPassword(key.getUsername(), key.getSecret());
              }
            }
        );
  } catch (URISyntaxException | SSLException e) {
    logger.log(Level.SEVERE, e.getMessage());
  }
  return null;
}
 
开发者ID:appscode-ci,项目名称:appscode-login-plugin,代码行数:38,代码来源:AppsCodeSecurityRealm.java

示例4: createChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
public Channel createChannel(HostAndPort endpoint) {
  NettyChannelBuilder nettyChannelBuilder = createChannelBuilder(endpoint);

  if (!callConfiguration.getTlsClientOverrideAuthority().isEmpty()) {
    nettyChannelBuilder.overrideAuthority(callConfiguration.getTlsClientOverrideAuthority());
  }

  return nettyChannelBuilder.build();
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:10,代码来源:ChannelFactory.java

示例5: 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

示例6: createChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
@Override
protected ManagedChannel createChannel() {
  NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", getPort())
      .negotiationType(NegotiationType.PLAINTEXT)
      .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
  io.grpc.internal.TestingAccessor.setStatsImplementation(
      builder, createClientCensusStatsModule());
  return builder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:10,代码来源:AutoWindowSizingOnTest.java

示例7: createChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
@Override
protected ManagedChannel createChannel() {
  NettyChannelBuilder builder = NettyChannelBuilder
      .forAddress(new LocalAddress("in-process-1"))
      .negotiationType(NegotiationType.PLAINTEXT)
      .channelType(LocalChannel.class)
      .flowControlWindow(65 * 1024)
      .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
  io.grpc.internal.TestingAccessor.setStatsImplementation(
      builder, createClientCensusStatsModule());
  return builder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:13,代码来源:Http2NettyLocalChannelTest.java

示例8: createChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
private static ManagedChannel createChannel(String target) {
  NettyChannelBuilder builder =
      NettyChannelBuilder.forTarget(target)
          .negotiationType(NegotiationType.PLAINTEXT);
  return builder.build();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:7,代码来源:Worker.java

示例9: createNettyChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
/**
 * <p>
 * createNettyChannel.
 * </p>
 *
 * @param interceptors a {@link List} object.
 * @param globalClientOptions a {@link ClientOptions} object.
 * @return a {@link ManagedChannel} object.
 * @throws SSLException if any.
 * @throws IOException if any.
 */
private ManagedChannel createNettyChannel(ClientOptions clientOptions, List<ClientInterceptor> interceptors) throws SSLException, IOException {
 
  NettyChannelBuilder builder = NettyChannelBuilder.forTarget(clientOptions.getServiceEndpoint());
  // 这里要注意下由于java版本的没有提供像go那样的可以指定域名
  // java版本源代码中把host传入作为证书域名
  // 域名是在证书生成的过程中自己输入的
  //String serverHostOverride = "localhost";
  if (clientOptions.getServerHostOverride() != null) {
    // Force the hostname to match the cert the server uses.
    builder.overrideAuthority(clientOptions.getServerHostOverride());
  }
  if (clientOptions.isUsedTls()) {
    builder
        .sslContext(
            GrpcSslContexts.forClient().trustManager(SslUtils.loadCert("server.pem")).build())
        .negotiationType(NegotiationType.TLS);
  }   
  builder
      .nameResolverFactory(AbstractNameResolverProvider.provider()
              .withRegistryCenterAddress(clientOptions.getRegistryCenterAddress())
              .withZoneToPrefer(clientOptions.getZoneToPrefer())
              .withServiceEndpoint(clientOptions.getServiceEndpoint())
              .withUsedTls(clientOptions.isUsedTls()))
      .loadBalancerFactory(GrpclbLoadBalancerFactory.getInstance())
      //The TCP connections are shutdown when you shutdown the Channel. 
      //Specify an idleTimeout() to have the Channel automatically close the TCP connection after a period of inactivity.
      .idleTimeout(Long.MAX_VALUE, TimeUnit.SECONDS)
      .maxInboundMessageSize(MAX_MESSAGE_SIZE)
      //.sslContext(createSslContext())
      //TODO: Caused run unit testing error happen in maven if comment out below 1 line code!!!
      //.eventLoopGroup(RpcSharedThreadPools.getInstance().getElg())
      .executor(RpcSharedThreadPools.getInstance().getBatchThreadPool())
      // .userAgent(VersionInfo.CORE_UESR_AGENT + "," + options.getUserAgent())
      .flowControlWindow(FLOW_CONTROL_WINDOW)
      .intercept(new HeaderClientInterceptor(),
          new StubDeadlineClientInterceptor());
  if(interceptors != null && interceptors.size() > 0){
    builder.intercept(interceptors);
  }
  return builder.build();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:53,代码来源:GrpcClientInitializer.java


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