Skip to content

Commit 14bf024

Browse files
committed
Javadoc generation and cosmetics.
1 parent 9d70ee8 commit 14bf024

File tree

6 files changed

+516
-158
lines changed

6 files changed

+516
-158
lines changed

vertx-grpc-docs/src/main/java/examples/GreeterClient.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,74 @@
1414
import io.vertx.grpc.common.GrpcMessageDecoder;
1515
import io.vertx.grpc.common.GrpcMessageEncoder;
1616

17+
/**
18+
* <p>A client for invoking the Greeter gRPC service.</p>
19+
*/
1720
@io.vertx.codegen.annotations.VertxGen
1821
public interface GreeterClient {
1922

23+
/**
24+
* SayHello protobuf RPC client service method.
25+
*/
2026
@io.vertx.codegen.annotations.GenIgnore(io.vertx.codegen.annotations.GenIgnore.PERMITTED_TYPE)
21-
public static final ServiceMethod<examples.HelloReply, examples.HelloRequest> SayHello = ServiceMethod.client(
27+
ServiceMethod<examples.HelloReply, examples.HelloRequest> SayHello = ServiceMethod.client(
2228
ServiceName.create("helloworld", "Greeter"),
2329
"SayHello",
2430
GrpcMessageEncoder.encoder(),
2531
GrpcMessageDecoder.decoder(examples.HelloReply.parser()));
2632

33+
/**
34+
* Json client service methods.
35+
*/
2736
@io.vertx.codegen.annotations.GenIgnore(io.vertx.codegen.annotations.GenIgnore.PERMITTED_TYPE)
28-
public final class Json {
37+
final class Json {
38+
39+
/**
40+
* SayHello json RPC client service method.
41+
*/
2942
public static final ServiceMethod<examples.HelloReply, examples.HelloRequest> SayHello = ServiceMethod.client(
3043
ServiceName.create("helloworld", "Greeter"),
3144
"SayHello",
3245
GrpcMessageEncoder.json(),
3346
GrpcMessageDecoder.json(() -> examples.HelloReply.newBuilder()));
3447
}
3548

36-
static GreeterClient create(GrpcClient client, SocketAddress socketAddress) {
37-
return new GreeterClientImpl(client, socketAddress);
49+
/**
50+
* Create and return a Greeter gRPC service client. The assumed wire format is Protobuf.
51+
*
52+
* @param client the gRPC client
53+
* @param host the host providing the service
54+
* @return the configured client
55+
*/
56+
static GreeterClient create(GrpcClient client, SocketAddress host) {
57+
return new GreeterClientImpl(client, host);
3858
}
3959

40-
static GreeterClient create(GrpcClient client, SocketAddress socketAddress, io.vertx.grpc.common.WireFormat wireFormat) {
41-
return new GreeterClientImpl(client, socketAddress, wireFormat);
60+
/**
61+
* Create and return a Greeter gRPC service client.
62+
*
63+
* @param client the gRPC client
64+
* @param host the host providing the service
65+
* @param wireFormat the wire format
66+
* @return the configured client
67+
*/
68+
static GreeterClient create(GrpcClient client, SocketAddress host, io.vertx.grpc.common.WireFormat wireFormat) {
69+
return new GreeterClientImpl(client, host, wireFormat);
4270
}
4371

72+
/**
73+
* Calls the SayHello RPC service method.
74+
*
75+
* @param request the examples.HelloRequest request message
76+
* @return a future of the examples.HelloReply response message
77+
*/
4478
@io.vertx.codegen.annotations.GenIgnore(io.vertx.codegen.annotations.GenIgnore.PERMITTED_TYPE)
4579
Future<examples.HelloReply> sayHello(examples.HelloRequest request);
46-
4780
}
4881

82+
/**
83+
* The proxy implementation.
84+
*/
4985
class GreeterClientImpl implements GreeterClient {
5086

5187
private final GrpcClient client;
@@ -63,8 +99,8 @@ class GreeterClientImpl implements GreeterClient {
6399
}
64100

65101
public Future<examples.HelloReply> sayHello(examples.HelloRequest request) {
66-
ServiceMethod<examples.HelloReply,examples.HelloRequest> serviceMethod;
67-
switch(wireFormat) {
102+
ServiceMethod<examples.HelloReply, examples.HelloRequest> serviceMethod;
103+
switch (wireFormat) {
68104
case PROTOBUF:
69105
serviceMethod = SayHello;
70106
break;

vertx-grpc-docs/src/main/java/examples/GreeterService.java

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.vertx.core.Promise;
55
import io.vertx.core.Handler;
66
import io.vertx.core.http.HttpMethod;
7-
import io.vertx.core.http.HttpServerRequest;
87
import io.vertx.core.streams.ReadStream;
98
import io.vertx.core.streams.WriteStream;
109
import io.vertx.grpc.common.GrpcStatus;
@@ -14,41 +13,65 @@
1413
import io.vertx.grpc.common.GrpcWriteStream;
1514
import io.vertx.grpc.common.GrpcMessageDecoder;
1615
import io.vertx.grpc.common.GrpcMessageEncoder;
17-
import io.vertx.grpc.server.GrpcServerResponse;
1816
import io.vertx.grpc.server.GrpcServer;
1917

20-
import java.util.ArrayList;
2118
import java.util.List;
2219

23-
public class GreeterService {
24-
20+
/**
21+
* <p>Provides support for RPC methods implementations of the Greeter gRPC service.</p>
22+
*
23+
* <p>The following methods of this class should be overridden to provide an implementation of the service:</p>
24+
* <ul>
25+
* <li>SayHello</li>
26+
* </ul>
27+
*/
28+
public class GreeterService {
29+
30+
/**
31+
* SayHello protobuf RPC server service method.
32+
*/
2533
public static final ServiceMethod<examples.HelloRequest, examples.HelloReply> SayHello = ServiceMethod.server(
2634
ServiceName.create("helloworld", "Greeter"),
2735
"SayHello",
2836
GrpcMessageEncoder.encoder(),
2937
GrpcMessageDecoder.decoder(examples.HelloRequest.parser()));
3038

31-
public static final java.util.List<ServiceMethod<?, ?>> all() {
39+
/**
40+
* @return a mutable list of the known protobuf RPC server service methods.
41+
*/
42+
public static java.util.List<ServiceMethod<?, ?>> all() {
3243
java.util.List<ServiceMethod<?, ?>> all = new java.util.ArrayList<>();
3344
all.add(SayHello);
3445
return all;
3546
}
3647

48+
/**
49+
* Json server service methods.
50+
*/
3751
public static final class Json {
3852

53+
/**
54+
* SayHello json RPC server service method.
55+
*/
3956
public static final ServiceMethod<examples.HelloRequest, examples.HelloReply> SayHello = ServiceMethod.server(
4057
ServiceName.create("helloworld", "Greeter"),
4158
"SayHello",
4259
GrpcMessageEncoder.json(),
4360
GrpcMessageDecoder.json(() -> examples.HelloRequest.newBuilder()));
4461

45-
public static final java.util.List<ServiceMethod<?, ?>> all() {
62+
/**
63+
* @return a mutable list of the known json RPC server service methods.
64+
*/
65+
public static java.util.List<ServiceMethod<?, ?>> all() {
4666
java.util.List<ServiceMethod<?, ?>> all = new java.util.ArrayList<>();
4767
all.add(SayHello);
4868
return all;
4969
}
5070
}
5171

72+
/**
73+
* Transcoded server service methods.
74+
*/
5275
public static final class Transcoding {
5376

5477
private static final io.vertx.grpc.transcoding.MethodTranscodingOptions SayHello_OPTIONS = new io.vertx.grpc.transcoding.MethodTranscodingOptions()
@@ -59,41 +82,59 @@ public static final class Transcoding {
5982
.setResponseBody("")
6083
;
6184

62-
public static final io.vertx.grpc.transcoding.TranscodingServiceMethod<examples.HelloRequest, examples.HelloReply> SayHello = io.vertx.grpc.transcoding.TranscodingServiceMethod.server(
63-
ServiceName.create("helloworld", "Greeter"),
64-
"SayHello",
65-
GrpcMessageEncoder.json(),
66-
GrpcMessageDecoder.json(() -> examples.HelloRequest.newBuilder()),
67-
SayHello_OPTIONS);
85+
/**
86+
* SayHello transcoded RPC server service method.
87+
*/
88+
public static final io.vertx.grpc.transcoding.TranscodingServiceMethod<examples.HelloRequest, examples.HelloReply> SayHello = io.vertx.grpc.transcoding.TranscodingServiceMethod.server(
89+
ServiceName.create("helloworld", "Greeter"),
90+
"SayHello",
91+
GrpcMessageEncoder.json(),
92+
GrpcMessageDecoder.json(() -> examples.HelloRequest.newBuilder()),
93+
SayHello_OPTIONS);
6894

69-
public static final java.util.List<ServiceMethod<?, ?>> all() {
95+
/**
96+
* @return a mutable list of the known transcoded RPC server service methods.
97+
*/
98+
public static java.util.List<ServiceMethod<?, ?>> all() {
7099
java.util.List<ServiceMethod<?, ?>> all = new java.util.ArrayList<>();
71100
all.add(SayHello);
72101
return all;
73102
}
74103
}
75104

76-
public Future<examples.HelloReply> sayHello(examples.HelloRequest request) {
77-
throw new UnsupportedOperationException("Not implemented");
78-
}
79-
public void sayHello(examples.HelloRequest request, Promise<examples.HelloReply> response) {
80-
sayHello(request)
81-
.onSuccess(msg -> response.complete(msg))
82-
.onFailure(error -> response.fail(error));
83-
}
84105

106+
/**
107+
* Override this method to implement the SayHello RPC.
108+
*/
109+
protected Future<examples.HelloReply> sayHello(examples.HelloRequest request) {
110+
throw new UnsupportedOperationException("Not implemented");
111+
}
112+
113+
protected void sayHello(examples.HelloRequest request, Promise<examples.HelloReply> response) {
114+
sayHello(request)
115+
.onSuccess(msg -> response.complete(msg))
116+
.onFailure(error -> response.fail(error));
117+
}
118+
119+
/**
120+
* Service method to RPC method binder.
121+
*/
85122
public class Binder {
123+
86124
private final List<ServiceMethod<?, ?>> serviceMethods;
125+
87126
private Binder(List<ServiceMethod<?, ?>> serviceMethods) {
88127
this.serviceMethods = serviceMethods;
89128
}
129+
90130
private void validate() {
91131
for (ServiceMethod<?, ?> serviceMethod : serviceMethods) {
92132
if (resolveHandler(serviceMethod) == null) {
93133
throw new IllegalArgumentException("Invalid service method:" + serviceMethod);
94134
}
95135
}
96136
}
137+
97138
private <Req, Resp> Handler<io.vertx.grpc.server.GrpcServerRequest<Req, Resp>> resolveHandler(ServiceMethod<Req, Resp> serviceMethod) {
98139
if (SayHello == serviceMethod || Json.SayHello == serviceMethod) {
99140
Handler<io.vertx.grpc.server.GrpcServerRequest<examples.HelloRequest, examples.HelloReply>> handler = GreeterService.this::handle_sayHello;
@@ -102,25 +143,36 @@ private <Req, Resp> Handler<io.vertx.grpc.server.GrpcServerRequest<Req, Resp>> r
102143
}
103144
return null;
104145
}
146+
105147
private <Req, Resp> void bindHandler(GrpcServer server, ServiceMethod<Req, Resp> serviceMethod) {
106148
Handler<io.vertx.grpc.server.GrpcServerRequest<Req, Resp>> handler = resolveHandler(serviceMethod);
107149
server.callHandler(serviceMethod, handler);
108150
}
151+
152+
/**
153+
* Bind the contained service methods to the {@code server}.
154+
*/
109155
public void to(GrpcServer server) {
110156
for (ServiceMethod<?, ?> serviceMethod : serviceMethods) {
111157
bindHandler(server, serviceMethod);
112158
}
113159
}
114160
}
115161

116-
public Binder bind(List<ServiceMethod<?, ?>> serviceMethods) {
117-
Binder binder = new Binder(serviceMethods);
162+
/**
163+
* @return a binder for the list of {@code methods}
164+
*/
165+
public Binder bind(List<ServiceMethod<?, ?>> methods) {
166+
Binder binder = new Binder(methods);
118167
binder.validate();
119168
return binder;
120169
}
121170

122-
public Binder bind(ServiceMethod<?, ?>... serviceMethods) {
123-
return bind(java.util.Arrays.asList(serviceMethods));
171+
/**
172+
* @return a binder for the {@code methods}
173+
*/
174+
public Binder bind(ServiceMethod<?, ?>... methods) {
175+
return bind(java.util.Arrays.asList(methods));
124176
}
125177

126178
private void handle_sayHello(io.vertx.grpc.server.GrpcServerRequest<examples.HelloRequest, examples.HelloReply> request) {

0 commit comments

Comments
 (0)