Top Description Inners Fields Constructors Methods
io.grpc

public final Class MethodDescriptor<ReqT, RespT>

extends Object
Class Inheritance
Annotations
@Immutable
Static Imports
com.google.common.base.Preconditions.checkNotNull

Description of a remote method used by Channel to initiate a call.

Provides the name of the operation to execute as well as 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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
MethodDescriptor.Builder<ReqT, RespT>

A builder for a MethodDescriptor.

public static interface
MethodDescriptor.Marshaller<
type of serializable message
T
>

A typed abstraction over message serialization and deserialization, a.k.a. marshalling and unmarshalling.

public static enum
MethodDescriptor.MethodType

The call type of a method.

public static interface
MethodDescriptor.PrototypeMarshaller<T>

A marshaller that uses a fixed instance of the type it produces.

public static interface
MethodDescriptor.ReflectableMarshaller<T>

A marshaller that supports retrieving it's type parameter T at runtime.

Field Summary

Modifier and TypeField and Description
private final String
private final boolean
private final AtomicReferenceArray<Object>
private final MethodDescriptor.Marshaller<ReqT>
private final MethodDescriptor.Marshaller<RespT>
private final boolean
private final boolean
private final Object
private final String
private final MethodDescriptor.MethodType

Constructor Summary

AccessConstructor and Description
private
MethodDescriptor(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 TypeMethod and Description
public static <RequestT, ResponseT> MethodDescriptor<RequestT, ResponseT>
create(MethodDescriptor.MethodType
the call type of this method
type
,
String
the fully qualified name of this method
fullMethodName
,
MethodDescriptor.Marshaller<RequestT>
the marshaller used to encode and decode requests
requestMarshaller
,
MethodDescriptor.Marshaller<ResponseT>
the marshaller used to encode and decode responses
responseMarshaller
)

Deprecated use newBuilder().
Creates a new MethodDescriptor.
public static String
extractBareMethodName(String fullMethodName)

Extract the method name out of a fully qualified method name.

public static String
extractFullServiceName(String fullMethodName)

Extract the fully qualified service name out of a fully qualified method name.

public static String
generateFullMethodName(String
the fully qualified service name that is prefixed with the package name
fullServiceName
,
String
the short method name
methodName
)

Generate the fully qualified method name.

public String
getBareMethodName()

A convenience method for extractBareMethodName(getFullMethodName()).

public String
getFullMethodName()

The fully qualified name of the method.

pack-priv final Object

Returns:

a transport specific representation of the method name.
getRawMethodName
(int
the unique ID of the transport, given by InternalKnownTransport#ordinal.
transportOrdinal
)

Gets the cached "raw" method name for this Method Descriptor.

public MethodDescriptor.Marshaller<ReqT>
getRequestMarshaller()

Returns the marshaller for the request type.

public MethodDescriptor.Marshaller<RespT>
getResponseMarshaller()

Returns the marshaller for the response type.

public Object
getSchemaDescriptor()

Returns the schema descriptor for this method.

public String
getServiceName()

A convenience method for extractFullServiceName(getFullMethodName()).

public MethodDescriptor.MethodType
getType()

The call type of the method.

public boolean
isIdempotent()

Returns whether this method is idempotent.

public boolean
isSafe()

Returns whether this method is safe.

public boolean
isSampledToLocalTracing()

Returns whether RPCs for this method may be sampled into the local tracing store.

public static <ReqT, RespT> MethodDescriptor.Builder<ReqT, RespT>
newBuilder()

Creates a new builder for a MethodDescriptor.

public static <ReqT, RespT> MethodDescriptor.Builder<ReqT, RespT>
newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller)

Creates a new builder for a MethodDescriptor.

public ReqT

Returns:

a parsed instance of the message.
parseRequest
(InputStream
the serialized message as a byte stream.
input
)

Parse an incoming request message.

public RespT

Returns:

parsed response message object.
parseResponse
(InputStream
stream containing response message to parse.
input
)

Parse a response payload from the given InputStream.

pack-priv final void
setRawMethodName(int transportOrdinal, Object o)

Safely, but weakly, sets the raw method name for this Method Descriptor.

public InputStream

Returns:

serialized request message.
streamRequest
(ReqT
to serialize using the request Marshaller.
requestMessage
)

Convert a request message to an InputStream.

public InputStream

Returns:

the serialized message as a byte stream.
streamResponse
(RespT
the response message to serialize.
response
)

Serialize an outgoing response message.

public MethodDescriptor.Builder<ReqT, RespT>
toBuilder()

Turns this descriptor into a builder.

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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fullMethodNameback to summary
private final String fullMethodName
idempotentback to summary
private final boolean idempotent
rawMethodNamesback to summary
private final AtomicReferenceArray<Object> rawMethodNames
requestMarshallerback to summary
private final MethodDescriptor.Marshaller<ReqT> requestMarshaller
responseMarshallerback to summary
private final MethodDescriptor.Marshaller<RespT> responseMarshaller
safeback to summary
private final boolean safe
sampledToLocalTracingback to summary
private final boolean sampledToLocalTracing
schemaDescriptorback to summary
private final Object schemaDescriptor
Annotations
@Nullable
serviceNameback to summary
private final String serviceName
Annotations
@Nullable
typeback to summary
private final MethodDescriptor.MethodType type

Constructor Detail

MethodDescriptorback to summary
private MethodDescriptor(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller, Object schemaDescriptor, boolean idempotent, boolean safe, boolean sampledToLocalTracing)

Method Detail

createback to summary
public static <RequestT, ResponseT> MethodDescriptor<RequestT, ResponseT> create(MethodDescriptor.MethodType type, String fullMethodName, MethodDescriptor.Marshaller<RequestT> requestMarshaller, MethodDescriptor.Marshaller<ResponseT> responseMarshaller)

Deprecated

use newBuilder().

Creates a new MethodDescriptor.

Parameters
type:MethodDescriptor.MethodType

the call type of this method

fullMethodName:String

the fully qualified name of this method

requestMarshaller:MethodDescriptor.Marshaller<RequestT>

the marshaller used to encode and decode requests

responseMarshaller:MethodDescriptor.Marshaller<ResponseT>

the marshaller used to encode and decode responses

Annotations
@Deprecated
Since
1.0.0
extractBareMethodNameback to summary
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.

Annotations
@Nullable
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/5635
Since
1.33.0
extractFullServiceNameback to summary
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.

Annotations
@Nullable
Since
1.0.0
generateFullMethodNameback to summary
public static String generateFullMethodName(String fullServiceName, String methodName)

Generate the fully qualified method name. This matches the name

Parameters
fullServiceName:String

the fully qualified service name that is prefixed with the package name

methodName:String

the short method name

Since
1.0.0
getBareMethodNameback to summary
public String getBareMethodName()

A convenience method for extractBareMethodName(getFullMethodName()).

Annotations
@Nullable
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/5635
Since
1.33.0
getFullMethodNameback to summary
public String getFullMethodName()

The fully qualified name of the method.

Since
1.0.0
getRawMethodNameback to summary
pack-priv final Object getRawMethodName(int transportOrdinal)

Gets the cached "raw" method name for this Method Descriptor. The raw name is transport specific, and should be set using setRawMethodName by the transport.

Parameters
transportOrdinal:int

the unique ID of the transport, given by InternalKnownTransport#ordinal.

Returns:Object

a transport specific representation of the method name.

getRequestMarshallerback to summary
public MethodDescriptor.Marshaller<ReqT> getRequestMarshaller()

Returns the marshaller for the request type. Allows introspection of the request marshaller.

Since
1.1.0
getResponseMarshallerback to summary
public MethodDescriptor.Marshaller<RespT> getResponseMarshaller()

Returns the marshaller for the response type. Allows introspection of the response marshaller.

Since
1.1.0
getSchemaDescriptorback to summary
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.

Annotations
@Nullable
Since
1.7.0
getServiceNameback to summary
public String getServiceName()

A convenience method for extractFullServiceName(getFullMethodName()).

Annotations
@Nullable
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/5635
Since
1.21.0
getTypeback to summary
public MethodDescriptor.MethodType getType()

The call type of the method.

Since
1.0.0
isIdempotentback to summary
public boolean isIdempotent()

Returns whether this method is idempotent.

Since
1.0.0
isSafeback to summary
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
isSampledToLocalTracingback to summary
public boolean isSampledToLocalTracing()

Returns whether RPCs for this method may be sampled into the local tracing store.

newBuilderback to summary
public static <ReqT, RespT> MethodDescriptor.Builder<ReqT, RespT> newBuilder()

Creates a new builder for a MethodDescriptor.

Annotations
@CheckReturnValue
Since
1.1.0
newBuilderback to summary
public static <ReqT, RespT> MethodDescriptor.Builder<ReqT, RespT> newBuilder(MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller)

Creates a new builder for a MethodDescriptor.

Annotations
@CheckReturnValue
Since
1.1.0
parseRequestback to summary
public ReqT parseRequest(InputStream input)

Parse an incoming request message.

Parameters
input:InputStream

the serialized message as a byte stream.

Returns:ReqT

a parsed instance of the message.

Since
1.0.0
parseResponseback to summary
public RespT parseResponse(InputStream input)

Parse a response payload from the given InputStream.

Parameters
input:InputStream

stream containing response message to parse.

Returns:RespT

parsed response message object.

Since
1.0.0
setRawMethodNameback to summary
pack-priv final void setRawMethodName(int transportOrdinal, Object o)

Safely, but weakly, sets the raw method name for this Method Descriptor. This should only be called by the transport. See getRawMethodName for more detail.

streamRequestback to summary
public InputStream streamRequest(ReqT requestMessage)

Convert a request message to an InputStream. The returned InputStream should be closed by the caller.

Parameters
requestMessage:ReqT

to serialize using the request Marshaller.

Returns:InputStream

serialized request message.

Since
1.0.0
streamResponseback to summary
public InputStream streamResponse(RespT response)

Serialize an outgoing response message. The returned InputStream should be closed by the caller.

Parameters
response:RespT

the response message to serialize.

Returns:InputStream

the serialized message as a byte stream.

Since
1.0.0
toBuilderback to summary
public MethodDescriptor.Builder<ReqT, RespT> toBuilder()

Turns this descriptor into a builder.

Annotations
@CheckReturnValue
Since
1.1.0
toBuilderback to summary
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.

Annotations
@CheckReturnValue
Since
1.1.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
io.grpc back to summary

public final Class MethodDescriptor.Builder<ReqT, RespT>

extends Object
Class Inheritance

A builder for a MethodDescriptor.
Since
1.1.0

Field Summary

Modifier and TypeField and Description
private String
private boolean
private MethodDescriptor.Marshaller<ReqT>
private MethodDescriptor.Marshaller<RespT>
private boolean
private boolean
private Object
private MethodDescriptor.MethodType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public MethodDescriptor<ReqT, RespT>
build()

Builds the method descriptor.

public MethodDescriptor.Builder<ReqT, RespT>
setFullMethodName(String fullMethodName)

Sets the fully qualified (service and method) method name.

public MethodDescriptor.Builder<ReqT, RespT>
setIdempotent(boolean idempotent)

Sets whether the method is idempotent.

public MethodDescriptor.Builder<ReqT, RespT>
setRequestMarshaller(MethodDescriptor.Marshaller<ReqT>
the marshaller to use.
requestMarshaller
)

Sets the request marshaller.

public MethodDescriptor.Builder<ReqT, RespT>
setResponseMarshaller(MethodDescriptor.Marshaller<RespT>
the marshaller to use.
responseMarshaller
)

Sets the response marshaller.

public MethodDescriptor.Builder<ReqT, RespT>
setSafe(boolean safe)

Sets whether this method is safe.

public MethodDescriptor.Builder<ReqT, RespT>
setSampledToLocalTracing(boolean value)

Sets whether RPCs for this method may be sampled into the local tracing store.

public MethodDescriptor.Builder<ReqT, RespT>
setSchemaDescriptor(Object
an object that describes the service structure. Should be immutable.
schemaDescriptor
)

Sets the schema descriptor for this builder.

public MethodDescriptor.Builder<ReqT, RespT>
setType(MethodDescriptor.MethodType
the type of the method.
type
)

Sets the method type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fullMethodNameback to summary
private String fullMethodName
idempotentback to summary
private boolean idempotent
requestMarshallerback to summary
private MethodDescriptor.Marshaller<ReqT> requestMarshaller
responseMarshallerback to summary
private MethodDescriptor.Marshaller<RespT> responseMarshaller
safeback to summary
private boolean safe
sampledToLocalTracingback to summary
private boolean sampledToLocalTracing
schemaDescriptorback to summary
private Object schemaDescriptor
typeback to summary
private MethodDescriptor.MethodType type

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public MethodDescriptor<ReqT, RespT> build()

Builds the method descriptor.

Annotations
@CheckReturnValue
Since
1.1.0
setFullMethodNameback to summary
public MethodDescriptor.Builder<ReqT, RespT> setFullMethodName(String fullMethodName)

Sets the fully qualified (service and method) method name.

Since
1.1.0
See Also
MethodDescriptor#generateFullMethodName
setIdempotentback to summary
public MethodDescriptor.Builder<ReqT, RespT> setIdempotent(boolean idempotent)

Sets whether the method is idempotent. If true, calling this method more than once doesn't have additional side effects. If false, method is also not safe. Note that implies calling builder.setIdempotent(false).setIdempotent(true) will leave isSafe() == false.

Since
1.1.0
setRequestMarshallerback to summary
public MethodDescriptor.Builder<ReqT, RespT> setRequestMarshaller(MethodDescriptor.Marshaller<ReqT> requestMarshaller)

Sets the request marshaller.

Parameters
requestMarshaller:MethodDescriptor.Marshaller<ReqT>

the marshaller to use.

Since
1.1.0
setResponseMarshallerback to summary
public MethodDescriptor.Builder<ReqT, RespT> setResponseMarshaller(MethodDescriptor.Marshaller<RespT> responseMarshaller)

Sets the response marshaller.

Parameters
responseMarshaller:MethodDescriptor.Marshaller<RespT>

the marshaller to use.

Since
1.1.0
setSafeback to summary
public MethodDescriptor.Builder<ReqT, RespT> setSafe(boolean safe)

Sets whether this method is safe. If true, calling this method any number of times doesn't have side effects. If true, method is also idempotent. Note that implies calling builder.setSafe(true).setSafe(false) will leave isIdempotent() == true.

Since
1.1.0
setSampledToLocalTracingback to summary
public MethodDescriptor.Builder<ReqT, RespT> setSampledToLocalTracing(boolean value)

Sets whether RPCs for this method may be sampled into the local tracing store. If true, sampled traces of this method may be kept in memory by tracing libraries.

Since
1.8.0
setSchemaDescriptorback to summary
public MethodDescriptor.Builder<ReqT, RespT> setSchemaDescriptor(Object schemaDescriptor)

Sets the schema descriptor for this builder. A schema descriptor is an object that is not used by gRPC core but includes information related to the methods. The type of the object is specific to the consumer, so both the code calling this and the code calling MethodDescriptor#getSchemaDescriptor() must coordinate.

Parameters
schemaDescriptor:Object

an object that describes the service structure. Should be immutable.

Since
1.7.0
setTypeback to summary
public MethodDescriptor.Builder<ReqT, RespT> setType(MethodDescriptor.MethodType type)

Sets the method type.

Parameters
type:MethodDescriptor.MethodType

the type of the method.

Since
1.1.0
io.grpc back to summary

public Interface MethodDescriptor.Marshaller<T>

Known Direct Subinterfaces
io.grpc.MethodDescriptor.ReflectableMarshaller
Type Parameters
<T>
type of serializable message

A typed abstraction over message serialization and deserialization, a.k.a. marshalling and unmarshalling.

Stub implementations will define implementations of this interface for each of the request and response messages provided by a service.

Since
1.0.0

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

parsed value
parse
(InputStream
of bytes for serialized value
stream
)

Given an InputStream parse it into an instance of the declared type so that it can be passed to application code.

public InputStream

Returns:

serialized value as stream of bytes.
stream
(T
to serialize.
value
)

Given a message, produce an InputStream for it so that it can be written to the wire.

Method Detail

parseback to summary
public T parse(InputStream stream)

Given an InputStream parse it into an instance of the declared type so that it can be passed to application code.

Parameters
stream:InputStream

of bytes for serialized value

Returns:T

parsed value

streamback to summary
public InputStream stream(T value)

Given a message, produce an InputStream for it so that it can be written to the wire. Where possible implementations should produce streams that are io.grpc.KnownLength to improve transport efficiency.

Parameters
value:T

to serialize.

Returns:InputStream

serialized value as stream of bytes.

io.grpc back to summary

public final Enum MethodDescriptor.MethodType

extends Enum<MethodDescriptor.MethodType>
Class Inheritance

The call type of a method.
Since
1.0.0

Field Summary

Modifier and TypeField and Description
public static final MethodDescriptor.MethodType
BIDI_STREAMING

Zero or more request and response messages arbitrarily interleaved in time.

public static final MethodDescriptor.MethodType
CLIENT_STREAMING

Zero or more request messages with one response message.

public static final MethodDescriptor.MethodType
SERVER_STREAMING

One request message followed by zero or more response messages.

public static final MethodDescriptor.MethodType
UNARY

One request message followed by one response message.

public static final MethodDescriptor.MethodType
UNKNOWN

Cardinality and temporal relationships are not known.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public final boolean
clientSendsOneMessage()

Returns true for UNARY and SERVER_STREAMING, which do not permit the client to stream.

public final boolean
serverSendsOneMessage()

Returns true for UNARY and CLIENT_STREAMING, which do not permit the server to stream.

public static MethodDescriptor.MethodType
public static MethodDescriptor.MethodType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BIDI_STREAMINGback to summary
public static final MethodDescriptor.MethodType BIDI_STREAMING

Zero or more request and response messages arbitrarily interleaved in time.

CLIENT_STREAMINGback to summary
public static final MethodDescriptor.MethodType CLIENT_STREAMING

Zero or more request messages with one response message.

SERVER_STREAMINGback to summary
public static final MethodDescriptor.MethodType SERVER_STREAMING

One request message followed by zero or more response messages.

UNARYback to summary
public static final MethodDescriptor.MethodType UNARY

One request message followed by one response message.

UNKNOWNback to summary
public static final MethodDescriptor.MethodType UNKNOWN

Cardinality and temporal relationships are not known. Implementations should not make buffering assumptions and should largely treat the same as BIDI_STREAMING.

Constructor Detail

MethodTypeback to summary
private MethodType()

Method Detail

clientSendsOneMessageback to summary
public final boolean clientSendsOneMessage()

Returns true for UNARY and SERVER_STREAMING, which do not permit the client to stream.

Since
1.0.0
serverSendsOneMessageback to summary
public final boolean serverSendsOneMessage()

Returns true for UNARY and CLIENT_STREAMING, which do not permit the server to stream.

Since
1.0.0
valueOfback to summary
public static MethodDescriptor.MethodType valueOf(String name)
valuesback to summary
public static MethodDescriptor.MethodType[] values()
io.grpc back to summary

public Interface MethodDescriptor.PrototypeMarshaller<T>

extends MethodDescriptor.ReflectableMarshaller<T>
Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/2222

A marshaller that uses a fixed instance of the type it produces.
Since
1.1.0

Method Summary

Modifier and TypeMethod and Description
public T
getMessagePrototype()

An instance of the expected message type, typically used as a schema and helper for producing other message instances.

Inherited from io.grpc.MethodDescriptor.ReflectableMarshaller:
getMessageClass

Method Detail

getMessagePrototypeback to summary
public T getMessagePrototype()

An instance of the expected message type, typically used as a schema and helper for producing other message instances. The null value may be a special value for the marshaller (like the equivalent of Void), so it is a valid return value. null does not mean "unsupported" or "unknown".

It is generally expected this would return the same instance each invocation, but it is not a requirement.

Annotations
@Nullable
io.grpc back to summary

public Interface MethodDescriptor.ReflectableMarshaller<T>

extends MethodDescriptor.Marshaller<T>
Known Direct Subinterfaces
io.grpc.MethodDescriptor.PrototypeMarshaller
Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/2222

A marshaller that supports retrieving it's type parameter T at runtime.
Since
1.1.0

Method Summary

Modifier and TypeMethod and Description
public Class<T>

Returns:

non-null base class for all objects produced and consumed by this marshaller
getMessageClass
()

Returns the Class that this marshaller serializes and deserializes.

Inherited from io.grpc.MethodDescriptor.Marshaller:
parsestream

Method Detail

getMessageClassback to summary
public Class<T> getMessageClass()

Returns the Class that this marshaller serializes and deserializes. If inheritance is allowed, this is the base class or interface for all supported classes.

Returns:Class<T>

non-null base class for all objects produced and consumed by this marshaller