/** * <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.core.Handler< io.vertx.grpc.GrpcUniExchange<io.vertx.example.grpc.Messages.StreamingInputCallRequest, io.vertx.example.grpc.Messages.StreamingInputCallResponse>> handler) { final io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingInputCallResponse> readStream = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingInputCallResponse>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getStreamingInputCallMethod(), getCallOptions()), readStream.readObserver()))); } }
void send(int numPoints) { if (result != null) { // RPC completed or errored before we finished sending. // Sending further requests won't error, but they will just be thrown away. return; } int index = random.nextInt(features.size()); Point point = features.get(index).getLocation(); System.out.println("Visiting point " + Util.getLatitude(point) + ", " + Util.getLongitude(point)); exchange.write(point); if (numPoints > 0) { vertx.setTimer(random.nextInt(1000) + 500, id -> { send(numPoints - 1); }); } else { exchange.end(); } } }
/** * Async client-streaming example. Sends {@code numPoints} randomly chosen points from {@code * features} with a variable delay in between. Prints the statistics when they are sent from the * server. */ public void recordRoute(List<Feature> features, int numPoints) throws InterruptedException { System.out.println("*** RecordRoute"); stub.recordRoute(exchange -> { RouteSender sender = new RouteSender(features, exchange); exchange.handler(ar -> { sender.result = ar; if (ar.succeeded()) { RouteSummary summary = ar.result(); System.out.println("Finished trip with " + summary.getPointCount() + " points. Passed " + summary.getFeatureCount() + " features.Travelled " + summary.getDistance() + " meters. It took " + summary.getElapsedTime() + " seconds."); System.out.println("Finished RecordRoute"); } else { System.out.println("RecordRoute Failed: " + Status.fromThrowable(ar.cause())); } }); // Send numPoints points randomly selected from the features list. sender.send(numPoints); }); }
/** * <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.core.Handler< io.vertx.grpc.GrpcUniExchange<io.grpc.examples.routeguide.Point, io.grpc.examples.routeguide.RouteSummary>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.RouteSummary> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.examples.routeguide.RouteSummary>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getRecordRouteMethod(), getCallOptions()), readStream.readObserver()))); }
/** */ public void sink(io.vertx.core.Handler< io.vertx.grpc.GrpcUniExchange<io.grpc.examples.streaming.Item, io.grpc.examples.streaming.Empty>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.examples.streaming.Empty> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.examples.streaming.Empty>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getSinkMethod(), getCallOptions()), readStream.readObserver()))); }
/** * <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.core.Handler< io.vertx.grpc.GrpcUniExchange<io.grpc.testing.integration.Messages.StreamingInputCallRequest, io.grpc.testing.integration.Messages.StreamingInputCallResponse>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.testing.integration.Messages.StreamingInputCallResponse> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.testing.integration.Messages.StreamingInputCallResponse>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getStreamingInputCallMethod(), getCallOptions()), readStream.readObserver()))); }