当前位置: 首页>>代码示例>>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;未经允许,请勿转载。