Class UnaryMethodHandlerSupplier.UnaryFutureNoRequest<ReqT,RespT>

java.lang.Object
io.helidon.microprofile.grpc.core.UnaryMethodHandlerSupplier.AbstractUnaryHandler<ReqT,RespT>
io.helidon.microprofile.grpc.core.UnaryMethodHandlerSupplier.UnaryFutureNoRequest<ReqT,RespT>
Type Parameters:
ReqT - the request type
RespT - the response type
All Implemented Interfaces:
io.grpc.stub.ServerCalls.BidiStreamingMethod<ReqT,RespT>, io.grpc.stub.ServerCalls.ClientStreamingMethod<ReqT,RespT>, io.grpc.stub.ServerCalls.ServerStreamingMethod<ReqT,RespT>, io.grpc.stub.ServerCalls.UnaryMethod<ReqT,RespT>, MethodHandler<ReqT,RespT>
Enclosing class:
UnaryMethodHandlerSupplier

public static class UnaryMethodHandlerSupplier.UnaryFutureNoRequest<ReqT,RespT> extends UnaryMethodHandlerSupplier.AbstractUnaryHandler<ReqT,RespT>
A unary MethodHandler that calls a handler method of the form.
     void invoke(CompletableFuture<RespT> future)
 

If the future completes normally and has a none null none Void result then that result will be passed to the StreamObserver.onNext(Object) method. If the future completes exceptionally then the error will be passed to the StreamObserver.onError(Throwable) method.

  • Method Details

    • invoke

      protected void invoke(Method method, Object instance, ReqT request, io.grpc.stub.StreamObserver<RespT> observer) throws InvocationTargetException, IllegalAccessException
      Invoke the actual unary or server streaming gRPC method handler.
      Parameters:
      method - the Method to invoke
      instance - the service instance to invoke the method on
      request - the method request
      observer - the method response observer
      Throws:
      InvocationTargetException - if an error occurs invoking the method
      IllegalAccessException - if the method cannot be accessed
    • unary

      public Object unary(Object[] args, MethodHandler.UnaryClient client)
      Invoke the client call.

      The call is from a method signature:

           void invoke(CompletableFuture<RespT> future)
       
      so there is no request parameter and the CompletableFuture to receive the response is in args[1.
      Parameters:
      args - the call arguments.
      client - the MethodHandler.UnaryClient instance to forward the call to
      Returns:
      the method signature return is void so this method always returns null
    • type

      public final io.grpc.MethodDescriptor.MethodType type()
      Description copied from interface: MethodHandler
      Obtain the gRPC method tyoe that this MethodHandler handles.
      Specified by:
      type in interface MethodHandler<ReqT,RespT>
      Returns:
      the gRPC method type that this MethodHandler handles
    • invoke

      public void invoke(ReqT request, io.grpc.stub.StreamObserver<RespT> observer)
      Specified by:
      invoke in interface MethodHandler<ReqT,RespT>
      Specified by:
      invoke in interface io.grpc.stub.ServerCalls.ServerStreamingMethod<ReqT,RespT>
      Specified by:
      invoke in interface io.grpc.stub.ServerCalls.UnaryMethod<ReqT,RespT>
    • invoke

      public io.grpc.stub.StreamObserver<ReqT> invoke(io.grpc.stub.StreamObserver<RespT> observer)
      Specified by:
      invoke in interface MethodHandler<ReqT,RespT>
      Specified by:
      invoke in interface io.grpc.stub.ServerCalls.BidiStreamingMethod<ReqT,RespT>
      Specified by:
      invoke in interface io.grpc.stub.ServerCalls.ClientStreamingMethod<ReqT,RespT>
    • getRequestType

      public Class<?> getRequestType()
      Description copied from interface: MethodHandler
      Obtain the request type.
      Specified by:
      getRequestType in interface MethodHandler<ReqT,RespT>
      Returns:
      the request type
    • setRequestType

      protected void setRequestType(Class<?> requestType)
      Set the request type to use if no Grpc.RequestType annotation is present on the annotated method.
      Parameters:
      requestType - the request type
    • getResponseType

      public Class<?> getResponseType()
      Description copied from interface: MethodHandler
      Obtain the response type.
      Specified by:
      getResponseType in interface MethodHandler<ReqT,RespT>
      Returns:
      the response type
    • javaMethodName

      public String javaMethodName()
      Description copied from interface: MethodHandler
      Obtain the name of the underlying Java method that this handler maps to.
      Specified by:
      javaMethodName in interface MethodHandler<ReqT,RespT>
      Returns:
      the name of the underlying Java method that this handler maps to
    • setResponseType

      protected void setResponseType(Class<?> responseType)
      Set the response type to use if no Grpc.ResponseType annotation is present on the annotated method.
      Parameters:
      responseType - the response type
    • methodName

      protected String methodName()
      Obtain the gRPC method name.
      Returns:
      the gRPC method name
    • handleFuture

      protected Void handleFuture(RespT response, Throwable thrown, io.grpc.stub.StreamObserver<RespT> observer)
      Complete a StreamObserver.
      Parameters:
      response - the response value
      thrown - an error that may have occurred
      observer - the StreamObserver to complete
      Returns:
      always returns Void (i.e. null)
    • getGenericResponseType

      protected Class<?> getGenericResponseType(Type type)
      Obtain the generic type of a Type

      Typically used to obtain the generic type of a StreamObserver but could be used to obtain the generic type of other classes.

      If the type passed in is a Class then it has no generic component so the Object Class will be returned. Typically this would be due to a declaration such as

      StreamObserver observer
      instead of a generic declaration such as
      StreamObserver<String> observer
      .
      Parameters:
      type - the type to obtain the generic type from
      Returns:
      the generic type of a Type