• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NegotiationType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.grpc.netty.NegotiationType的典型用法代码示例。如果您正苦于以下问题:Java NegotiationType类的具体用法?Java NegotiationType怎么用?Java NegotiationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NegotiationType类属于io.grpc.netty包,在下文中一共展示了NegotiationType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: connectPlugin

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public void connectPlugin(String host, int port) {
    ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
            .negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
            .keepAliveTime(1, TimeUnit.MINUTES)
            .keepAliveTimeout(5, TimeUnit.SECONDS)
            .directExecutor()
            .channelType(EpollSocketChannel.class)
            .eventLoopGroup(new EpollEventLoopGroup())
            .build();

    PluginManagerGrpc.PluginManagerBlockingStub blocking = PluginManagerGrpc.newBlockingStub(channel);
    PluginManagerGrpc.PluginManagerStub async = PluginManagerGrpc.newStub(channel);

    ServiceConnection connection = ServiceConnection.builder()
            .channel(channel)
            .blockingStub(blocking)
            .asyncStub(async)
            .build();

    this.pluginConnections.put(PLUGIN_MANAGER, connection);
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:22,代码来源:PluginGrpcServer.java


示例2: getGenomicsManagedChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private static ManagedChannel getGenomicsManagedChannel(List<ClientInterceptor> interceptors)
    throws SSLException {
  // Java 8's implementation of GCM ciphers is extremely slow. Therefore we disable
  // them here.
  List<String> defaultCiphers = GrpcSslContexts.forClient().ciphers(null).build().cipherSuites();
  List<String> performantCiphers = new ArrayList<>();
  for (String cipher : defaultCiphers) {
    if (!cipher.contains("GCM")) {
      performantCiphers.add(cipher);
    }
  }

  return NettyChannelBuilder.forAddress(GENOMICS_ENDPOINT, 443)
      .negotiationType(NegotiationType.TLS)
      .sslContext(GrpcSslContexts.forClient().ciphers(performantCiphers).build())
      .intercept(interceptors)
      .build();
}
 
开发者ID:googlegenomics,项目名称:utils-java,代码行数:19,代码来源:GenomicsChannel.java


示例3: MemberServiceImpl

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public MemberServiceImpl(String host, int port, Crypto crypto) {
    Preconditions.checkNotNull(host);
    Preconditions.checkNotNull(port);

    InetAddress address = null;
    try {
        address = InetAddress.getByName(host);
    } catch (UnknownHostException e) {
        logger.error("Create member service failed by unknown host exception", e);
        Throwables.propagate(e);
    }

    final Channel channel = NettyChannelBuilder
            .forAddress(new InetSocketAddress(address, port))
            .negotiationType(NegotiationType.PLAINTEXT)
            .build();

    initializeStubs(channel);
    this.crypto = crypto;
}
 
开发者ID:GrapeBaBa,项目名称:fabric-java,代码行数:21,代码来源:MemberServiceImpl.java


示例4: newClient

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
@Override
public PubsubClient newClient(
    @Nullable String timestampAttribute, @Nullable String idAttribute, PubsubOptions options)
    throws IOException {
  ManagedChannel channel = NettyChannelBuilder
      .forAddress(PUBSUB_ADDRESS, PUBSUB_PORT)
      .negotiationType(NegotiationType.TLS)
      .sslContext(GrpcSslContexts.forClient().ciphers(null).build())
      .build();

  return new PubsubGrpcClient(timestampAttribute,
                              idAttribute,
                              DEFAULT_TIMEOUT_S,
                              channel,
                              options.getGcpCredential());
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:PubsubGrpcClient.java


示例5: newClientChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel newClientChannel() throws CertificateException, IOException {
  File clientCertChainFile = TestUtils.loadCert("client.pem");
  File clientPrivateKeyFile = TestUtils.loadCert("client.key");
  X509Certificate[] clientTrustedCaCerts = {
    TestUtils.loadX509Cert("ca.pem")
  };

  SslContext sslContext =
      GrpcSslContexts.forClient()
                     .keyManager(clientCertChainFile, clientPrivateKeyFile)
                     .trustManager(clientTrustedCaCerts)
                     .build();

  return NettyChannelBuilder.forAddress("localhost", server.getPort())
      .overrideAuthority(TestUtils.TEST_SERVER_HOST)
      .negotiationType(NegotiationType.TLS)
      .sslContext(sslContext)
      .build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:ConcurrencyTest.java


示例6: newOkhttpClientChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private static OkHttpChannelBuilder newOkhttpClientChannel(
    SocketAddress address, boolean tls, boolean testca, @Nullable String authorityOverride) {
  InetSocketAddress addr = (InetSocketAddress) address;
  OkHttpChannelBuilder builder =
      OkHttpChannelBuilder.forAddress(addr.getHostName(), addr.getPort());
  if (tls) {
    builder.negotiationType(io.grpc.okhttp.NegotiationType.TLS);
    SSLSocketFactory factory;
    if (testca) {
      builder.overrideAuthority(
          GrpcUtil.authorityFromHostAndPort(authorityOverride, addr.getPort()));
      try {
        factory = TestUtils.newSslSocketFactoryForCa(
            Platform.get().getProvider(),
            TestUtils.loadCert("ca.pem"));
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } else {
      factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
    builder.sslSocketFactory(factory);
  } else {
    builder.negotiationType(io.grpc.okhttp.NegotiationType.PLAINTEXT);
  }
  return builder;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:28,代码来源:Utils.java


示例7: MyServiceClient

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
/**
 * Constructor for the client.
 * @param host The host to connect to for the server
 * @param port The port to connect to on the host server
 */
public MyServiceClient(String host, int port) {
  InetAddress address;
  try {
    address = InetAddress.getByName(host);
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
  managedChannel = NettyChannelBuilder.forAddress(new InetSocketAddress(address,port))
      .flowControlWindow(65 * 1024)
      .negotiationType(NegotiationType.PLAINTEXT).build();
  simpleBlockingStub = SimpleGrpc.newBlockingStub(managedChannel);
  lessSimpleBlockingStub = LessSimpleGrpc.newBlockingStub(managedChannel);
}
 
开发者ID:mavrukin,项目名称:grpc-base-gradle,代码行数:19,代码来源:MyServiceClient.java


示例8: initCache

import io.grpc.netty.NegotiationType; //导入依赖的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


示例9: addConnection

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void addConnection(ServiceType serviceType, String host, int port) {
    ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
            .negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
            .keepAliveTime(1, TimeUnit.MINUTES)
            .keepAliveTimeout(5, TimeUnit.SECONDS)
            .directExecutor()
            .channelType(EpollSocketChannel.class)
            .eventLoopGroup(new EpollEventLoopGroup())
            .build();

    AbstractStub blocking;
    AbstractStub async;

    switch (serviceType) {
        case WORLD: {
            blocking = WorldServiceGrpc.newBlockingStub(channel);
            async = WorldServiceGrpc.newStub(channel);
            break;
        }
        case PLUGIN_MANAGER: {
            blocking = PluginManagerGrpc.newBlockingStub(channel);
            async = PluginManagerGrpc.newStub(channel);
            break;
        }
        default: {
            throw new RuntimeException("Service type not handled: " + serviceType.name());
        }
    }

    ServiceConnection connection = ServiceConnection.builder()
            .channel(channel)
            .blockingStub(blocking)
            .asyncStub(async)
            .build();

    this.connections.put(serviceType, connection);
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:40,代码来源:JungleConnectorGrpcClient.java


示例10: createChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel createChannel(URI uri) {
    log.debug("Creating channel for {}", uri);
    int port = GrpcRemoteServiceServer.DEFAULT_LISTEN_PORT;
    if (uri.getPort() != -1) {
        port = uri.getPort();
    }
    return NettyChannelBuilder.forAddress(uri.getHost(), port)
            .negotiationType(NegotiationType.PLAINTEXT)
            .build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:11,代码来源:GrpcRemoteServiceProvider.java


示例11: createChannelBuilder

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private NettyChannelBuilder createChannelBuilder(HostAndPort endpoint) {
  if (!callConfiguration.getUseTls()) {
    return NettyChannelBuilder.forAddress(endpoint.getHostText(), endpoint.getPort())
        .negotiationType(NegotiationType.PLAINTEXT);
  } else {
    return NettyChannelBuilder.forAddress(endpoint.getHostText(), endpoint.getPort())
        .sslContext(createSslContext())
        .negotiationType(NegotiationType.TLS)
        .intercept(metadataInterceptor());
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:12,代码来源:ChannelFactory.java


示例12: GRPCClient

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public GRPCClient(String host, int port, int observerPort) {
    log.debug("Trying to connect to GRPC host:port={}:{}, host:observerPort={}:{}, ", host, port, observerPort);
    ManagedChannel channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build();
    ManagedChannel observerChannel = NettyChannelBuilder.forAddress(host, observerPort).negotiationType(NegotiationType.PLAINTEXT).build();
    pbs = PeerGrpc.newBlockingStub(channel);
    obs = OpenchainGrpc.newBlockingStub(channel);
    observer = new GRPCObserver(observerChannel);
    observer.connect();
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:10,代码来源:GRPCClient.java


示例13: getChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
/** Return {@link io.grpc.Channel} which is used by Cloud Pub/Sub gRPC API's. */
public static Channel getChannel() throws IOException {
  ManagedChannel channelImpl =
      NettyChannelBuilder.forAddress(ENDPOINT, 443).negotiationType(NegotiationType.TLS).build();
  final ClientAuthInterceptor interceptor =
      new ClientAuthInterceptor(
          GoogleCredentials.getApplicationDefault().createScoped(CPS_SCOPE),
          Executors.newCachedThreadPool());
  return ClientInterceptors.intercept(channelImpl, interceptor);
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:11,代码来源:ConnectorUtils.java


示例14: GRPCClient

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public GRPCClient(String host, int port, int observerPort) {
    log.debug("Trying to connect to GRPC host:port={}:{}, host:observerPort={}:{}, ", host, port, observerPort);
    ManagedChannel channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build();
    ManagedChannel observerChannel = NettyChannelBuilder.forAddress(host, observerPort).negotiationType(NegotiationType.PLAINTEXT).build();
    dbs = DevopsGrpc.newBlockingStub(channel);
    obs = OpenchainGrpc.newBlockingStub(channel);
    observer = new GRPCObserver(observerChannel);
    observer.connect();
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api,代码行数:10,代码来源:GRPCClient.java


示例15: main

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {

        if (args.length == 0) {
            System.err.println("Please specify your project name.");
            System.exit(1);
        }
        final String project = args[0];
        ManagedChannelImpl channelImpl = NettyChannelBuilder
            .forAddress("pubsub.googleapis.com", 443)
            .negotiationType(NegotiationType.TLS)
            .build();
        GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
        // Down-scope the credential to just the scopes required by the service
        creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
        // Intercept the channel to bind the credential
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, executor);
        Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
        // Create a stub using the channel that has the bound credential
        PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel);
        ListTopicsRequest request = ListTopicsRequest.newBuilder()
                .setPageSize(10)
                .setProject("projects/" + project)
                .build();
        ListTopicsResponse resp = publisherStub.listTopics(request);
        System.out.println("Found " + resp.getTopicsCount() + " topics.");
        for (Topic topic : resp.getTopicsList()) {
            System.out.println(topic.getName());
        }
    }
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:31,代码来源:Main.java


示例16: newChannel

import io.grpc.netty.NegotiationType; //导入依赖的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


示例17: createChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel createChannel(URI uri) {
    log.debug("Creating channel for {}", uri);
    int port = GrpcRemoteServiceServer.DEFAULT_LISTEN_PORT;
    if (uri.getPort() != -1) {
        port = uri.getPort();
    }
    return NettyChannelBuilder.forAddress(uri.getHost(), port)
            .negotiationType(NegotiationType.PLAINTEXT)
            // TODO Not ideal fix, gRPC discovers name resolvers
            // in the class path, but OSGi was preventing it.
            // Manually specifying the default dns resolver for now.
            .nameResolverFactory(new DnsNameResolverProvider())
            .build();
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:15,代码来源:GrpcRemoteServiceProvider.java


示例18: runTest

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private void runTest() throws Exception {
  try {
    controlChannel = NettyChannelBuilder.forAddress("127.0.0.1", serverControlPort)
        .negotiationType(NegotiationType.PLAINTEXT).build();
    controlStub = ReconnectServiceGrpc.newBlockingStub(controlChannel);
    if (useOkhttp) {
      retryChannel = OkHttpChannelBuilder.forAddress("127.0.0.1", serverRetryPort)
          .negotiationType(io.grpc.okhttp.NegotiationType.TLS).build();
    } else {
      retryChannel = NettyChannelBuilder.forAddress("127.0.0.1", serverRetryPort)
          .negotiationType(NegotiationType.TLS).build();
    }
    retryStub = ReconnectServiceGrpc.newBlockingStub(retryChannel);
    controlStub.start(Empty.getDefaultInstance());

    long startTimeStamp = System.currentTimeMillis();
    while ((System.currentTimeMillis() - startTimeStamp) < TEST_TIME_MS) {
      try {
        retryStub.start(Empty.getDefaultInstance());
      } catch (StatusRuntimeException expected) {
        // Make CheckStyle happy.
      }
      Thread.sleep(50);
    }
    ReconnectInfo info = controlStub.stop(Empty.getDefaultInstance());
    assertTrue(info.getPassed());
  } finally {
    controlChannel.shutdownNow();
    retryChannel.shutdownNow();
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:32,代码来源:ReconnectTestClient.java


示例19: createChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel createChannel() {
  InetAddress address;
  try {
    address = InetAddress.getByName(serverHost);
  } catch (UnknownHostException ex) {
    throw new RuntimeException(ex);
  }
  return NettyChannelBuilder.forAddress(new InetSocketAddress(address, serverPort))
      .negotiationType(NegotiationType.PLAINTEXT)
      .build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:12,代码来源:Http2Client.java


示例20: createChannel

import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel createChannel(InetSocketAddress address) {
  SslContext sslContext = null;
  if (useTestCa) {
    try {
      sslContext = GrpcSslContexts.forClient().trustManager(
          TestUtils.loadCert("ca.pem")).build();
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
  return NettyChannelBuilder.forAddress(address)
      .negotiationType(useTls ? NegotiationType.TLS : NegotiationType.PLAINTEXT)
      .sslContext(sslContext)
      .build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:16,代码来源:StressTestClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SpecificRequestor类代码示例发布时间:2022-05-21
下一篇:
Java Parser类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap