Class SafeStreamObserver<T>

  • Type Parameters:
    T - the type of response expected
    All Implemented Interfaces:
    io.grpc.stub.StreamObserver<T>

    public class SafeStreamObserver<T>
    extends Object
    implements io.grpc.stub.StreamObserver<T>
    A StreamObserver that handles exceptions correctly.
    Author:
    Jonathan Knight 2020.09.22
    • Method Detail

      • onNext

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

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

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

        public io.grpc.stub.StreamObserver<? super T> delegate()
        Obtain the wrapped StreamObserver.
        Returns:
        the wrapped StreamObserver
      • isDone

        public boolean isDone()
        Returns true if this observer is complete.
        Returns:
        true if this observer is complete
      • ensureSafeObserver

        public static <T> io.grpc.stub.StreamObserver<T> ensureSafeObserver​(io.grpc.stub.StreamObserver<T> observer)
        Ensure that the specified StreamObserver is a safe observer.

        If the specified observer is not an instance of SafeStreamObserver then wrap it in a SafeStreamObserver.

        Type Parameters:
        T - the response type expected by the observer
        Parameters:
        observer - the StreamObserver to test
        Returns:
        a safe StreamObserver