Package io.grpc

Class MethodDescriptor<ReqT,​RespT>


  • @Immutable
    public final class MethodDescriptor<ReqT,​RespT>
    extends Object
    Description of a remote method used by Channel to initiate a call.

    Provides the name of the operation to execute as well as MethodDescriptor.Marshaller instances used to parse and serialize request and response messages.

    Can be constructed manually but will often be generated by stub code generators.

    Since:
    1.0.0
    • Method Detail

      • getFullMethodName

        public String getFullMethodName()
        The fully qualified name of the method.
        Since:
        1.0.0
      • getServiceName

        @Nullable
        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635")
        public String getServiceName()
        A convenience method for extractFullServiceName(getFullMethodName()).
        Since:
        1.21.0
      • getBareMethodName

        @Nullable
        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635")
        public String getBareMethodName()
        A convenience method for extractBareMethodName(getFullMethodName()).
        Since:
        1.33.0
      • parseResponse

        public RespT parseResponse​(InputStream input)
        Parse a response payload from the given InputStream.
        Parameters:
        input - stream containing response message to parse.
        Returns:
        parsed response message object.
        Since:
        1.0.0
      • streamRequest

        public InputStream streamRequest​(ReqT requestMessage)
        Convert a request message to an InputStream. The returned InputStream should be closed by the caller.
        Parameters:
        requestMessage - to serialize using the request MethodDescriptor.Marshaller.
        Returns:
        serialized request message.
        Since:
        1.0.0
      • parseRequest

        public ReqT parseRequest​(InputStream input)
        Parse an incoming request message.
        Parameters:
        input - the serialized message as a byte stream.
        Returns:
        a parsed instance of the message.
        Since:
        1.0.0
      • streamResponse

        public InputStream streamResponse​(RespT response)
        Serialize an outgoing response message. The returned InputStream should be closed by the caller.
        Parameters:
        response - the response message to serialize.
        Returns:
        the serialized message as a byte stream.
        Since:
        1.0.0
      • getRequestMarshaller

        public MethodDescriptor.Marshaller<ReqT> getRequestMarshaller()
        Returns the marshaller for the request type. Allows introspection of the request marshaller.
        Since:
        1.1.0
      • getResponseMarshaller

        public MethodDescriptor.Marshaller<RespT> getResponseMarshaller()
        Returns the marshaller for the response type. Allows introspection of the response marshaller.
        Since:
        1.1.0
      • getSchemaDescriptor

        @Nullable
        public Object getSchemaDescriptor()
        Returns the schema descriptor for this method. A schema descriptor is an object that is not used by gRPC core but includes information related to the service method. The type of the object is specific to the consumer, so both the code setting the schema descriptor and the code calling getSchemaDescriptor() must coordinate. For example, protobuf generated code sets this value, in order to be consumed by the server reflection service. See also: io.grpc.protobuf.ProtoMethodDescriptorSupplier.
        Since:
        1.7.0
      • isIdempotent

        public boolean isIdempotent()
        Returns whether this method is idempotent.
        Since:
        1.0.0
      • isSafe

        public boolean isSafe()
        Returns whether this method is safe.

        A safe request does nothing except retrieval so it has no side effects on the server side.

        Since:
        1.1.0
      • isSampledToLocalTracing

        public boolean isSampledToLocalTracing()
        Returns whether RPCs for this method may be sampled into the local tracing store.
      • generateFullMethodName

        public static String generateFullMethodName​(String fullServiceName,
                                                    String methodName)
        Generate the fully qualified method name. This matches the name
        Parameters:
        fullServiceName - the fully qualified service name that is prefixed with the package name
        methodName - the short method name
        Since:
        1.0.0
      • extractFullServiceName

        @Nullable
        public static String extractFullServiceName​(String fullMethodName)
        Extract the fully qualified service name out of a fully qualified method name. May return null if the input is malformed, but you cannot rely on it for the validity of the input.
        Since:
        1.0.0
      • extractBareMethodName

        @Nullable
        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635")
        public static String extractBareMethodName​(String fullMethodName)
        Extract the method name out of a fully qualified method name. May return null if the input is malformed, but you cannot rely on it for the validity of the input.
        Since:
        1.33.0