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


Java ManagedChannelBuilder.build方法代码示例

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


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

示例1: SeldonClientExample

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/** Construct client for accessing RouteGuide server using the existing channel. */
public SeldonClientExample(ManagedChannelBuilder<?> channelBuilder) {
 ClientInterceptor interceptor = new HeaderClientInterceptor();
  channel = channelBuilder.build();
  Channel interceptChannel = ClientInterceptors.intercept(channel, interceptor);
  blockingStub = SeldonGrpc.newBlockingStub(interceptChannel);
  asyncStub = SeldonGrpc.newStub(interceptChannel);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:9,代码来源:SeldonClientExample.java

示例2: open

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
public void open(boolean compressedConnection) throws IOException {

		ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forAddress(member.getServerAddress(), member.getExternalPort())
				.maxInboundMessageSize(256 * 1024 * 1024).usePlaintext(true);
		channel = managedChannelBuilder.build();

		blockingStub = ExternalServiceGrpc.newBlockingStub(channel);
		if (compressedConnection) {
			blockingStub = blockingStub.withCompression("gzip");
		}

		asyncStub = ExternalServiceGrpc.newStub(channel);
		if (compressedConnection) {
			asyncStub = asyncStub.withCompression("gzip");
		}

		System.err.println("INFO: Connecting to <" + member.getServerAddress() + ">");

	}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:20,代码来源:LumongoConnection.java

示例3: connectChannel

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
@Override
public ManagedChannel connectChannel(GrpcChannelId channelId,
                                     ManagedChannelBuilder<?> channelBuilder)
        throws IOException {
    checkNotNull(channelId);
    checkNotNull(channelBuilder);

    Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
    lock.lock();

    try {
        if (enableMessageLog) {
            channelBuilder.intercept(new InternalLogChannelInterceptor(channelId));
        }
        ManagedChannel channel = channelBuilder.build();
        // Forced connection not yet implemented. Use workaround...
        // channel.getState(true);
        doDummyMessage(channel);
        channels.put(channelId, channel);
        return channel;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:25,代码来源:GrpcControllerImpl.java

示例4: createChannel

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
@Override
protected ManagedChannel createChannel() {
  assertEquals(
      "jdk7 required",
      "1.7",
      System.getProperty("java.specification.version"));
  assertEquals(
      "Can not run in dev servers because they lack org.conscrypt.OpenSSLProvider support",
      "Production",
      System.getProperty("com.google.appengine.runtime.environment"));
  ManagedChannelBuilder<?> builder =
      ManagedChannelBuilder.forTarget(INTEROP_TEST_ADDRESS)
          .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
  assertTrue(builder instanceof OkHttpChannelBuilder);
  return builder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:OkHttpClientInteropServlet.java

示例5: build

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride,
    boolean useTls, @Nullable InputStream testCa, @Nullable String androidSocketFactoryTls) {
  ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port)
      .maxInboundMessageSize(16 * 1024 * 1024);
  if (serverHostOverride != null) {
    // Force the hostname to match the cert the server uses.
    channelBuilder.overrideAuthority(serverHostOverride);
  }
  if (useTls) {
    try {
      SSLSocketFactory factory;
      if (androidSocketFactoryTls != null) {
        factory = getSslCertificateSocketFactory(testCa, androidSocketFactoryTls);
      } else {
        factory = getSslSocketFactory(testCa);
      }
      ((OkHttpChannelBuilder) channelBuilder).negotiationType(NegotiationType.TLS);
      ((OkHttpChannelBuilder) channelBuilder).sslSocketFactory(factory);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  } else {
    channelBuilder.usePlaintext(true);
  }
  return channelBuilder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:TesterOkHttpChannelBuilder.java

示例6: AskerClient

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
public AskerClient() {
    ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forAddress("localhost", port)
            .usePlaintext(true);
    this.channel = channelBuilder.build();
    this.blockingStub = AskerGrpc.newBlockingStub(channel);
    this.asyncStub = AskerGrpc.newStub(channel);
}
 
开发者ID:altiplanogao,项目名称:rpc-comparison,代码行数:8,代码来源:FunctionTest.java

示例7: ControllerImpl

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/**
 * Creates a new instance of the Controller client class.
 *
 * @param channelBuilder The channel builder to connect to the service instance.
 * @param config         The configuration for this client implementation.
 * @param executor       The executor service to be used internally.
 */
@VisibleForTesting
public ControllerImpl(ManagedChannelBuilder<?> channelBuilder, final ControllerImplConfig config,
                      final ScheduledExecutorService executor) {
    Preconditions.checkNotNull(channelBuilder, "channelBuilder");
    this.executor = executor;
    this.retryConfig = Retry.withExpBackoff(config.getInitialBackoffMillis(), config.getBackoffMultiple(),
            config.getRetryAttempts(), config.getMaxBackoffMillis())
            .retryingOn(StatusRuntimeException.class)
            .throwingOn(Exception.class);

    // Create Async RPC client.
    this.channel = channelBuilder.build();
    this.client = ControllerServiceGrpc.newStub(this.channel);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:22,代码来源:ControllerImpl.java

示例8: EchoClient

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/** Construct client for accessing RouteGuide server using the existing channel. */
EchoClient(ManagedChannelBuilder<?> channelBuilder) {
  channel = channelBuilder.build();
  Metadata metadata = GrpcUtils.setupYarpcHeaders();
  metadata.put(
      Metadata.Key.of(GrpcUtils.ENCODING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER),
      PROTO_ENCODING);
  blockingStub =
      io.grpc.stub.MetadataUtils.attachHeaders(EchoGrpc.newBlockingStub(channel), metadata)
          .withDeadlineAfter(1000, TimeUnit.MILLISECONDS);
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:12,代码来源:EchoClient.java

示例9: run

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
@Override
public void run() {
    logger.debug("Selected collector grpc service running, reconnect:{}.", reconnect);
    if (reconnect) {
        if (RemoteDownstreamConfig.Collector.GRPC_SERVERS.size() > 0) {
            String server = "";
            try {
                int index = Math.abs(random.nextInt()) % RemoteDownstreamConfig.Collector.GRPC_SERVERS.size();
                server = RemoteDownstreamConfig.Collector.GRPC_SERVERS.get(index);
                String[] ipAndPort = server.split(":");
                ManagedChannelBuilder<?> channelBuilder =
                    NettyChannelBuilder.forAddress(ipAndPort[0], Integer.parseInt(ipAndPort[1]))
                        .nameResolverFactory(new DnsNameResolverProvider())
                        .maxInboundMessageSize(1024 * 1024 * 50)
                        .usePlaintext(true);
                managedChannel = channelBuilder.build();
                if (!managedChannel.isShutdown() && !managedChannel.isTerminated()) {
                    reconnect = false;
                    notify(GRPCChannelStatus.CONNECTED);
                } else {
                    notify(GRPCChannelStatus.DISCONNECT);
                }
                return;
            } catch (Throwable t) {
                logger.error(t, "Create channel to {} fail.", server);
                notify(GRPCChannelStatus.DISCONNECT);
            }
        }

        logger.debug("Selected collector grpc service is not available. Wait {} seconds to retry", Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL);
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:33,代码来源:GRPCChannelManager.java

示例10: main

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    ManagedChannelBuilder<?> channelBuilder =
        NettyChannelBuilder.forAddress("127.0.0.1", 8080)
            .nameResolverFactory(new DnsNameResolverProvider())
            .maxInboundMessageSize(1024 * 1024 * 50)
            .usePlaintext(true);
    ManagedChannel channel = channelBuilder.build();
    TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel);
    final Status[] status = {null};
    StreamObserver<UpstreamSegment> streamObserver = serviceStub.collect(new StreamObserver<Downstream>() {
        @Override public void onNext(Downstream value) {

        }

        @Override public void onError(Throwable t) {
            status[0] = ((StatusRuntimeException)t).getStatus();
        }

        @Override public void onCompleted() {

        }
    });

    streamObserver.onNext(null);
    streamObserver.onCompleted();

    Thread.sleep(2 * 1000);

    Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode());
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:31,代码来源:GRPCNoServerTest.java

示例11: InternalRpcConnection

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
public InternalRpcConnection(String memberAddress, int internalServicePort) {
	this.memberAddress = memberAddress;
	this.internalServicePort = internalServicePort;

	ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forAddress(memberAddress, internalServicePort)
			.maxInboundMessageSize(256 * 1024 * 1024).usePlaintext(true);
	channel = managedChannelBuilder.build();

	blockingStub = InternalServiceGrpc.newBlockingStub(channel);

	log.info("Connecting to <" + memberAddress + ":" + internalServicePort + ">");
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:13,代码来源:InternalRpcConnection.java

示例12: createChannel

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
@Override
protected ManagedChannel createChannel() {
  assertEquals(
      "jdk8 required",
      "1.8",
      System.getProperty("java.specification.version"));
  ManagedChannelBuilder<?> builder =
      ManagedChannelBuilder.forTarget(INTEROP_TEST_ADDRESS)
          .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
  assertTrue(builder instanceof NettyChannelBuilder);
  ((NettyChannelBuilder) builder).flowControlWindow(65 * 1024);
  return builder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:14,代码来源:NettyClientInteropServlet.java

示例13: newClientChannel

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/**
 * Create a {@link ManagedChannel} for the given parameters.
 */
public static ManagedChannel newClientChannel(Transport transport, SocketAddress address,
      boolean tls, boolean testca, @Nullable String authorityOverride, boolean useDefaultCiphers,
      int flowControlWindow, boolean directExecutor) {
  ManagedChannelBuilder<?> builder;
  if (transport == Transport.OK_HTTP) {
    builder = newOkhttpClientChannel(address, tls, testca, authorityOverride);
  } else {
    try {
      builder = newNettyClientChannel(
          transport, address, tls, testca, flowControlWindow, useDefaultCiphers);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  if (authorityOverride != null) {
    builder.overrideAuthority(authorityOverride);
  }

  if (directExecutor) {
    builder.directExecutor();
  } else {
    // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
    // put.  Move it somewhere else, or remove it if no longer necessary.
    // See: https://github.com/grpc/grpc-java/issues/2119
    builder.executor(getExecutor());
  }

  return builder.build();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:33,代码来源:Utils.java

示例14: SeldonClientExample

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/** Construct client for accessing RouteGuide server using the existing channel. */
public SeldonClientExample(ManagedChannelBuilder<?> channelBuilder) {
  channel = channelBuilder.build();
  blockingStub = SeldonGrpc.newBlockingStub(channel);
  asyncStub = SeldonGrpc.newStub(channel);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:7,代码来源:SeldonClientExample.java

示例15: RouteGuideClient

import io.grpc.ManagedChannelBuilder; //导入方法依赖的package包/类
/** Construct client for accessing RouteGuide server using the existing channel. */
public RouteGuideClient(ManagedChannelBuilder<?> channelBuilder) {
  channel = channelBuilder.build();
  blockingStub = RouteGuideGrpc.newBlockingStub(channel);
  asyncStub = RouteGuideGrpc.newStub(channel);
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:7,代码来源:RouteGuideClient.java


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