Created
April 23, 2015 19:45
-
-
Save buchgr/b11f5e59c7444f5b8032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basically I want to initiate the stream from the client and then whenever I get a message from the server | |
// I want to respond immediately over the same stream. | |
private Future<Histogram> doStreamingCalls(Channel channel, final SimpleRequest request, | |
final long endTime) { | |
final TestServiceStub stub = TestServiceGrpc.newStub(channel); | |
final Histogram histogram = new Histogram(HISTOGRAM_MAX_VALUE, HISTOGRAM_PRECISION); | |
final HistogramFuture future = new HistogramFuture(histogram); | |
final StreamObserver<SimpleRequest> requestObserver; | |
requestObserver = stub.streamingCall(new StreamObserver<SimpleResponse>() { | |
long lastCall = System.nanoTime(); | |
@Override | |
public void onValue(SimpleResponse value) { | |
long now = System.nanoTime(); | |
// Record the latencies in microseconds | |
histogram.recordValue((now - lastCall) / 1000); | |
lastCall = now; | |
if (endTime > now) { | |
requestObserver.onValue(request); | |
} else { | |
requestObserver.onCompleted(); | |
} | |
} | |
@Override | |
public void onError(Throwable t) { | |
} | |
@Override | |
public void onCompleted() { | |
future.done(); | |
} | |
}); | |
requestObserver.onValue(request); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment