Skip to content

Commit

Permalink
Revert breaking change with v4 generated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jul 25, 2024
1 parent 791a243 commit 41ac770
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 360 deletions.
59 changes: 0 additions & 59 deletions vertx-grpc-docs/src/main/java/examples/GreeterGrpcServer.java

This file was deleted.

10 changes: 5 additions & 5 deletions vertx-grpc-docs/src/main/java/examples/GrpcClientExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void createClient(Vertx vertx) {
public void sendRequest(GrpcClient client) {

SocketAddress server = SocketAddress.inetSocketAddress(443, "example.com");
ServiceMethod<HelloReply, HelloRequest> sayHelloMethod = GreeterGrpcClient.SayHello;
ServiceMethod<HelloReply, HelloRequest> sayHelloMethod = VertxGreeterGrpcClient.SayHello;
Future<GrpcClientRequest<HelloRequest, HelloReply>> fut = client.request(server, sayHelloMethod);
fut.onSuccess(request -> {
// The end method calls the service
Expand All @@ -42,7 +42,7 @@ public void receiveResponse(GrpcClientRequest<HelloRequest, HelloReply> request)

public void requestResponse(GrpcClient client, SocketAddress server) {
client
.request(server, GreeterGrpcClient.SayHello).compose(request -> {
.request(server, VertxGreeterGrpcClient.SayHello).compose(request -> {
request.end(HelloRequest
.newBuilder()
.setName("Bob")
Expand All @@ -55,7 +55,7 @@ public void requestResponse(GrpcClient client, SocketAddress server) {

public void streamingRequest(GrpcClient client, SocketAddress server) {
client
.request(server, StreamingGrpcClient.Sink)
.request(server, VertxStreamingGrpcClient.Sink)
.onSuccess(request -> {
for (int i = 0;i < 10;i++) {
request.write(Item.newBuilder().setValue("1").build());
Expand All @@ -66,7 +66,7 @@ public void streamingRequest(GrpcClient client, SocketAddress server) {

public void streamingResponse(GrpcClient client, SocketAddress server) {
client
.request(server, StreamingGrpcClient.Source)
.request(server, VertxStreamingGrpcClient.Source)
.compose(request -> {
request.end(Empty.getDefaultInstance());
return request.response();
Expand Down Expand Up @@ -133,7 +133,7 @@ public void requestWithDeadline(Vertx vertx) {

public void requestWithDeadline2(GrpcClient client, SocketAddress server, MethodDescriptor<HelloRequest, HelloReply> sayHelloMethod) {

Future<GrpcClientRequest<HelloRequest, HelloReply>> fut = client.request(server, GreeterGrpcClient.SayHello);
Future<GrpcClientRequest<HelloRequest, HelloReply>> fut = client.request(server, VertxGreeterGrpcClient.SayHello);
fut.onSuccess(request -> {

request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void createServer(Vertx vertx, HttpServerOptions options) {

public void requestResponse(GrpcServer server) {

ServiceMethod<HelloRequest, HelloReply> serviceMethod = GreeterGrpcServer.SayHello;
ServiceMethod<HelloRequest, HelloReply> serviceMethod = VertxGreeterGrpcServer.SayHello;

server.callHandler(serviceMethod, request -> {

Expand All @@ -45,7 +45,7 @@ public void requestResponse(GrpcServer server) {

public void streamingRequest(GrpcServer server) {

server.callHandler(StreamingGrpcServer.Sink, request -> {
server.callHandler(VertxStreamingGrpcServer.Sink, request -> {
request.handler(item -> {
// Process item
});
Expand All @@ -62,7 +62,7 @@ public void streamingRequest(GrpcServer server) {

public void streamingResponse(GrpcServer server) {

server.callHandler(StreamingGrpcServer.Source, request -> {
server.callHandler(VertxStreamingGrpcServer.Source, request -> {
GrpcServerResponse<Empty, Item> response = request.response();
request.handler(empty -> {
for (int i = 0;i < 10;i++) {
Expand All @@ -75,7 +75,7 @@ public void streamingResponse(GrpcServer server) {

public void bidi(GrpcServer server) {

server.callHandler(StreamingGrpcServer.Pipe, request -> {
server.callHandler(VertxStreamingGrpcServer.Pipe, request -> {

request.handler(item -> request.response().write(item));
request.endHandler(v -> request.response().end());
Expand Down
111 changes: 0 additions & 111 deletions vertx-grpc-docs/src/main/java/examples/StreamingGrpcServer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
import io.vertx.grpc.common.GrpcMessageDecoder;
import io.vertx.grpc.common.GrpcMessageEncoder;

public class GreeterGrpcClient {
public class VertxGreeterGrpcClient {

public static final ServiceMethod<examples.HelloReply, examples.HelloRequest> SayHello = ServiceMethod.client(
ServiceName.create("helloworld", "Greeter"),
"SayHello",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.HelloReply.parser())
);
ServiceName.create("helloworld", "Greeter"),
"SayHello",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.HelloReply.parser()));

private final GrpcClient client;
private final SocketAddress socketAddress;

public GreeterGrpcClient(GrpcClient client, SocketAddress socketAddress) {
public VertxGreeterGrpcClient(GrpcClient client, SocketAddress socketAddress) {
this.client = client;
this.socketAddress = socketAddress;
}
Expand Down
61 changes: 61 additions & 0 deletions vertx-grpc-docs/src/main/java/examples/VertxGreeterGrpcServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package examples;

import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.streams.ReadStream;
import io.vertx.core.streams.WriteStream;
import io.vertx.grpc.common.GrpcStatus;
import io.vertx.grpc.common.ServiceName;
import io.vertx.grpc.common.ServiceMethod;
import io.vertx.grpc.common.GrpcMessageDecoder;
import io.vertx.grpc.common.GrpcMessageEncoder;
import io.vertx.grpc.server.GrpcServerResponse;
import io.vertx.grpc.server.GrpcServer;

import java.util.ArrayList;
import java.util.List;

public class VertxGreeterGrpcServer {

public static final ServiceMethod<examples.HelloRequest, examples.HelloReply> SayHello = ServiceMethod.server(
ServiceName.create("helloworld", "Greeter"),
"SayHello",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.HelloRequest.parser()));

public interface GreeterApi {

default Future<examples.HelloReply> sayHello(examples.HelloRequest request) {
throw new UnsupportedOperationException("Not implemented");
}
default void sayHello(examples.HelloRequest request, Promise<examples.HelloReply> response) {
sayHello(request)
.onSuccess(msg -> response.complete(msg))
.onFailure(error -> response.fail(error));
}

default GreeterApi bind_sayHello(GrpcServer server) {
server.callHandler(SayHello, request -> {
Promise<examples.HelloReply> promise = Promise.promise();
request.handler(req -> {
try {
sayHello(req, promise);
} catch (RuntimeException err) {
promise.tryFail(err);
}
});
promise.future()
.onFailure(err -> request.response().status(GrpcStatus.INTERNAL).end())
.onSuccess(resp -> request.response().end(resp));
});
return this;
}

default GreeterApi bindAll(GrpcServer server) {
bind_sayHello(server);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,28 @@
import io.vertx.grpc.common.GrpcMessageDecoder;
import io.vertx.grpc.common.GrpcMessageEncoder;

public class StreamingGrpcClient {
public class VertxStreamingGrpcClient {

public static final ServiceMethod<examples.Item, examples.Empty> Source = ServiceMethod.client(
ServiceName.create("streaming", "Streaming"),
"Source",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Item.parser())
);
ServiceName.create("streaming", "Streaming"),
"Source",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Item.parser()));
public static final ServiceMethod<examples.Empty, examples.Item> Sink = ServiceMethod.client(
ServiceName.create("streaming", "Streaming"),
"Sink",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Empty.parser())
);
ServiceName.create("streaming", "Streaming"),
"Sink",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Empty.parser()));
public static final ServiceMethod<examples.Item, examples.Item> Pipe = ServiceMethod.client(
ServiceName.create("streaming", "Streaming"),
"Pipe",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Item.parser())
);
ServiceName.create("streaming", "Streaming"),
"Pipe",
GrpcMessageEncoder.encoder(),
GrpcMessageDecoder.decoder(examples.Item.parser()));

private final GrpcClient client;
private final SocketAddress socketAddress;

public StreamingGrpcClient(GrpcClient client, SocketAddress socketAddress) {
public VertxStreamingGrpcClient(GrpcClient client, SocketAddress socketAddress) {
this.client = client;
this.socketAddress = socketAddress;
}
Expand Down
Loading

0 comments on commit 41ac770

Please sign in to comment.