Class BlockingResponseObserver<T>

  • All Implemented Interfaces:
    StreamObserver<T>

    public class BlockingResponseObserver<T>
    extends Object
    implements StreamObserver<T>
    Response observer for a client side that blocks until response is completed with either onCompleted() or onError(Throwable).

    Typical usage:

    var responseObserver = new BlockingResponseObserver<ResponseMessage>(response -> {
        // handle ResponseMessage response here...
    });
    myGrpcServiceStub.myRemoteProcedure(someRequest, responseObserver);
    try {
        responseObserver.awaitCompletion();
        // continue positive flow here...
    } catch (InterruptedException e) {  // often unreachable code
    } catch (ErrorReportedException e) {
        Throwable reportedError = e.getCause();
        // handle error that was reported via onError(reportedError) here...
    }