Class GrpcUtil
java.lang.Object
io.deephaven.extensions.barrage.util.GrpcUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 <T> void
safelyComplete
(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.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.
-
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 completemessage
- the message to send on this stream
-
safelyComplete
public static <T> void safelyComplete(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 completemessage
- 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
orcause
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 runnablemessage
- if notnull
, will appear as the description of the CANCELLED statuscause
- if notnull
, will appear as the cause of the CANCELLED status
-