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
diff --git a/core/src/main/java/com/google/net/stubby/MethodDescriptor.java b/core/src/main/java/com/google/net/stubby/MethodDescriptor.java
index 30c51b0..a9ab6b4 100644
--- a/core/src/main/java/com/google/net/stubby/MethodDescriptor.java
+++ b/core/src/main/java/com/google/net/stubby/MethodDescriptor.java
@@ -19,6 +19,14 @@
@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 @@
}
};
+ private final Type type;
private final String name;
private final Marshaller<RequestT> requestMarshaller;
private final Marshaller<ResponseT> responseMarshaller;
@@ -34,18 +43,19 @@
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;
@@ -55,6 +65,13 @@
}
/**
+ * The call type of the method.
+ */
+ public Type getType() {
+ return type;
+ }
+
+ /**
* The fully qualified name of the method
*/
public String getName() {
@@ -96,7 +113,7 @@
* 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 @@
* 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());