Class SingleResponseStreamObserver<T>

java.lang.Object
dk.gtz.graphedit.spi.SingleResponseStreamObserver<T>
Type Parameters:
T - The type of return value
All Implemented Interfaces:
io.grpc.stub.StreamObserver<T>

public class SingleResponseStreamObserver<T> extends Object implements io.grpc.stub.StreamObserver<T>
Utility class for capturing a single gRPC response and returning it. Example Usage:
 
 try {
     var so = new SingleResponseStreamObserver<GRPCObject>();
     stub.get().getValue(empty, so);
     so.await();
     return so.get();
 } catch(InterruptedException e) {
	   // handle e
 }
 
 
  • Constructor Details

    • SingleResponseStreamObserver

      public SingleResponseStreamObserver()
      Constructs a new SingleResponseStreamObserver instance
  • Method Details

    • onNext

      public void onNext(T value)
      Specified by:
      onNext in interface io.grpc.stub.StreamObserver<T>
    • onError

      public void onError(Throwable t)
      Specified by:
      onError in interface io.grpc.stub.StreamObserver<T>
    • onCompleted

      public void onCompleted()
      Specified by:
      onCompleted in interface io.grpc.stub.StreamObserver<T>
    • get

      public T get()
      Get the returned value.
      Returns:
      An instance of T
      Throws:
      RuntimeException - if an error had occurred or if the value is not present
    • await

      public void await() throws InterruptedException
      Wait for the request to complete.
      Throws:
      InterruptedException - if the current thread is interrupted while waiting