@Immutable public final class MethodDescriptor<ReqT,RespT> extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
MethodDescriptor.Builder<ReqT,RespT>
A builder for a
MethodDescriptor . |
static interface |
MethodDescriptor.Marshaller<T>
A typed abstraction over message serialization and deserialization, a.k.a.
|
static class |
MethodDescriptor.MethodType
The call type of a method.
|
static interface |
MethodDescriptor.PrototypeMarshaller<T>
A marshaller that uses a fixed instance of the type it produces.
|
static interface |
MethodDescriptor.ReflectableMarshaller<T>
A marshaller that supports retrieving it's type parameter
T at runtime. |
Modifier and Type | Method and Description |
---|---|
static <RequestT,ResponseT> |
create(MethodDescriptor.MethodType type,
String fullMethodName,
MethodDescriptor.Marshaller<RequestT> requestMarshaller,
MethodDescriptor.Marshaller<ResponseT> responseMarshaller)
Deprecated.
use
newBuilder() . |
static String |
extractBareMethodName(String fullMethodName)
Extract the method name out of a fully qualified method name.
|
static String |
extractFullServiceName(String fullMethodName)
Extract the fully qualified service name out of a fully qualified method name.
|
static String |
generateFullMethodName(String fullServiceName,
String methodName)
Generate the fully qualified method name.
|
String |
getBareMethodName()
A convenience method for
extractBareMethodName(getFullMethodName()) . |
String |
getFullMethodName()
The fully qualified name of the method.
|
MethodDescriptor.Marshaller<ReqT> |
getRequestMarshaller()
Returns the marshaller for the request type.
|
MethodDescriptor.Marshaller<RespT> |
getResponseMarshaller()
Returns the marshaller for the response type.
|
Object |
getSchemaDescriptor()
Returns the schema descriptor for this method.
|
String |
getServiceName()
A convenience method for
extractFullServiceName(getFullMethodName()) . |
MethodDescriptor.MethodType |
getType()
The call type of the method.
|
boolean |
isIdempotent()
Returns whether this method is idempotent.
|
boolean |
isSafe()
Returns whether this method is safe.
|
boolean |
isSampledToLocalTracing()
Returns whether RPCs for this method may be sampled into the local tracing store.
|
static <ReqT,RespT> |
newBuilder()
Creates a new builder for a
MethodDescriptor . |
static <ReqT,RespT> |
newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller,
MethodDescriptor.Marshaller<RespT> responseMarshaller)
Creates a new builder for a
MethodDescriptor . |
ReqT |
parseRequest(InputStream input)
Parse an incoming request message.
|
RespT |
parseResponse(InputStream input)
Parse a response payload from the given
InputStream . |
InputStream |
streamRequest(ReqT requestMessage)
Convert a request message to an
InputStream . |
InputStream |
streamResponse(RespT response)
Serialize an outgoing response message.
|
MethodDescriptor.Builder<ReqT,RespT> |
toBuilder()
Turns this descriptor into a builder.
|
<NewReqT,NewRespT> |
toBuilder(MethodDescriptor.Marshaller<NewReqT> requestMarshaller,
MethodDescriptor.Marshaller<NewRespT> responseMarshaller)
Turns this descriptor into a builder, replacing the request and response marshallers.
|
String |
toString() |
@Deprecated public static <RequestT,ResponseT> MethodDescriptor<RequestT,ResponseT> create(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<RequestT> requestMarshaller, MethodDescriptor.Marshaller<ResponseT> responseMarshaller)
newBuilder()
.MethodDescriptor
.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 responsespublic MethodDescriptor.MethodType getType()
public String getFullMethodName()
@Nullable @ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/5635") public String getServiceName()
extractFullServiceName(getFullMethodName())
.@Nullable @ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/5635") public String getBareMethodName()
extractBareMethodName(getFullMethodName())
.public RespT parseResponse(InputStream input)
InputStream
.input
- stream containing response message to parse.public InputStream streamRequest(ReqT requestMessage)
InputStream
.
The returned InputStream should be closed by the caller.requestMessage
- to serialize using the request MethodDescriptor.Marshaller
.public ReqT parseRequest(InputStream input)
input
- the serialized message as a byte stream.public InputStream streamResponse(RespT response)
response
- the response message to serialize.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/2592") public MethodDescriptor.Marshaller<ReqT> getRequestMarshaller()
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/2592") public MethodDescriptor.Marshaller<RespT> getResponseMarshaller()
@Nullable public Object getSchemaDescriptor()
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
.public boolean isIdempotent()
public boolean isSafe()
A safe request does nothing except retrieval so it has no side effects on the server side.
public boolean isSampledToLocalTracing()
public static String generateFullMethodName(String fullServiceName, String methodName)
fullServiceName
- the fully qualified service name that is prefixed with the package namemethodName
- the short method name@Nullable public static String extractFullServiceName(String fullMethodName)
null
if the input is malformed, but you cannot rely on it for the validity of the
input.@Nullable @ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/5635") public static String extractBareMethodName(String fullMethodName)
null
if the input is malformed, but you cannot rely on it for the validity of the input.@CheckReturnValue public static <ReqT,RespT> MethodDescriptor.Builder<ReqT,RespT> newBuilder()
MethodDescriptor
.@CheckReturnValue public static <ReqT,RespT> MethodDescriptor.Builder<ReqT,RespT> newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller)
MethodDescriptor
.@CheckReturnValue public MethodDescriptor.Builder<ReqT,RespT> toBuilder()
@CheckReturnValue public <NewReqT,NewRespT> MethodDescriptor.Builder<NewReqT,NewRespT> toBuilder(MethodDescriptor.Marshaller<NewReqT> requestMarshaller, MethodDescriptor.Marshaller<NewRespT> responseMarshaller)