Updating examples to be consistent with proto3 styleguide.

This commit is contained in:
nmittler 2015-02-27 09:17:31 -08:00
parent 4afd98486c
commit 81cc0daea7
9 changed files with 36 additions and 51 deletions

View File

@ -24,25 +24,25 @@ protobufCodeGenPlugins = ["java_plugin:$rootDir/compiler/build/binaries/java_plu
generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
task routeGuideServer(type: JavaExec) {
main = "io.grpc.examples.RouteGuideServer"
main = "io.grpc.examples.routeguide.RouteGuideServer"
description = "Executes the route guide server."
classpath = sourceSets.main.runtimeClasspath
}
task routeGuideClient(type: JavaExec) {
main = "io.grpc.examples.RouteGuideClient"
main = "io.grpc.examples.routeguide.RouteGuideClient"
description = "Executes the route guide client."
classpath = sourceSets.main.runtimeClasspath
}
task helloWorldServer(type: JavaExec) {
main = "io.grpc.examples.HelloWorldServer"
main = "io.grpc.examples.helloworld.HelloWorldServer"
description = "Executes the hello world server."
classpath = sourceSets.main.runtimeClasspath
}
task helloWorldClient(type: JavaExec) {
main = "io.grpc.examples.HelloWorldClient"
main = "io.grpc.examples.helloworld.HelloWorldClient"
description = "Executes the hello world client."
classpath = sourceSets.main.runtimeClasspath
}

View File

@ -1,8 +1,6 @@
package io.grpc.examples;
package io.grpc.examples.helloworld;
import io.grpc.ChannelImpl;
import io.grpc.examples.Helloworld.HelloReply;
import io.grpc.examples.Helloworld.HelloRequest;
import io.grpc.transport.netty.NegotiationType;
import io.grpc.transport.netty.NettyChannelBuilder;
@ -33,9 +31,9 @@ public class HelloWorldClient {
public void greet(String name) {
try {
logger.info("Will try to greet " + name + " ...");
HelloRequest req = HelloRequest.newBuilder().setName(name).build();
HelloReply reply = blockingStub.sayHello(req);
logger.info("Greeting: " + reply.getMessage());
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloResponse response = blockingStub.sayHello(request);
logger.info("Greeting: " + response.getMessage());
} catch (RuntimeException e) {
logger.log(Level.WARNING, "RPC failed", e);
return;

View File

@ -1,8 +1,6 @@
package io.grpc.examples;
package io.grpc.examples.helloworld;
import io.grpc.ServerImpl;
import io.grpc.examples.Helloworld.HelloReply;
import io.grpc.examples.Helloworld.HelloRequest;
import io.grpc.stub.StreamObserver;
import io.grpc.transport.netty.NettyServerBuilder;
@ -51,8 +49,8 @@ public class HelloWorldServer {
private class GreeterImpl implements GreeterGrpc.Greeter {
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
public void sayHello(HelloRequest req, StreamObserver<HelloResponse> responseObserver) {
HelloResponse reply = HelloResponse.newBuilder().setMessage("Hello " + req.getName()).build();
responseObserver.onValue(reply);
responseObserver.onCompleted();
}

View File

@ -29,18 +29,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.grpc.examples;
package io.grpc.examples.routeguide;
import com.google.common.util.concurrent.SettableFuture;
import io.grpc.ChannelImpl;
import io.grpc.examples.RouteGuideGrpc.RouteGuideBlockingStub;
import io.grpc.examples.RouteGuideGrpc.RouteGuideStub;
import io.grpc.examples.RouteGuideOuterClass.Feature;
import io.grpc.examples.RouteGuideOuterClass.Point;
import io.grpc.examples.RouteGuideOuterClass.Rectangle;
import io.grpc.examples.RouteGuideOuterClass.RouteNote;
import io.grpc.examples.RouteGuideOuterClass.RouteSummary;
import io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideBlockingStub;
import io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideStub;
import io.grpc.stub.StreamObserver;
import io.grpc.transport.netty.NegotiationType;
import io.grpc.transport.netty.NettyChannelBuilder;

View File

@ -29,7 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.grpc.examples;
package io.grpc.examples.routeguide;
import static java.lang.Math.atan2;
import static java.lang.Math.cos;
@ -41,11 +41,6 @@ import static java.lang.Math.toRadians;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import io.grpc.ServerImpl;
import io.grpc.examples.RouteGuideOuterClass.Feature;
import io.grpc.examples.RouteGuideOuterClass.Point;
import io.grpc.examples.RouteGuideOuterClass.Rectangle;
import io.grpc.examples.RouteGuideOuterClass.RouteNote;
import io.grpc.examples.RouteGuideOuterClass.RouteSummary;
import io.grpc.stub.StreamObserver;
import io.grpc.transport.netty.NettyServerBuilder;

View File

@ -29,10 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.grpc.examples;
import io.grpc.examples.RouteGuideOuterClass.Feature;
import io.grpc.examples.RouteGuideOuterClass.Point;
package io.grpc.examples.routeguide;
import java.io.IOException;
import java.io.InputStream;

View File

@ -29,14 +29,15 @@
syntax = "proto3";
option java_package = "io.grpc.examples";
package grpc.example.helloworld;
package helloworld;
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
rpc SayHello (HelloRequest) returns (HelloResponse) {}
}
// The request message containing the user's name.
@ -45,6 +46,6 @@ message HelloRequest {
}
// The response message containing the greetings
message HelloReply {
message HelloResponse {
string message = 1;
}

View File

@ -29,9 +29,10 @@
syntax = "proto3";
option java_package = "io.grpc.examples";
package grpc.example.routeguide;
package examples;
option java_multiple_files = true;
option java_package = "io.grpc.examples.routeguide";
// Interface exported by the server.
service RouteGuide {
@ -66,18 +67,18 @@ service RouteGuide {
// Latitudes should be in the range +/- 90 degrees and longitude should be in
// the range +/- 180 degrees (inclusive).
message Point {
optional int32 latitude = 1;
optional int32 longitude = 2;
int32 latitude = 1;
int32 longitude = 2;
}
// A latitude-longitude rectangle, represented as two diagonally opposite
// points "lo" and "hi".
message Rectangle {
// One corner of the rectangle.
optional Point lo = 1;
Point lo = 1;
// The other corner of the rectangle.
optional Point hi = 2;
Point hi = 2;
}
// A feature names something at a given point.
@ -85,19 +86,19 @@ message Rectangle {
// If a feature could not be named, the name is empty.
message Feature {
// The name of the feature.
optional string name = 1;
string name = 1;
// The point where the feature is detected.
optional Point location = 2;
Point location = 2;
}
// A RouteNote is a message sent while at a given point.
message RouteNote {
// The location from which the message is sent.
optional Point location = 1;
Point location = 1;
// The message to be sent.
optional string message = 2;
string message = 2;
}
// A RouteSummary is received in response to a RecordRoute rpc.
@ -107,14 +108,14 @@ message RouteNote {
// the distance between each point.
message RouteSummary {
// The number of points received.
optional int32 point_count = 1;
int32 point_count = 1;
// The number of known features passed while traversing the route.
optional int32 feature_count = 2;
int32 feature_count = 2;
// The distance covered in metres.
optional int32 distance = 3;
int32 distance = 3;
// The duration of the traversal in seconds.
optional int32 elapsed_time = 4;
int32 elapsed_time = 4;
}