本文整理汇总了Java中io.grpc.ManagedChannel.shutdownNow方法的典型用法代码示例。如果您正苦于以下问题:Java ManagedChannel.shutdownNow方法的具体用法?Java ManagedChannel.shutdownNow怎么用?Java ManagedChannel.shutdownNow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.ManagedChannel
的用法示例。
在下文中一共展示了ManagedChannel.shutdownNow方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serverRunsAndRespondsCorrectly
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
@Test
public void serverRunsAndRespondsCorrectly() throws ExecutionException,
IOException,
InterruptedException,
TimeoutException {
final String name = UUID.randomUUID().toString();
Server server = ServerBuilder.forPort(9999)
.addService(new GreeterImpl())
.build();
server.start();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
.usePlaintext(true)
.build();
GreeterGrpc8.GreeterCompletableFutureStub stub = GreeterGrpc8.newCompletableFutureStub(channel);
CompletableFuture<HelloResponse> response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
await().atMost(3, TimeUnit.SECONDS).until(() -> response.isDone() && response.get().getMessage().contains(name));
channel.shutdown();
channel.awaitTermination(1, TimeUnit.MINUTES);
channel.shutdownNow();
server.shutdown();
server.awaitTermination(1, TimeUnit.MINUTES);
server.shutdownNow();
}
示例2: shutdown
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
synchronized void shutdown(boolean force) {
if (shutdown) {
return;
}
shutdown = true;
ManagedChannel lchannel = managedChannel;
managedChannel = null;
if (lchannel == null) {
return;
}
if (force) {
lchannel.shutdownNow();
} else {
boolean isTerminated = false;
try {
isTerminated = lchannel.shutdown().awaitTermination(3, TimeUnit.SECONDS);
} catch (Exception e) {
logger.debug(e); //best effort
}
if (!isTerminated) {
lchannel.shutdownNow();
}
}
}
示例3: disconnectChannel
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
@Override
public void disconnectChannel(GrpcChannelId channelId) {
checkNotNull(channelId);
Lock lock = channelLocks.computeIfAbsent(channelId, k -> new ReentrantLock());
lock.lock();
try {
if (!channels.containsKey(channelId)) {
// Nothing to do.
return;
}
ManagedChannel channel = channels.get(channelId);
try {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.warn("Channel {} didn't shut down in time.");
channel.shutdownNow();
}
channels.remove(channelId);
} finally {
lock.unlock();
}
}
示例4: doClient
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
public String doClient(String name) {
ManagedChannel channel = InProcessChannelBuilder
.forName("GradleProof")
.build();
try {
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloResponse response = stub.sayHello(request);
return response.getMessage();
} finally {
channel.shutdownNow();
}
}
示例5: main
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
public static void main(String[] args) {
ManagedChannel goodbyeChannel = ManagedChannelBuilder.forAddress("localhost", 9090)
.usePlaintext(true)
.intercept(new BraveGrpcClientInterceptor(Constant.brave("client-example")))
.intercept(MonitoringClientInterceptor.create(Configuration.allMetrics()))
.build();
for (int i = 0; i < 100; i++) {
GoodbyeServiceGrpc.GoodbyeServiceBlockingStub stub = GoodbyeServiceGrpc.newBlockingStub(goodbyeChannel);
GoodbyeResponse goodbye = stub.goodbye(GoodbyeRequest.newBuilder().setName("Ray").build());
System.out.println(goodbye);
}
goodbyeChannel.shutdownNow();
}
示例6: shutdown
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
synchronized void shutdown(boolean force) {
if (shutdown) {
return;
}
shutdown = true;
ManagedChannel lchannel = managedChannel;
// let all referenced resource finalize
managedChannel = null;
blockingStub = null;
futureStub = null;
if (lchannel == null) {
return;
}
if (force) {
lchannel.shutdownNow();
} else {
boolean isTerminated = false;
try {
isTerminated = lchannel.shutdown().awaitTermination(3, TimeUnit.SECONDS);
} catch (Exception e) {
logger.debug(e); //best effort
}
if (!isTerminated) {
lchannel.shutdownNow();
}
}
}
示例7: testDefaultChannel
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
@Test
public void testDefaultChannel() {
Endpoints.ApiServiceDescriptor apiServiceDescriptor =
Endpoints.ApiServiceDescriptor.newBuilder().setUrl("localhost:123").build();
ManagedChannel channel =
ManagedChannelFactory.createDefault().forDescriptor(apiServiceDescriptor);
assertEquals("localhost:123", channel.authority());
channel.shutdownNow();
}
示例8: uncompressedClient_compressedEndpoint
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
@Test
public void uncompressedClient_compressedEndpoint() throws Exception {
ManagedChannel nonDecompressingChannel =
ManagedChannelBuilder.forAddress("127.0.0.1", server.httpPort())
.decompressorRegistry(
DecompressorRegistry.emptyInstance()
.with(Codec.Identity.NONE, false))
.usePlaintext(true)
.build();
UnitTestServiceBlockingStub client = UnitTestServiceGrpc.newBlockingStub(nonDecompressingChannel);
assertThat(client.staticUnaryCallSetsMessageCompression(REQUEST_MESSAGE))
.isEqualTo(RESPONSE_MESSAGE);
nonDecompressingChannel.shutdownNow();
}
示例9: main
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ManagedChannel channel = GenomicsChannel.fromDefaultCreds();
// Regular RPC example: list all reference set assembly ids.
ReferenceServiceV1BlockingStub refStub =
ReferenceServiceV1Grpc.newBlockingStub(channel);
SearchReferenceSetsRequest request =
SearchReferenceSetsRequest.newBuilder().build();
SearchReferenceSetsResponse response = refStub.searchReferenceSets(request);
for (ReferenceSet rs : response.getReferenceSetsList()) {
System.out.println(rs.getAssemblyId());
}
// Streaming RPC example: request the variants within BRCA1 for the Platinum Genomes variant set.
StreamingVariantServiceBlockingStub varStub =
StreamingVariantServiceGrpc.newBlockingStub(channel);
StreamVariantsRequest varRequest = StreamVariantsRequest.newBuilder()
.setVariantSetId("3049512673186936334")
.setReferenceName("chr17")
.setStart(41196311)
.setEnd(41277499)
.build();
try {
Iterator<StreamVariantsResponse> iter = varStub.streamVariants(varRequest);
while (iter.hasNext()) {
StreamVariantsResponse varResponse = iter.next();
System.out.println("Response:");
System.out.println(varResponse.toString());
System.out.println();
}
System.out.println("Done");
} finally {
channel.shutdownNow();
}
}
示例10: shutdown
import io.grpc.ManagedChannel; //导入方法依赖的package包/类
private void shutdown(ManagedChannel mc) throws Exception {
mc.shutdownNow();
assertTrue(mc.awaitTermination(1, TimeUnit.SECONDS));
}