in servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java [948:1053]
private static MethodSpec newRpcMethodSpec(
final ClassName inClass, final ClassName outClass, final String methodName,
final boolean clientSteaming, final boolean serverStreaming,
final EnumSet<NewRpcMethodFlag> flags, final boolean printJavaDocs,
final BiFunction<String, MethodSpec.Builder, MethodSpec.Builder> methodBuilderCustomizer) {
final MethodSpec.Builder methodSpecBuilder = methodBuilderCustomizer.apply(methodName,
methodBuilder(methodName)).addModifiers(PUBLIC);
final Modifier[] mods = flags.contains(INTERFACE) ? new Modifier[0] : new Modifier[]{FINAL};
if (flags.contains(BLOCKING)) {
if (clientSteaming) {
if (flags.contains(CLIENT)) {
methodSpecBuilder.addParameter(ParameterizedTypeName.get(ClassName.get(Iterable.class),
inClass), request, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request +
" used to send a stream of type {@link $T} to the server." + lineSeparator(), inClass);
}
} else {
methodSpecBuilder.addParameter(ParameterizedTypeName.get(BlockingIterable, inClass), request, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request +
" used to read the stream of type {@link $T} from the client." + lineSeparator(), inClass);
}
}
} else {
methodSpecBuilder.addParameter(inClass, request, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request + " the request from the client." +
lineSeparator());
}
}
if (serverStreaming) {
if (flags.contains(CLIENT)) {
methodSpecBuilder.returns(ParameterizedTypeName.get(BlockingIterable, outClass));
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(
JAVADOC_RETURN + "used to read the response stream of type {@link $T} from the server."
+ lineSeparator(), outClass);
}
} else {
methodSpecBuilder.addParameter(ParameterizedTypeName.get(GrpcPayloadWriter, outClass),
responseWriter, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + responseWriter +
" used to write a stream of type {@link $T} to the server." + lineSeparator() +
"The implementation of this method is responsible for calling {@link $T#close()}." +
lineSeparator(), outClass, GrpcPayloadWriter);
}
}
} else {
methodSpecBuilder.returns(outClass);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_RETURN + (flags.contains(CLIENT) ?
"the response from the server." :
"the response to send to the client") + lineSeparator());
}
}
methodSpecBuilder.addException(Exception.class);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_THROWS + "$T if an unexpected application error occurs." +
lineSeparator(), Exception.class)
.addJavadoc(JAVADOC_THROWS +
"$T if an expected application exception occurs. Its contents will be serialized and " +
"propagated to the peer.", GrpcStatusException);
}
} else {
if (clientSteaming) {
methodSpecBuilder.addParameter(ParameterizedTypeName.get(Publisher, inClass), request, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request +
" used to write a stream of type {@link $T} to the server." + lineSeparator(), inClass);
}
} else {
methodSpecBuilder.addParameter(inClass, request, mods);
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request +
(flags.contains(CLIENT) ?
" the request to send to the server." :
" the request from the client.") + lineSeparator());
}
}
if (serverStreaming) {
methodSpecBuilder.returns(ParameterizedTypeName.get(Publisher, outClass));
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_RETURN + (flags.contains(CLIENT) ?
"used to read a stream of type {@link $T} from the server." :
"used to write a stream of type {@link $T} to the client.")
+ lineSeparator(), outClass);
}
} else {
methodSpecBuilder.returns(ParameterizedTypeName.get(Single, outClass));
if (printJavaDocs) {
methodSpecBuilder.addJavadoc(JAVADOC_RETURN + (flags.contains(CLIENT) ?
"a {@link $T} which completes when the response is received from the server." :
"a {@link $T} which sends the response to the client when it terminates.")
+ lineSeparator(), Single);
}
}
}
return methodSpecBuilder.build();
}