Class ResponseHandlers

java.lang.Object
com.oracle.coherence.grpc.proxy.ResponseHandlers

public class ResponseHandlers extends Object
Helper methods to handle gRPC async responses.
Since:
23.03
Author:
Jonathan Knight 2023.02.02
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Void
    A Void value to make it obvious the return value in Void methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <Resp> Void
    handleError(Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
    A handler method that will call StreamObserver.onError(Throwable) if the error parameter is not null.
    static <Resp> Resp
    handleError(Resp response, Throwable err)
    A handler method that will return the response if there is no error or if there is an error then ensure that it is a StatusRuntimeException.
    static <Resp> Void
    handleErrorOrComplete(Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
    A handler method that will call StreamObserver.onError(Throwable) if the error parameter is not null otherwise calls StreamObserver.onCompleted().
    static Void
    handleMapOfEntries(RequestHolder<?,Map<Binary,Binary>> holder, Throwable err, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
    Handle the result of the asynchronous invoke all request sending the results, or any errors to the StreamObserver.
    static Void
    handleSetOfEntries(RequestHolder<?,Set<Map.Entry<Binary,Binary>>> holder, Throwable err, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
    Handle the result of the asynchronous entry set request sending the results, or any errors to the StreamObserver.
    static Void
    handleStream(RequestHolder<?,? extends Iterable<Binary>> holder, Throwable err, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
    Send an Iterable of Binary instances to a StreamObserver, converting the Binary instances to a BytesValue.
    static <Resp> Void
    handleStream(Iterable<Resp> iterable, Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
    A handler method that streams results from an Iterable to a StreamObserver and completes the StreamObserver, or if an error is provided calls StreamObserver.onError(Throwable).
    static <Resp> Void
    handleStream(Stream<Resp> stream, Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
    A handler method that streams results to a StreamObserver and completes the StreamObserver or if an error is provided calls StreamObserver.onError(Throwable).
    static void
    handleStreamOfEntries(RequestHolder<?,?> holder, Stream<Map.Entry<Binary,Binary>> entries, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
    Handle the result of the asynchronous invoke all request sending the results, or any errors to the StreamObserver.
    static <R> Void
    handleUnary(R result, Throwable err, io.grpc.stub.StreamObserver<R> observer)
    Handle an unary request.
    static com.google.protobuf.Int32Value
    Convert a value to an Int32Value.

    Methods inherited from class java.lang.Object

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

    • VOID

      public static final Void VOID
      A Void value to make it obvious the return value in Void methods.
  • Constructor Details

    • ResponseHandlers

      public ResponseHandlers()
  • Method Details

    • handleUnary

      public static <R> Void handleUnary(R result, Throwable err, io.grpc.stub.StreamObserver<R> observer)
      Handle an unary request.
      Type Parameters:
      R - the type of the result
      Parameters:
      result - the result
      err - any error that may have occurred
      observer - the StreamObserver to send the result to
      Returns:
      always returns Void
    • handleMapOfEntries

      public static Void handleMapOfEntries(RequestHolder<?,Map<Binary,Binary>> holder, Throwable err, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Handle the result of the asynchronous invoke all request sending the results, or any errors to the StreamObserver.
      Parameters:
      holder - the RequestHolder containing the request
      err - any error that occurred during execution of the get all request
      observer - the StreamObserver to receive the results
      Returns:
      always return Void
    • handleSetOfEntries

      public static Void handleSetOfEntries(RequestHolder<?,Set<Map.Entry<Binary,Binary>>> holder, Throwable err, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Handle the result of the asynchronous entry set request sending the results, or any errors to the StreamObserver.
      Parameters:
      holder - the RequestHolder containing the request
      err - any error that occurred during execution of the get all request
      observer - the StreamObserver to receive the results
      Returns:
      always return Void
    • handleStreamOfEntries

      public static void handleStreamOfEntries(RequestHolder<?,?> holder, Stream<Map.Entry<Binary,Binary>> entries, io.grpc.stub.StreamObserver<com.oracle.coherence.grpc.Entry> observer)
      Handle the result of the asynchronous invoke all request sending the results, or any errors to the StreamObserver.
      Parameters:
      holder - the RequestHolder containing the request
      entries - a Stream of entries
      observer - the StreamObserver to receive the results
    • handleStream

      public static Void handleStream(RequestHolder<?,? extends Iterable<Binary>> holder, Throwable err, io.grpc.stub.StreamObserver<com.google.protobuf.BytesValue> observer)
      Send an Iterable of Binary instances to a StreamObserver, converting the Binary instances to a BytesValue.
      Parameters:
      holder - the RequestHolder containing the request and Iterable or Binary instances to stream
      err - the error the pass to StreamObserver.onError(Throwable)
      observer - the StreamObserver to receive the results
      Returns:
      always return Void
    • handleStream

      public static <Resp> Void handleStream(Iterable<Resp> iterable, Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
      A handler method that streams results from an Iterable to a StreamObserver and completes the StreamObserver, or if an error is provided calls StreamObserver.onError(Throwable).

      Note: this method will complete by calling either StreamObserver.onCompleted() or StreamObserver.onError(Throwable).

      Type Parameters:
      Resp - the type of the element to stream to the StreamObserver
      Parameters:
      iterable - the elements to stream to the StreamObserver
      err - the error the pass to StreamObserver.onError(Throwable)
      observer - the StreamObserver
      Returns:
      always returns Void
    • handleStream

      public static <Resp> Void handleStream(Stream<Resp> stream, Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
      A handler method that streams results to a StreamObserver and completes the StreamObserver or if an error is provided calls StreamObserver.onError(Throwable).

      Note: this method will complete by calling either StreamObserver.onCompleted() or StreamObserver.onError(Throwable).

      Type Parameters:
      Resp - the type of the element to stream to the StreamObserver
      Parameters:
      stream - the elements to stream to the StreamObserver
      err - the error the pass to StreamObserver.onError(Throwable)
      observer - the StreamObserver
      Returns:
      always returns Void
    • handleError

      public static <Resp> Void handleError(Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
      A handler method that will call StreamObserver.onError(Throwable) if the error parameter is not null.

      NOTE: this method will not complete the StreamObserver if there is no error.

      Type Parameters:
      Resp - the type of the element to stream to the StreamObserver
      Parameters:
      err - the error the pass to StreamObserver.onError(Throwable)
      observer - the StreamObserver
      Returns:
      always returns Void
    • handleErrorOrComplete

      public static <Resp> Void handleErrorOrComplete(Throwable err, io.grpc.stub.StreamObserver<Resp> observer)
      A handler method that will call StreamObserver.onError(Throwable) if the error parameter is not null otherwise calls StreamObserver.onCompleted().

      NOTE: this method will not complete the StreamObserver if there is no error.

      Type Parameters:
      Resp - the type of the element to stream to the StreamObserver
      Parameters:
      err - the error the pass to StreamObserver.onError(Throwable)
      observer - the StreamObserver
      Returns:
      always returns Void
    • handleError

      public static <Resp> Resp handleError(Resp response, Throwable err)
      A handler method that will return the response if there is no error or if there is an error then ensure that it is a StatusRuntimeException.
      Type Parameters:
      Resp - the type of the response
      Parameters:
      response - the response to return if there is no error
      err - the error to check
      Returns:
      always returns the passed in response
    • toInt32Value

      public static com.google.protobuf.Int32Value toInt32Value(Object o)
      Convert a value to an Int32Value.
      Parameters:
      o - the value to convert
      Returns:
      the value of o as an Int32Value id o is a Number, otherwise Int32Value.getDefaultInstance()