本文整理匯總了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));
}