當前位置: 首頁>>代碼示例>>Java>>正文


Java ManagedChannel.shutdownNow方法代碼示例

本文整理匯總了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();
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:32,代碼來源:CompletableFutureEndToEndTest.java

示例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();
            }
        }
    }
 
開發者ID:hyperledger,項目名稱:fabric-sdk-java,代碼行數:27,代碼來源:OrdererClient.java

示例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();
    }
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:27,代碼來源:GrpcControllerImpl.java

示例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();
    }
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:14,代碼來源:GradleProof.java

示例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();
}
 
開發者ID:saturnism,項目名稱:grpc-java-by-example,代碼行數:15,代碼來源:ZipkinExampleClient.java

示例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();
        }
    }
}
 
開發者ID:hyperledger,項目名稱:fabric-sdk-java,代碼行數:30,代碼來源:EndorserClient.java

示例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();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:10,代碼來源:ManagedChannelFactoryTest.java

示例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();
}
 
開發者ID:line,項目名稱:armeria,代碼行數:15,代碼來源:GrpcServiceServerTest.java

示例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();
  }
}
 
開發者ID:googlegenomics,項目名稱:utils-java,代碼行數:37,代碼來源:Example.java

示例10: shutdown

import io.grpc.ManagedChannel; //導入方法依賴的package包/類
private void shutdown(ManagedChannel mc) throws Exception {
  mc.shutdownNow();
  assertTrue(mc.awaitTermination(1, TimeUnit.SECONDS));
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:5,代碼來源:NettyChannelBuilderTest.java


注:本文中的io.grpc.ManagedChannel.shutdownNow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。