本文整理匯總了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);
}
示例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() + ">");
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
示例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 + ">");
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}