use of io.grpc.benchmarks.proto.Messages.SimpleResponse 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;
}
Aggregations