mirror of https://github.com/grpc/grpc-java.git
Adds call type to MethodDescriptor as some transports need to know whether
the call is unary or streaming when starting the call. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=71867037
This commit is contained in:
parent
f97eb733f7
commit
712e9c1201
|
@ -19,6 +19,14 @@ import javax.inject.Provider;
|
|||
@Immutable
|
||||
public class MethodDescriptor<RequestT, ResponseT> {
|
||||
|
||||
public enum Type {
|
||||
UNARY,
|
||||
CLIENT_STREAMING,
|
||||
SERVER_STREAMING,
|
||||
DUPLEX_STREAMING,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private static final Function<Provider<String>,String> HEADER_SNAPSHOT =
|
||||
new Function<Provider<String>, String>() {
|
||||
@Override
|
||||
|
@ -27,6 +35,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
|||
}
|
||||
};
|
||||
|
||||
private final Type type;
|
||||
private final String name;
|
||||
private final Marshaller<RequestT> requestMarshaller;
|
||||
private final Marshaller<ResponseT> responseMarshaller;
|
||||
|
@ -34,18 +43,19 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
|||
private final ImmutableMap<String, Provider<String>> headers;
|
||||
|
||||
public static <RequestT, ResponseT> MethodDescriptor<RequestT, ResponseT> create(
|
||||
String name, long timeout, TimeUnit timeoutUnit,
|
||||
Type type, String name, long timeout, TimeUnit timeoutUnit,
|
||||
Marshaller<RequestT> requestMarshaller,
|
||||
Marshaller<ResponseT> responseMarshaller) {
|
||||
return new MethodDescriptor<RequestT, ResponseT>(
|
||||
name, timeoutUnit.toMicros(timeout), requestMarshaller, responseMarshaller,
|
||||
type, name, timeoutUnit.toMicros(timeout), requestMarshaller, responseMarshaller,
|
||||
ImmutableMap.<String, Provider<String>>of());
|
||||
}
|
||||
|
||||
private MethodDescriptor(String name, long timeoutMicros,
|
||||
private MethodDescriptor(Type type, String name, long timeoutMicros,
|
||||
Marshaller<RequestT> requestMarshaller,
|
||||
Marshaller<ResponseT> responseMarshaller,
|
||||
ImmutableMap<String, Provider<String>> headers) {
|
||||
this.type = Preconditions.checkNotNull(type);
|
||||
this.name = name;
|
||||
Preconditions.checkArgument(timeoutMicros > 0);
|
||||
this.timeoutMicros = timeoutMicros;
|
||||
|
@ -54,6 +64,13 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
|||
this.headers = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* The call type of the method.
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The fully qualified name of the method
|
||||
*/
|
||||
|
@ -96,7 +113,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
|||
* Create a new descriptor with a different timeout
|
||||
*/
|
||||
public MethodDescriptor withTimeout(long timeout, TimeUnit unit) {
|
||||
return new MethodDescriptor<RequestT, ResponseT>(name, unit.toMicros(timeout),
|
||||
return new MethodDescriptor<RequestT, ResponseT>(type, name, unit.toMicros(timeout),
|
||||
requestMarshaller, responseMarshaller, headers);
|
||||
}
|
||||
|
||||
|
@ -104,7 +121,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
|||
* Create a new descriptor with an additional bound header.
|
||||
*/
|
||||
public MethodDescriptor withHeader(String headerName, Provider<String> headerValueProvider) {
|
||||
return new MethodDescriptor<RequestT, ResponseT>(name, timeoutMicros,
|
||||
return new MethodDescriptor<RequestT, ResponseT>(type, name, timeoutMicros,
|
||||
requestMarshaller, responseMarshaller,
|
||||
ImmutableMap.<String, Provider<String>>builder().
|
||||
putAll(headers).put(headerName, headerValueProvider).build());
|
||||
|
|
Loading…
Reference in New Issue