use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project google-cloud-java by GoogleCloudPlatform.
the class SpannerImpl method close.
@Override
public void close() {
List<ListenableFuture<Void>> closureFutures = null;
synchronized (this) {
Preconditions.checkState(!spannerIsClosed, "Cloud Spanner client has been closed");
spannerIsClosed = true;
closureFutures = new ArrayList<>();
for (DatabaseClientImpl dbClient : dbClients.values()) {
closureFutures.add(dbClient.closeAsync());
}
dbClients.clear();
}
try {
Futures.successfulAsList(closureFutures).get();
} catch (InterruptedException | ExecutionException e) {
throw SpannerExceptionFactory.newSpannerException(e);
}
for (ManagedChannel channel : getOptions().getRpcChannels()) {
try {
channel.shutdown();
} catch (RuntimeException e) {
logger.log(Level.WARNING, "Failed to close channel", e);
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project google-cloud-java by GoogleCloudPlatform.
the class SpannerOptions method createChannel.
private static ManagedChannel createChannel(String rootUrl, RpcChannelFactory factory) {
URL url;
try {
url = new URL(rootUrl);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid host: " + rootUrl, e);
}
ManagedChannel channel = factory.newChannel(url.getHost(), url.getPort() > 0 ? url.getPort() : url.getDefaultPort());
return channel;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grakn by graknlabs.
the class RemoteGraknSessionTest method whenClosingASession_ShutdownTheChannel.
@Test
public void whenClosingASession_ShutdownTheChannel() {
ManagedChannel channel = mock(ManagedChannel.class);
GraknSession ignored = RemoteGraknSession.create(KEYSPACE, URI, channel);
ignored.close();
verify(channel).shutdown();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project tutorials by eugenp.
the class GrpcClient method main.
public static void main(String[] args) throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080).usePlaintext(true).build();
HelloServiceGrpc.HelloServiceBlockingStub stub = HelloServiceGrpc.newBlockingStub(channel);
HelloResponse helloResponse = stub.hello(HelloRequest.newBuilder().setFirstName("Baeldung").setLastName("gRPC").build());
System.out.println("Response received from server:\n" + helloResponse);
channel.shutdown();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project incubator-skywalking by apache.
the class GRPCNoServerTest method main.
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());
}
Aggregations