@java.lang.Override @java.lang.SuppressWarnings("unchecked") public io.grpc.stub.StreamObserver<Req> invoke( io.grpc.stub.StreamObserver<Resp> responseObserver) { switch (methodId) { case METHODID_FULL_DUPLEX_CALL: io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingOutputCallRequest> request0 = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingOutputCallRequest>create(); serviceImpl.fullDuplexCall( io.vertx.grpc.GrpcBidiExchange.<io.vertx.example.grpc.Messages.StreamingOutputCallRequest, io.vertx.example.grpc.Messages.StreamingOutputCallResponse>create( request0, (io.grpc.stub.StreamObserver<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>) responseObserver)); return (io.grpc.stub.StreamObserver<Req>) request0.readObserver(); default: throw new AssertionError(); } } }
@Override public void recordRoute(GrpcReadStream<Point> request, Future<RouteSummary> response) { request.exceptionHandler(err -> { System.out.println("recordRoute cancelled"); }); RouteRecorder recorder = new RouteRecorder(); request.handler(recorder::append); request.endHandler(v -> { response.complete(recorder.build()); }); }
/** * <pre> * A client-to-server streaming RPC. * Accepts a stream of Points on a route being traversed, returning a * RouteSummary when traversal is completed. * </pre> */ public void recordRoute(io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.Point> request, io.vertx.core.Future<io.grpc.examples.routeguide.RouteSummary> response) { request.setReadObserver(asyncUnimplementedStreamingCall(getRecordRouteMethod(), RouteGuideGrpc.toObserver(response.completer()))); }
@Override public void streamingInputCall(GrpcReadStream<Messages.StreamingInputCallRequest> request, Future<Messages.StreamingInputCallResponse> future) { request.handler(payload -> { System.out.println(payload.getPayload().getType().getNumber()); }).endHandler(v -> { System.out.println("Request has ended."); future.complete(Messages.StreamingInputCallResponse.newBuilder().build()); }); } };
@Override public StreamObserver<I> readObserver() { return readStream.readObserver(); }
public GrpcBidiExchangeImpl(StreamObserver<I> readObserver, StreamObserver<O> writeObserver) { readStream = GrpcReadStream.create(readObserver); writeStream = GrpcWriteStream.create(writeObserver); }
@Override public GrpcBidiExchange<I, O> exceptionHandler(Handler<Throwable> handler) { readStream.exceptionHandler(handler); return this; }
@Override public GrpcBidiExchange<I, O> handler(Handler<I> handler) { readStream.handler(handler); return this; }
@Override public GrpcBidiExchange<I, O> endHandler(Handler<Void> handler) { readStream.endHandler(handler); return this; }
@Override public GrpcBidiExchange<I, O> fetch(long amount) { readStream.fetch(amount); return this; }
@Override public void start() throws Exception { // Create the channel ManagedChannel channel = VertxChannelBuilder .forAddress(vertx, "localhost", 8080) .usePlaintext(true) .build(); // Get a stub to use for interacting with the remote service ConsumerServiceGrpc.ConsumerServiceVertxStub stub = ConsumerServiceGrpc.newVertxStub(channel); // Make a request Messages.StreamingOutputCallRequest request = Messages .StreamingOutputCallRequest .newBuilder() .build(); // Call the remote service stub.streamingOutputCall(request, stream -> { stream.handler(response -> { System.out .println(new String(response.getPayload().toByteArray(), Charset.forName("UTF-8"))); }).endHandler(v -> { System.out.println("Response has ended."); }); }); } }
/** * <pre> * One request followed by a sequence of responses (streamed download). * The server returns the payload with client desired type and sizes. * </pre> */ public void streamingOutputCall(io.vertx.example.grpc.Messages.StreamingOutputCallRequest request, io.vertx.core.Handler<io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>> handler) { final io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingOutputCallResponse> readStream = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>create(); handler.handle(readStream); asyncServerStreamingCall( getChannel().newCall(getStreamingOutputCallMethod(), getCallOptions()), request, readStream.readObserver()); } }
public GrpcUniExchangeImpl(GrpcReadStream<I> readStream, StreamObserver<O> writeObserver) { this.writeStream = GrpcWriteStream.create(writeObserver); readStream.endHandler(v -> { if (complete.compareAndSet(false, true)) { if (GrpcUniExchangeImpl.this.handler != null) { GrpcUniExchangeImpl.this.handler.handle(Future.succeededFuture()); } } }); readStream.handler(input -> { if (complete.compareAndSet(false, true)) { if (GrpcUniExchangeImpl.this.handler != null) { GrpcUniExchangeImpl.this.handler.handle(Future.succeededFuture(input)); } } }); readStream.exceptionHandler(t -> { if (complete.compareAndSet(false, true)) { if (GrpcUniExchangeImpl.this.handler != null) { GrpcUniExchangeImpl.this.handler.handle(Future.failedFuture(t)); } } }); }
response.handler(feature -> { System.out.println("Result #" + features.size() + ": " + feature); features.add(feature); response.endHandler(v -> {
/** * <pre> * A sequence of requests followed by one response (streamed upload). * The server returns the aggregated size of client payload as the result. * </pre> */ public void streamingInputCall(io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingInputCallRequest> request, io.vertx.core.Future<io.vertx.example.grpc.Messages.StreamingInputCallResponse> response) { request.setReadObserver(asyncUnimplementedStreamingCall(getStreamingInputCallMethod(), ProducerServiceGrpc.toObserver(response.completer()))); }
@java.lang.Override @java.lang.SuppressWarnings("unchecked") public io.grpc.stub.StreamObserver<Req> invoke( io.grpc.stub.StreamObserver<Resp> responseObserver) { switch (methodId) { case METHODID_STREAMING_INPUT_CALL: io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingInputCallRequest> request0 = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingInputCallRequest>create(); serviceImpl.streamingInputCall(request0, (io.vertx.core.Future<io.vertx.example.grpc.Messages.StreamingInputCallResponse>) io.vertx.core.Future.<io.vertx.example.grpc.Messages.StreamingInputCallResponse>future().setHandler(ar -> { if (ar.succeeded()) { ((io.grpc.stub.StreamObserver<io.vertx.example.grpc.Messages.StreamingInputCallResponse>) responseObserver).onNext(ar.result()); responseObserver.onCompleted(); } else { responseObserver.onError(ar.cause()); } })); return (io.grpc.stub.StreamObserver<Req>) request0.readObserver(); default: throw new AssertionError(); } } }
@Override public void streamingInputCall(GrpcReadStream<StreamingInputCallRequest> request, Future<StreamingInputCallResponse> response) { will.assertNotNull(response); request .exceptionHandler(will::fail) .handler(resp -> { will.assertNotNull(resp); cnt.incrementAndGet(); }) .endHandler(v -> { will.assertEquals(10, cnt.get()); response.complete(StreamingInputCallResponse.newBuilder().build()); }); } }, startServer -> {
@Override public GrpcBidiExchange<I, O> setReadObserver(StreamObserver<I> observer) { readStream.setReadObserver(observer); return this; }
/** * <pre> * A server-to-client streaming RPC. * Obtains the Features available within the given Rectangle. Results are * streamed rather than returned at once (e.g. in a response message with a * repeated field), as the rectangle may cover a large area and contain a * huge number of features. * </pre> */ public void listFeatures(io.grpc.examples.routeguide.Rectangle request, io.vertx.core.Handler<io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.Feature>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.Feature> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.examples.routeguide.Feature>create(); handler.handle(readStream); asyncServerStreamingCall( getChannel().newCall(getListFeaturesMethod(), getCallOptions()), request, readStream.readObserver()); }
.exceptionHandler(will::fail) .handler(resp -> { will.assertNotNull(resp); cnt.incrementAndGet(); }) .endHandler(v -> { will.assertEquals(10, cnt.get()); test.complete();