Use ReqT and RespT for generics

This commit is contained in:
Carl Mastrangelo 2015-09-08 12:39:14 -07:00
parent ae4ee40711
commit 950fe1d108
6 changed files with 39 additions and 41 deletions

View File

@ -61,10 +61,10 @@ package io.grpc;
* {@link Status#CANCELLED CANCELLED}. Otherwise, {@link Listener#onClose Listener.onClose()} is
* called with whatever status the RPC was finished. We ensure that at most one is called.
*
* @param <RequestT> type of message sent one or more times to the server.
* @param <ResponseT> type of message received one or more times from the server.
* @param <ReqT> type of message sent one or more times to the server.
* @param <RespT> type of message received one or more times from the server.
*/
public abstract class ClientCall<RequestT, ResponseT> {
public abstract class ClientCall<ReqT, RespT> {
/**
* Callbacks for receiving metadata, response messages and completion status from the server.
*
@ -123,7 +123,7 @@ public abstract class ClientCall<RequestT, ResponseT> {
* @throws IllegalStateException if a method (including {@code start()}) on this class has been
* called.
*/
public abstract void start(Listener<ResponseT> responseListener, Metadata headers);
public abstract void start(Listener<RespT> responseListener, Metadata headers);
/**
* Requests up to the given number of messages from the call to be delivered to
@ -170,7 +170,7 @@ public abstract class ClientCall<RequestT, ResponseT> {
* @param message message to be sent to the server.
* @throws IllegalStateException if call is {@link #halfClose}d or explicitly {@link #cancel}ed
*/
public abstract void sendMessage(RequestT message);
public abstract void sendMessage(ReqT message);
/**
* If {@code true}, indicates that the call is capable of sending additional messages

View File

@ -58,8 +58,6 @@ public interface ClientInterceptor {
* @param next the channel which is being intercepted.
* @return the call object for the remote operation, never {@code null}.
*/
<RequestT, ResponseT> ClientCall<RequestT, ResponseT> interceptCall(
MethodDescriptor<RequestT, ResponseT> method,
CallOptions callOptions,
Channel next);
<ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next);
}

View File

@ -47,12 +47,12 @@ import javax.annotation.concurrent.Immutable;
* <p>Can be constructed manually but will often be generated by stub code generators.
*/
@Immutable
public class MethodDescriptor<RequestT, ResponseT> {
public class MethodDescriptor<ReqT, RespT> {
private final MethodType type;
private final String fullMethodName;
private final Marshaller<RequestT> requestMarshaller;
private final Marshaller<ResponseT> responseMarshaller;
private final Marshaller<ReqT> requestMarshaller;
private final Marshaller<RespT> responseMarshaller;
/**
* The call type of a method.
@ -150,8 +150,8 @@ public class MethodDescriptor<RequestT, ResponseT> {
}
private MethodDescriptor(MethodType type, String fullMethodName,
Marshaller<RequestT> requestMarshaller,
Marshaller<ResponseT> responseMarshaller) {
Marshaller<ReqT> requestMarshaller,
Marshaller<RespT> responseMarshaller) {
this.type = Preconditions.checkNotNull(type, "type");
this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName");
this.requestMarshaller = Preconditions.checkNotNull(requestMarshaller, "requestMarshaller");
@ -178,7 +178,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
* @param input stream containing response message to parse.
* @return parsed response message object.
*/
public ResponseT parseResponse(InputStream input) {
public RespT parseResponse(InputStream input) {
return responseMarshaller.parse(input);
}
@ -188,7 +188,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
* @param requestMessage to serialize using the request {@link Marshaller}.
* @return serialized request message.
*/
public InputStream streamRequest(RequestT requestMessage) {
public InputStream streamRequest(ReqT requestMessage) {
return requestMarshaller.stream(requestMessage);
}
@ -198,7 +198,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
* @param input the serialized message as a byte stream.
* @return a parsed instance of the message.
*/
public RequestT parseRequest(InputStream input) {
public ReqT parseRequest(InputStream input) {
return requestMarshaller.parse(input);
}
@ -208,7 +208,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
* @param response the response message to serialize.
* @return the serialized message as a byte stream.
*/
public InputStream streamResponse(ResponseT response) {
public InputStream streamResponse(RespT response) {
return responseMarshaller.stream(response);
}

View File

@ -46,9 +46,9 @@ package io.grpc;
*
* <p>Methods are guaranteed to be non-blocking. Implementations are not required to be thread-safe.
*
* @param <ResponseT> parsed type of response message.
* @param <RespT> parsed type of response message.
*/
public abstract class ServerCall<ResponseT> {
public abstract class ServerCall<RespT> {
/**
* Callbacks for consuming incoming RPC messages.
*
@ -61,14 +61,14 @@ public abstract class ServerCall<ResponseT> {
// TODO(ejona86): We need to decide what to do in the case of server closing with non-cancellation
// before client half closes. It may be that we treat such a case as an error. If we permit such
// a case then we either get to generate a half close or purposefully omit it.
public abstract static class Listener<RequestT> {
public abstract static class Listener<ReqT> {
/**
* A request message has been received. For streaming calls, there may be zero or more request
* messages.
*
* @param message a received request message.
*/
public void onMessage(RequestT message) {}
public void onMessage(ReqT message) {}
/**
* The client completed all message sending. However, the call may still be cancelled.
@ -130,7 +130,7 @@ public abstract class ServerCall<ResponseT> {
* @param message response message.
* @throws IllegalStateException if call is {@link #close}d
*/
public abstract void sendMessage(ResponseT message);
public abstract void sendMessage(RespT message);
/**
* If {@code true}, indicates that the call is capable of sending additional messages

View File

@ -61,9 +61,9 @@ public interface ServerInterceptor {
* @param next next processor in the interceptor chain
* @return listener for processing incoming messages for {@code call}, never {@code null}.
*/
<RequestT, ResponseT> ServerCall.Listener<RequestT> interceptCall(
MethodDescriptor<RequestT, ResponseT> method,
ServerCall<ResponseT> call,
<ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
MethodDescriptor<ReqT, RespT> method,
ServerCall<RespT> call,
Metadata headers,
ServerCallHandler<RequestT, ResponseT> next);
ServerCallHandler<ReqT, RespT> next);
}

View File

@ -34,14 +34,14 @@ package io.grpc;
/**
* Definition of a method exposed by a {@link Server}.
*/
public final class ServerMethodDefinition<RequestT, ResponseT> {
private final MethodDescriptor<RequestT, ResponseT> method;
private final ServerCallHandler<RequestT, ResponseT> handler;
public final class ServerMethodDefinition<ReqT, RespT> {
private final MethodDescriptor<ReqT, RespT> method;
private final ServerCallHandler<ReqT, RespT> handler;
// ServerMethodDefinition has no form of public construction. It is only created within the
// context of a ServerServiceDefinition.Builder.
ServerMethodDefinition(MethodDescriptor<RequestT, ResponseT> method,
ServerCallHandler<RequestT, ResponseT> handler) {
ServerMethodDefinition(MethodDescriptor<ReqT, RespT> method,
ServerCallHandler<ReqT, RespT> handler) {
this.method = method;
this.handler = handler;
}
@ -53,19 +53,19 @@ public final class ServerMethodDefinition<RequestT, ResponseT> {
* @param handler to dispatch calls to.
* @return a new instance.
*/
public static <RequestT, ResponseT> ServerMethodDefinition<RequestT, ResponseT> create(
MethodDescriptor<RequestT, ResponseT> method,
ServerCallHandler<RequestT, ResponseT> handler) {
return new ServerMethodDefinition<RequestT, ResponseT>(method, handler);
public static <ReqT, RespT> ServerMethodDefinition<ReqT, RespT> create(
MethodDescriptor<ReqT, RespT> method,
ServerCallHandler<ReqT, RespT> handler) {
return new ServerMethodDefinition<ReqT, RespT>(method, handler);
}
/** The {@code MethodDescriptor} for this method. */
public MethodDescriptor<RequestT, ResponseT> getMethodDescriptor() {
public MethodDescriptor<ReqT, RespT> getMethodDescriptor() {
return method;
}
/** Handler for incoming calls. */
public ServerCallHandler<RequestT, ResponseT> getServerCallHandler() {
public ServerCallHandler<ReqT, RespT> getServerCallHandler() {
return handler;
}
@ -75,8 +75,8 @@ public final class ServerMethodDefinition<RequestT, ResponseT> {
* @param handler to bind to a cloned instance of this.
* @return a cloned instance of this with the new handler bound.
*/
public ServerMethodDefinition<RequestT, ResponseT> withServerCallHandler(
ServerCallHandler<RequestT, ResponseT> handler) {
return new ServerMethodDefinition<RequestT, ResponseT>(method, handler);
public ServerMethodDefinition<ReqT, RespT> withServerCallHandler(
ServerCallHandler<ReqT, RespT> handler) {
return new ServerMethodDefinition<ReqT, RespT>(method, handler);
}
}