Class MethodDescriptor<ReqT,RespT>
java.lang.Object
io.grpc.MethodDescriptor<ReqT,RespT>
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for aMethodDescriptor.static interfaceA typed abstraction over message serialization and deserialization, a.k.a.static enumThe call type of a method.static interfaceA marshaller that uses a fixed instance of the type it produces.static interfaceA marshaller that supports retrieving its type parameterTat runtime. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate final booleanprivate final AtomicReferenceArray<Object> private final MethodDescriptor.Marshaller<ReqT> private final MethodDescriptor.Marshaller<RespT> private final booleanprivate final booleanprivate final Objectprivate final Stringprivate final MethodDescriptor.MethodType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateMethodDescriptor(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller, Object schemaDescriptor, boolean idempotent, boolean safe, boolean sampledToLocalTracing) -
Method Summary
Modifier and TypeMethodDescriptionstatic <RequestT, ResponseT>
MethodDescriptor<RequestT, ResponseT> create(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<RequestT> requestMarshaller, MethodDescriptor.Marshaller<ResponseT> responseMarshaller) Deprecated.static StringextractBareMethodName(String fullMethodName) Extract the method name out of a fully qualified method name.static StringextractFullServiceName(String fullMethodName) Extract the fully qualified service name out of a fully qualified method name.static StringgenerateFullMethodName(String fullServiceName, String methodName) Generate the fully qualified method name.A convenience method forextractBareMethodName(getFullMethodName()).The fully qualified name of the method.(package private) final ObjectgetRawMethodName(int transportOrdinal) Gets the cached "raw" method name for this Method Descriptor.Returns the marshaller for the request type.Returns the marshaller for the response type.Returns the schema descriptor for this method.A convenience method forextractFullServiceName(getFullMethodName()).getType()The call type of the method.booleanReturns whether this method is idempotent.booleanisSafe()Returns whether this method is safe.booleanReturns whether RPCs for this method may be sampled into the local tracing store.static <ReqT,RespT>
MethodDescriptor.Builder<ReqT, RespT> Creates a new builder for aMethodDescriptor.static <ReqT,RespT>
MethodDescriptor.Builder<ReqT, RespT> newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller) Creates a new builder for aMethodDescriptor.parseRequest(InputStream input) Parse an incoming request message.parseResponse(InputStream input) Parse a response payload from the givenInputStream.(package private) final voidsetRawMethodName(int transportOrdinal, Object o) Safely, but weakly, sets the raw method name for this Method Descriptor.streamRequest(ReqT requestMessage) Convert a request message to anInputStream.streamResponse(RespT response) Serialize an outgoing response message.Turns this descriptor into a builder.<NewReqT,NewRespT>
MethodDescriptor.Builder<NewReqT, NewRespT> toBuilder(MethodDescriptor.Marshaller<NewReqT> requestMarshaller, MethodDescriptor.Marshaller<NewRespT> responseMarshaller) Turns this descriptor into a builder, replacing the request and response marshallers.toString()
-
Field Details
-
type
-
fullMethodName
-
serviceName
-
requestMarshaller
-
responseMarshaller
-
schemaDescriptor
-
idempotent
private final boolean idempotent -
safe
private final boolean safe -
sampledToLocalTracing
private final boolean sampledToLocalTracing -
rawMethodNames
-
-
Constructor Details
-
MethodDescriptor
private MethodDescriptor(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller, Object schemaDescriptor, boolean idempotent, boolean safe, boolean sampledToLocalTracing)
-
-
Method Details
-
getRawMethodName
Gets the cached "raw" method name for this Method Descriptor. The raw name is transport specific, and should be set usingsetRawMethodName(int, Object)by the transport.- Parameters:
transportOrdinal- the unique ID of the transport, given byEnum.ordinal().- Returns:
- a transport specific representation of the method name.
-
setRawMethodName
Safely, but weakly, sets the raw method name for this Method Descriptor. This should only be called by the transport. SeegetRawMethodName(int)for more detail. -
create
@Deprecated public static <RequestT, ResponseT> MethodDescriptor<RequestT, ResponseT> create(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<RequestT> requestMarshaller, MethodDescriptor.Marshaller<ResponseT> responseMarshaller) Deprecated.usenewBuilder().Creates a newMethodDescriptor.- Parameters:
type- the call type of this methodfullMethodName- the fully qualified name of this methodrequestMarshaller- the marshaller used to encode and decode requestsresponseMarshaller- the marshaller used to encode and decode responses- Since:
- 1.0.0
-
getType
-
getFullMethodName
-
getServiceName
@Nullable @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635") public String getServiceName()A convenience method forextractFullServiceName(getFullMethodName()).- Since:
- 1.21.0
-
getBareMethodName
@Nullable @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635") public String getBareMethodName()A convenience method forextractBareMethodName(getFullMethodName()).- Since:
- 1.33.0
-
parseResponse
Parse a response payload from the givenInputStream.- Parameters:
input- stream containing response message to parse.- Returns:
- parsed response message object.
- Since:
- 1.0.0
-
streamRequest
Convert a request message to anInputStream. The returned InputStream should be closed by the caller.- Parameters:
requestMessage- to serialize using the requestMethodDescriptor.Marshaller.- Returns:
- serialized request message.
- Since:
- 1.0.0
-
parseRequest
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
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
Returns the marshaller for the request type. Allows introspection of the request marshaller.- Since:
- 1.1.0
-
getResponseMarshaller
Returns the marshaller for the response type. Allows introspection of the response marshaller.- Since:
- 1.1.0
-
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 callinggetSchemaDescriptor()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
Generate the fully qualified method name. This matches the name- Parameters:
fullServiceName- the fully qualified service name that is prefixed with the package namemethodName- the short method name- Since:
- 1.0.0
-
extractFullServiceName
-
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 returnnullif the input is malformed, but you cannot rely on it for the validity of the input.- Since:
- 1.33.0
-
newBuilder
Creates a new builder for aMethodDescriptor.- Since:
- 1.1.0
-
newBuilder
@CheckReturnValue public static <ReqT,RespT> MethodDescriptor.Builder<ReqT,RespT> newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller) Creates a new builder for aMethodDescriptor.- Since:
- 1.1.0
-
toBuilder
Turns this descriptor into a builder.- Since:
- 1.1.0
-
toBuilder
@CheckReturnValue public <NewReqT,NewRespT> MethodDescriptor.Builder<NewReqT,NewRespT> toBuilder(MethodDescriptor.Marshaller<NewReqT> requestMarshaller, MethodDescriptor.Marshaller<NewRespT> responseMarshaller) Turns this descriptor into a builder, replacing the request and response marshallers.- Since:
- 1.1.0
-
toString
-
newBuilder().