use of io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub in project grpc-java by grpc.
the class AsyncClient method doUnaryCalls.
private Future<Histogram> doUnaryCalls(Channel channel, final SimpleRequest request, final long endTime) {
final BenchmarkServiceStub stub = BenchmarkServiceGrpc.newStub(channel);
final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
final HistogramFuture future = new HistogramFuture(histogram);
stub.unaryCall(request, new StreamObserver<SimpleResponse>() {
long lastCall = System.nanoTime();
@Override
public void onNext(SimpleResponse value) {
}
@Override
public void onError(Throwable t) {
Status status = Status.fromThrowable(t);
System.err.println("Encountered an error in unaryCall. Status is " + status);
t.printStackTrace();
future.cancel(true);
}
@Override
public void onCompleted() {
long now = System.nanoTime();
// Record the latencies in microseconds
histogram.recordValue((now - lastCall) / 1000);
lastCall = now;
if (endTime > now) {
stub.unaryCall(request, this);
} else {
future.done();
}
}
});
return future;
}
use of io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub in project grpc-java by grpc.
the class AsyncClient method doStreamingCalls.
private static Future<Histogram> doStreamingCalls(Channel channel, final SimpleRequest request, final long endTime) {
final BenchmarkServiceStub stub = BenchmarkServiceGrpc.newStub(channel);
final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION);
final HistogramFuture future = new HistogramFuture(histogram);
ThisIsAHackStreamObserver responseObserver = new ThisIsAHackStreamObserver(request, histogram, future, endTime);
StreamObserver<SimpleRequest> requestObserver = stub.streamingCall(responseObserver);
responseObserver.requestObserver = requestObserver;
requestObserver.onNext(request);
return future;
}
Aggregations