Search in sources :

Example 11 with ManagedChannel

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);
        }
    }
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ManagedChannel(io.grpc.ManagedChannel) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with ManagedChannel

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) ManagedChannel(io.grpc.ManagedChannel) URL(java.net.URL)

Example 13 with ManagedChannel

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();
}
Also used : GraknSession(ai.grakn.GraknSession) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Example 14 with ManagedChannel

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();
}
Also used : HelloResponse(org.baeldung.grpc.HelloResponse) ManagedChannel(io.grpc.ManagedChannel) HelloServiceGrpc(org.baeldung.grpc.HelloServiceGrpc)

Example 15 with ManagedChannel

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());
}
Also used : Status(io.grpc.Status) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentServiceGrpc(org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc) DnsNameResolverProvider(io.grpc.internal.DnsNameResolverProvider) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Downstream(org.apache.skywalking.apm.network.proto.Downstream)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)163 Test (org.junit.Test)92 CountDownLatch (java.util.concurrent.CountDownLatch)26 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)26 ArrayList (java.util.ArrayList)20 Metadata (io.grpc.Metadata)18 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)15 ExecutorService (java.util.concurrent.ExecutorService)13 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)11 StreamObserver (io.grpc.stub.StreamObserver)10 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)10 CallOptions (io.grpc.CallOptions)9 Subchannel (io.grpc.LoadBalancer.Subchannel)9 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)9 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)9 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)9