Class GrpcUtil

java.lang.Object
io.deephaven.extensions.barrage.util.GrpcUtil

public class GrpcUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    safelyCancel(@NotNull io.grpc.stub.ClientCallStreamObserver<?> observer, @Nullable String message, @Nullable Throwable cause)
    Cancels the observer in a try/catch block to minimize damage caused by failing observer call.
    static void
    safelyComplete(io.grpc.stub.StreamObserver<?> observer)
    Completes the stream, ignoring any errors that may happen during this call.
    static void
    safelyError(@NotNull io.grpc.stub.StreamObserver<?> observer, @NotNull io.grpc.StatusRuntimeException exception)
    Writes an error to the observer in a try/catch block to minimize damage caused by failing observer call.
    static void
    safelyError(@NotNull io.grpc.stub.StreamObserver<?> observer, com.google.rpc.Code statusCode, @NotNull String msg)
    Writes an error to the observer in a try/catch block to minimize damage caused by failing observer call.
    static <T> void
    safelyOnNext(io.grpc.stub.StreamObserver<T> observer, T message)
    Sends one message to the stream, ignoring any errors that may happen during that call.
    static <T> void
    safelyOnNextAndComplete(io.grpc.stub.StreamObserver<T> observer, T message)
    Sends one message and then completes the stream, ignoring any errors that may happen during these calls.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GrpcUtil

      public GrpcUtil()
  • Method Details

    • safelyOnNext

      public static <T> void safelyOnNext(io.grpc.stub.StreamObserver<T> observer, T message)
      Sends one message to the stream, ignoring any errors that may happen during that call.
      Type Parameters:
      T - the type of message that the stream handles
      Parameters:
      observer - the stream to complete
      message - the message to send on this stream
    • safelyOnNextAndComplete

      public static <T> void safelyOnNextAndComplete(io.grpc.stub.StreamObserver<T> observer, T message)
      Sends one message and then completes the stream, ignoring any errors that may happen during these calls. Useful for unary responses.
      Type Parameters:
      T - the type of message that the stream handles
      Parameters:
      observer - the stream to complete
      message - the last message to send on this stream before completing
    • safelyComplete

      public static void safelyComplete(io.grpc.stub.StreamObserver<?> observer)
      Completes the stream, ignoring any errors that may happen during this call.
      Parameters:
      observer - the stream to complete
    • safelyError

      public static void safelyError(@NotNull @NotNull io.grpc.stub.StreamObserver<?> observer, com.google.rpc.Code statusCode, @NotNull @NotNull String msg)
      Writes an error to the observer in a try/catch block to minimize damage caused by failing observer call.

      This will always synchronize on the observer to ensure thread safety when interacting with the grpc response stream.

    • safelyError

      public static void safelyError(@NotNull @NotNull io.grpc.stub.StreamObserver<?> observer, @NotNull @NotNull io.grpc.StatusRuntimeException exception)
      Writes an error to the observer in a try/catch block to minimize damage caused by failing observer call.

      This will always synchronize on the observer to ensure thread safety when interacting with the grpc response stream.

    • safelyCancel

      public static void safelyCancel(@NotNull @NotNull io.grpc.stub.ClientCallStreamObserver<?> observer, @Nullable @Nullable String message, @Nullable @Nullable Throwable cause)
      Cancels the observer in a try/catch block to minimize damage caused by failing observer call.

      This will always synchronize on the observer to ensure thread safety when interacting with the grpc response stream.

      It is recommended that at least one of message or cause to be non-null, to provide useful debug information. Both arguments being null may log warnings and result in suboptimal performance. Also note that the provided information will not be sent to the server.

      Parameters:
      observer - the stream that will be used in the runnable
      message - if not null, will appear as the description of the CANCELLED status
      cause - if not null, will appear as the cause of the CANCELLED status