Skip to content

Commit 81cc0da

Browse files
author
nmittler
committed
Updating examples to be consistent with proto3 styleguide.
1 parent 4afd984 commit 81cc0da

File tree

9 files changed

+36
-51
lines changed

9 files changed

+36
-51
lines changed

examples/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ protobufCodeGenPlugins = ["java_plugin:$rootDir/compiler/build/binaries/java_plu
2424
generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
2525

2626
task routeGuideServer(type: JavaExec) {
27-
main = "io.grpc.examples.RouteGuideServer"
27+
main = "io.grpc.examples.routeguide.RouteGuideServer"
2828
description = "Executes the route guide server."
2929
classpath = sourceSets.main.runtimeClasspath
3030
}
3131

3232
task routeGuideClient(type: JavaExec) {
33-
main = "io.grpc.examples.RouteGuideClient"
33+
main = "io.grpc.examples.routeguide.RouteGuideClient"
3434
description = "Executes the route guide client."
3535
classpath = sourceSets.main.runtimeClasspath
3636
}
3737

3838
task helloWorldServer(type: JavaExec) {
39-
main = "io.grpc.examples.HelloWorldServer"
39+
main = "io.grpc.examples.helloworld.HelloWorldServer"
4040
description = "Executes the hello world server."
4141
classpath = sourceSets.main.runtimeClasspath
4242
}
4343

4444
task helloWorldClient(type: JavaExec) {
45-
main = "io.grpc.examples.HelloWorldClient"
45+
main = "io.grpc.examples.helloworld.HelloWorldClient"
4646
description = "Executes the hello world client."
4747
classpath = sourceSets.main.runtimeClasspath
4848
}

examples/src/main/java/io/grpc/examples/HelloWorldClient.java renamed to examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package io.grpc.examples;
1+
package io.grpc.examples.helloworld;
22

33
import io.grpc.ChannelImpl;
4-
import io.grpc.examples.Helloworld.HelloReply;
5-
import io.grpc.examples.Helloworld.HelloRequest;
64
import io.grpc.transport.netty.NegotiationType;
75
import io.grpc.transport.netty.NettyChannelBuilder;
86

@@ -33,9 +31,9 @@ public void shutdown() throws InterruptedException {
3331
public void greet(String name) {
3432
try {
3533
logger.info("Will try to greet " + name + " ...");
36-
HelloRequest req = HelloRequest.newBuilder().setName(name).build();
37-
HelloReply reply = blockingStub.sayHello(req);
38-
logger.info("Greeting: " + reply.getMessage());
34+
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
35+
HelloResponse response = blockingStub.sayHello(request);
36+
logger.info("Greeting: " + response.getMessage());
3937
} catch (RuntimeException e) {
4038
logger.log(Level.WARNING, "RPC failed", e);
4139
return;

examples/src/main/java/io/grpc/examples/HelloWorldServer.java renamed to examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package io.grpc.examples;
1+
package io.grpc.examples.helloworld;
22

33
import io.grpc.ServerImpl;
4-
import io.grpc.examples.Helloworld.HelloReply;
5-
import io.grpc.examples.Helloworld.HelloRequest;
64
import io.grpc.stub.StreamObserver;
75
import io.grpc.transport.netty.NettyServerBuilder;
86

@@ -51,8 +49,8 @@ public static void main(String[] args) throws Exception {
5149
private class GreeterImpl implements GreeterGrpc.Greeter {
5250

5351
@Override
54-
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
55-
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
52+
public void sayHello(HelloRequest req, StreamObserver<HelloResponse> responseObserver) {
53+
HelloResponse reply = HelloResponse.newBuilder().setMessage("Hello " + req.getName()).build();
5654
responseObserver.onValue(reply);
5755
responseObserver.onCompleted();
5856
}

examples/src/main/java/io/grpc/examples/RouteGuideClient.java renamed to examples/src/main/java/io/grpc/examples/routeguide/RouteGuideClient.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@
2929
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32-
package io.grpc.examples;
32+
package io.grpc.examples.routeguide;
3333

3434
import com.google.common.util.concurrent.SettableFuture;
3535

3636
import io.grpc.ChannelImpl;
37-
import io.grpc.examples.RouteGuideGrpc.RouteGuideBlockingStub;
38-
import io.grpc.examples.RouteGuideGrpc.RouteGuideStub;
39-
import io.grpc.examples.RouteGuideOuterClass.Feature;
40-
import io.grpc.examples.RouteGuideOuterClass.Point;
41-
import io.grpc.examples.RouteGuideOuterClass.Rectangle;
42-
import io.grpc.examples.RouteGuideOuterClass.RouteNote;
43-
import io.grpc.examples.RouteGuideOuterClass.RouteSummary;
37+
import io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideBlockingStub;
38+
import io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideStub;
4439
import io.grpc.stub.StreamObserver;
4540
import io.grpc.transport.netty.NegotiationType;
4641
import io.grpc.transport.netty.NettyChannelBuilder;

examples/src/main/java/io/grpc/examples/RouteGuideServer.java renamed to examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32-
package io.grpc.examples;
32+
package io.grpc.examples.routeguide;
3333

3434
import static java.lang.Math.atan2;
3535
import static java.lang.Math.cos;
@@ -41,11 +41,6 @@
4141
import static java.util.concurrent.TimeUnit.NANOSECONDS;
4242

4343
import io.grpc.ServerImpl;
44-
import io.grpc.examples.RouteGuideOuterClass.Feature;
45-
import io.grpc.examples.RouteGuideOuterClass.Point;
46-
import io.grpc.examples.RouteGuideOuterClass.Rectangle;
47-
import io.grpc.examples.RouteGuideOuterClass.RouteNote;
48-
import io.grpc.examples.RouteGuideOuterClass.RouteSummary;
4944
import io.grpc.stub.StreamObserver;
5045
import io.grpc.transport.netty.NettyServerBuilder;
5146

examples/src/main/java/io/grpc/examples/RouteGuideUtil.java renamed to examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32-
package io.grpc.examples;
33-
34-
import io.grpc.examples.RouteGuideOuterClass.Feature;
35-
import io.grpc.examples.RouteGuideOuterClass.Point;
32+
package io.grpc.examples.routeguide;
3633

3734
import java.io.IOException;
3835
import java.io.InputStream;
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929

3030
syntax = "proto3";
3131

32-
option java_package = "io.grpc.examples";
32+
package grpc.example.helloworld;
3333

34-
package helloworld;
34+
option java_multiple_files = true;
35+
option java_package = "io.grpc.examples.helloworld";
3536

3637
// The greeting service definition.
3738
service Greeter {
3839
// Sends a greeting
39-
rpc SayHello (HelloRequest) returns (HelloReply) {}
40+
rpc SayHello (HelloRequest) returns (HelloResponse) {}
4041
}
4142

4243
// The request message containing the user's name.
@@ -45,6 +46,6 @@ message HelloRequest {
4546
}
4647

4748
// The response message containing the greetings
48-
message HelloReply {
49+
message HelloResponse {
4950
string message = 1;
5051
}

examples/src/main/proto/route_guide.proto

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929

3030
syntax = "proto3";
3131

32-
option java_package = "io.grpc.examples";
32+
package grpc.example.routeguide;
3333

34-
package examples;
34+
option java_multiple_files = true;
35+
option java_package = "io.grpc.examples.routeguide";
3536

3637
// Interface exported by the server.
3738
service RouteGuide {
@@ -66,38 +67,38 @@ service RouteGuide {
6667
// Latitudes should be in the range +/- 90 degrees and longitude should be in
6768
// the range +/- 180 degrees (inclusive).
6869
message Point {
69-
optional int32 latitude = 1;
70-
optional int32 longitude = 2;
70+
int32 latitude = 1;
71+
int32 longitude = 2;
7172
}
7273

7374
// A latitude-longitude rectangle, represented as two diagonally opposite
7475
// points "lo" and "hi".
7576
message Rectangle {
7677
// One corner of the rectangle.
77-
optional Point lo = 1;
78+
Point lo = 1;
7879

7980
// The other corner of the rectangle.
80-
optional Point hi = 2;
81+
Point hi = 2;
8182
}
8283

8384
// A feature names something at a given point.
8485
//
8586
// If a feature could not be named, the name is empty.
8687
message Feature {
8788
// The name of the feature.
88-
optional string name = 1;
89+
string name = 1;
8990

9091
// The point where the feature is detected.
91-
optional Point location = 2;
92+
Point location = 2;
9293
}
9394

9495
// A RouteNote is a message sent while at a given point.
9596
message RouteNote {
9697
// The location from which the message is sent.
97-
optional Point location = 1;
98+
Point location = 1;
9899

99100
// The message to be sent.
100-
optional string message = 2;
101+
string message = 2;
101102
}
102103

103104
// A RouteSummary is received in response to a RecordRoute rpc.
@@ -107,14 +108,14 @@ message RouteNote {
107108
// the distance between each point.
108109
message RouteSummary {
109110
// The number of points received.
110-
optional int32 point_count = 1;
111+
int32 point_count = 1;
111112

112113
// The number of known features passed while traversing the route.
113-
optional int32 feature_count = 2;
114+
int32 feature_count = 2;
114115

115116
// The distance covered in metres.
116-
optional int32 distance = 3;
117+
int32 distance = 3;
117118

118119
// The duration of the traversal in seconds.
119-
optional int32 elapsed_time = 4;
120+
int32 elapsed_time = 4;
120121
}

examples/src/main/resources/io/grpc/examples/route_guide_db.json renamed to examples/src/main/resources/io/grpc/examples/routeguide/route_guide_db.json

File renamed without changes.

0 commit comments

Comments
 (0)