mirror of https://github.com/grpc/grpc-java.git
Use ReqT and RespT for generics
This commit is contained in:
parent
ae4ee40711
commit
950fe1d108
|
|
@ -61,10 +61,10 @@ package io.grpc;
|
||||||
* {@link Status#CANCELLED CANCELLED}. Otherwise, {@link Listener#onClose Listener.onClose()} is
|
* {@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.
|
* 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 <ReqT> 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 <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.
|
* 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
|
* @throws IllegalStateException if a method (including {@code start()}) on this class has been
|
||||||
* called.
|
* 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
|
* 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.
|
* @param message message to be sent to the server.
|
||||||
* @throws IllegalStateException if call is {@link #halfClose}d or explicitly {@link #cancel}ed
|
* @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
|
* If {@code true}, indicates that the call is capable of sending additional messages
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,6 @@ public interface ClientInterceptor {
|
||||||
* @param next the channel which is being intercepted.
|
* @param next the channel which is being intercepted.
|
||||||
* @return the call object for the remote operation, never {@code null}.
|
* @return the call object for the remote operation, never {@code null}.
|
||||||
*/
|
*/
|
||||||
<RequestT, ResponseT> ClientCall<RequestT, ResponseT> interceptCall(
|
<ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
|
||||||
MethodDescriptor<RequestT, ResponseT> method,
|
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next);
|
||||||
CallOptions callOptions,
|
|
||||||
Channel next);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,12 @@ import javax.annotation.concurrent.Immutable;
|
||||||
* <p>Can be constructed manually but will often be generated by stub code generators.
|
* <p>Can be constructed manually but will often be generated by stub code generators.
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
public class MethodDescriptor<RequestT, ResponseT> {
|
public class MethodDescriptor<ReqT, RespT> {
|
||||||
|
|
||||||
private final MethodType type;
|
private final MethodType type;
|
||||||
private final String fullMethodName;
|
private final String fullMethodName;
|
||||||
private final Marshaller<RequestT> requestMarshaller;
|
private final Marshaller<ReqT> requestMarshaller;
|
||||||
private final Marshaller<ResponseT> responseMarshaller;
|
private final Marshaller<RespT> responseMarshaller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The call type of a method.
|
* The call type of a method.
|
||||||
|
|
@ -150,8 +150,8 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodDescriptor(MethodType type, String fullMethodName,
|
private MethodDescriptor(MethodType type, String fullMethodName,
|
||||||
Marshaller<RequestT> requestMarshaller,
|
Marshaller<ReqT> requestMarshaller,
|
||||||
Marshaller<ResponseT> responseMarshaller) {
|
Marshaller<RespT> responseMarshaller) {
|
||||||
this.type = Preconditions.checkNotNull(type, "type");
|
this.type = Preconditions.checkNotNull(type, "type");
|
||||||
this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName");
|
this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName");
|
||||||
this.requestMarshaller = Preconditions.checkNotNull(requestMarshaller, "requestMarshaller");
|
this.requestMarshaller = Preconditions.checkNotNull(requestMarshaller, "requestMarshaller");
|
||||||
|
|
@ -178,7 +178,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
||||||
* @param input stream containing response message to parse.
|
* @param input stream containing response message to parse.
|
||||||
* @return parsed response message object.
|
* @return parsed response message object.
|
||||||
*/
|
*/
|
||||||
public ResponseT parseResponse(InputStream input) {
|
public RespT parseResponse(InputStream input) {
|
||||||
return responseMarshaller.parse(input);
|
return responseMarshaller.parse(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,7 +188,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
||||||
* @param requestMessage to serialize using the request {@link Marshaller}.
|
* @param requestMessage to serialize using the request {@link Marshaller}.
|
||||||
* @return serialized request message.
|
* @return serialized request message.
|
||||||
*/
|
*/
|
||||||
public InputStream streamRequest(RequestT requestMessage) {
|
public InputStream streamRequest(ReqT requestMessage) {
|
||||||
return requestMarshaller.stream(requestMessage);
|
return requestMarshaller.stream(requestMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
||||||
* @param input the serialized message as a byte stream.
|
* @param input the serialized message as a byte stream.
|
||||||
* @return a parsed instance of the message.
|
* @return a parsed instance of the message.
|
||||||
*/
|
*/
|
||||||
public RequestT parseRequest(InputStream input) {
|
public ReqT parseRequest(InputStream input) {
|
||||||
return requestMarshaller.parse(input);
|
return requestMarshaller.parse(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ public class MethodDescriptor<RequestT, ResponseT> {
|
||||||
* @param response the response message to serialize.
|
* @param response the response message to serialize.
|
||||||
* @return the serialized message as a byte stream.
|
* @return the serialized message as a byte stream.
|
||||||
*/
|
*/
|
||||||
public InputStream streamResponse(ResponseT response) {
|
public InputStream streamResponse(RespT response) {
|
||||||
return responseMarshaller.stream(response);
|
return responseMarshaller.stream(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ package io.grpc;
|
||||||
*
|
*
|
||||||
* <p>Methods are guaranteed to be non-blocking. Implementations are not required to be thread-safe.
|
* <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.
|
* 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
|
// 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
|
// 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.
|
// 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
|
* A request message has been received. For streaming calls, there may be zero or more request
|
||||||
* messages.
|
* messages.
|
||||||
*
|
*
|
||||||
* @param message a received request message.
|
* @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.
|
* 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.
|
* @param message response message.
|
||||||
* @throws IllegalStateException if call is {@link #close}d
|
* @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
|
* If {@code true}, indicates that the call is capable of sending additional messages
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,9 @@ public interface ServerInterceptor {
|
||||||
* @param next next processor in the interceptor chain
|
* @param next next processor in the interceptor chain
|
||||||
* @return listener for processing incoming messages for {@code call}, never {@code null}.
|
* @return listener for processing incoming messages for {@code call}, never {@code null}.
|
||||||
*/
|
*/
|
||||||
<RequestT, ResponseT> ServerCall.Listener<RequestT> interceptCall(
|
<ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
||||||
MethodDescriptor<RequestT, ResponseT> method,
|
MethodDescriptor<ReqT, RespT> method,
|
||||||
ServerCall<ResponseT> call,
|
ServerCall<RespT> call,
|
||||||
Metadata headers,
|
Metadata headers,
|
||||||
ServerCallHandler<RequestT, ResponseT> next);
|
ServerCallHandler<ReqT, RespT> next);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,14 @@ package io.grpc;
|
||||||
/**
|
/**
|
||||||
* Definition of a method exposed by a {@link Server}.
|
* Definition of a method exposed by a {@link Server}.
|
||||||
*/
|
*/
|
||||||
public final class ServerMethodDefinition<RequestT, ResponseT> {
|
public final class ServerMethodDefinition<ReqT, RespT> {
|
||||||
private final MethodDescriptor<RequestT, ResponseT> method;
|
private final MethodDescriptor<ReqT, RespT> method;
|
||||||
private final ServerCallHandler<RequestT, ResponseT> handler;
|
private final ServerCallHandler<ReqT, RespT> handler;
|
||||||
|
|
||||||
// ServerMethodDefinition has no form of public construction. It is only created within the
|
// ServerMethodDefinition has no form of public construction. It is only created within the
|
||||||
// context of a ServerServiceDefinition.Builder.
|
// context of a ServerServiceDefinition.Builder.
|
||||||
ServerMethodDefinition(MethodDescriptor<RequestT, ResponseT> method,
|
ServerMethodDefinition(MethodDescriptor<ReqT, RespT> method,
|
||||||
ServerCallHandler<RequestT, ResponseT> handler) {
|
ServerCallHandler<ReqT, RespT> handler) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
@ -53,19 +53,19 @@ public final class ServerMethodDefinition<RequestT, ResponseT> {
|
||||||
* @param handler to dispatch calls to.
|
* @param handler to dispatch calls to.
|
||||||
* @return a new instance.
|
* @return a new instance.
|
||||||
*/
|
*/
|
||||||
public static <RequestT, ResponseT> ServerMethodDefinition<RequestT, ResponseT> create(
|
public static <ReqT, RespT> ServerMethodDefinition<ReqT, RespT> create(
|
||||||
MethodDescriptor<RequestT, ResponseT> method,
|
MethodDescriptor<ReqT, RespT> method,
|
||||||
ServerCallHandler<RequestT, ResponseT> handler) {
|
ServerCallHandler<ReqT, RespT> handler) {
|
||||||
return new ServerMethodDefinition<RequestT, ResponseT>(method, handler);
|
return new ServerMethodDefinition<ReqT, RespT>(method, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The {@code MethodDescriptor} for this method. */
|
/** The {@code MethodDescriptor} for this method. */
|
||||||
public MethodDescriptor<RequestT, ResponseT> getMethodDescriptor() {
|
public MethodDescriptor<ReqT, RespT> getMethodDescriptor() {
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handler for incoming calls. */
|
/** Handler for incoming calls. */
|
||||||
public ServerCallHandler<RequestT, ResponseT> getServerCallHandler() {
|
public ServerCallHandler<ReqT, RespT> getServerCallHandler() {
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,8 +75,8 @@ public final class ServerMethodDefinition<RequestT, ResponseT> {
|
||||||
* @param handler to bind to a cloned instance of this.
|
* @param handler to bind to a cloned instance of this.
|
||||||
* @return a cloned instance of this with the new handler bound.
|
* @return a cloned instance of this with the new handler bound.
|
||||||
*/
|
*/
|
||||||
public ServerMethodDefinition<RequestT, ResponseT> withServerCallHandler(
|
public ServerMethodDefinition<ReqT, RespT> withServerCallHandler(
|
||||||
ServerCallHandler<RequestT, ResponseT> handler) {
|
ServerCallHandler<ReqT, RespT> handler) {
|
||||||
return new ServerMethodDefinition<RequestT, ResponseT>(method, handler);
|
return new ServerMethodDefinition<ReqT, RespT>(method, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue