mirror of https://github.com/grpc/grpc-java.git
Merge pull request #149 from nmittler/examples_style
Updating examples to be consistent with proto3 styleguide.
This commit is contained in:
commit
bb71e21613
|
|
@ -24,25 +24,25 @@ protobufCodeGenPlugins = ["java_plugin:$rootDir/compiler/build/binaries/java_plu
|
||||||
generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
|
generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
|
||||||
|
|
||||||
task routeGuideServer(type: JavaExec) {
|
task routeGuideServer(type: JavaExec) {
|
||||||
main = "io.grpc.examples.RouteGuideServer"
|
main = "io.grpc.examples.routeguide.RouteGuideServer"
|
||||||
description = "Executes the route guide server."
|
description = "Executes the route guide server."
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
task routeGuideClient(type: JavaExec) {
|
task routeGuideClient(type: JavaExec) {
|
||||||
main = "io.grpc.examples.RouteGuideClient"
|
main = "io.grpc.examples.routeguide.RouteGuideClient"
|
||||||
description = "Executes the route guide client."
|
description = "Executes the route guide client."
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
task helloWorldServer(type: JavaExec) {
|
task helloWorldServer(type: JavaExec) {
|
||||||
main = "io.grpc.examples.HelloWorldServer"
|
main = "io.grpc.examples.helloworld.HelloWorldServer"
|
||||||
description = "Executes the hello world server."
|
description = "Executes the hello world server."
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
task helloWorldClient(type: JavaExec) {
|
task helloWorldClient(type: JavaExec) {
|
||||||
main = "io.grpc.examples.HelloWorldClient"
|
main = "io.grpc.examples.helloworld.HelloWorldClient"
|
||||||
description = "Executes the hello world client."
|
description = "Executes the hello world client."
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package io.grpc.examples;
|
package io.grpc.examples.helloworld;
|
||||||
|
|
||||||
import io.grpc.ChannelImpl;
|
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.NegotiationType;
|
||||||
import io.grpc.transport.netty.NettyChannelBuilder;
|
import io.grpc.transport.netty.NettyChannelBuilder;
|
||||||
|
|
||||||
|
|
@ -33,9 +31,9 @@ public class HelloWorldClient {
|
||||||
public void greet(String name) {
|
public void greet(String name) {
|
||||||
try {
|
try {
|
||||||
logger.info("Will try to greet " + name + " ...");
|
logger.info("Will try to greet " + name + " ...");
|
||||||
HelloRequest req = HelloRequest.newBuilder().setName(name).build();
|
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
|
||||||
HelloReply reply = blockingStub.sayHello(req);
|
HelloResponse response = blockingStub.sayHello(request);
|
||||||
logger.info("Greeting: " + reply.getMessage());
|
logger.info("Greeting: " + response.getMessage());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.log(Level.WARNING, "RPC failed", e);
|
logger.log(Level.WARNING, "RPC failed", e);
|
||||||
return;
|
return;
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package io.grpc.examples;
|
package io.grpc.examples.helloworld;
|
||||||
|
|
||||||
import io.grpc.ServerImpl;
|
import io.grpc.ServerImpl;
|
||||||
import io.grpc.examples.Helloworld.HelloReply;
|
|
||||||
import io.grpc.examples.Helloworld.HelloRequest;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
import io.grpc.stub.StreamObserver;
|
||||||
import io.grpc.transport.netty.NettyServerBuilder;
|
import io.grpc.transport.netty.NettyServerBuilder;
|
||||||
|
|
||||||
|
|
@ -51,8 +49,8 @@ public class HelloWorldServer {
|
||||||
private class GreeterImpl implements GreeterGrpc.Greeter {
|
private class GreeterImpl implements GreeterGrpc.Greeter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
|
public void sayHello(HelloRequest req, StreamObserver<HelloResponse> responseObserver) {
|
||||||
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
|
HelloResponse reply = HelloResponse.newBuilder().setMessage("Hello " + req.getName()).build();
|
||||||
responseObserver.onValue(reply);
|
responseObserver.onValue(reply);
|
||||||
responseObserver.onCompleted();
|
responseObserver.onCompleted();
|
||||||
}
|
}
|
||||||
|
|
@ -29,18 +29,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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 com.google.common.util.concurrent.SettableFuture;
|
||||||
|
|
||||||
import io.grpc.ChannelImpl;
|
import io.grpc.ChannelImpl;
|
||||||
import io.grpc.examples.RouteGuideGrpc.RouteGuideBlockingStub;
|
import io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideBlockingStub;
|
||||||
import io.grpc.examples.RouteGuideGrpc.RouteGuideStub;
|
import io.grpc.examples.routeguide.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.stub.StreamObserver;
|
import io.grpc.stub.StreamObserver;
|
||||||
import io.grpc.transport.netty.NegotiationType;
|
import io.grpc.transport.netty.NegotiationType;
|
||||||
import io.grpc.transport.netty.NettyChannelBuilder;
|
import io.grpc.transport.netty.NettyChannelBuilder;
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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.atan2;
|
||||||
import static java.lang.Math.cos;
|
import static java.lang.Math.cos;
|
||||||
|
|
@ -41,11 +41,6 @@ import static java.lang.Math.toRadians;
|
||||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||||
|
|
||||||
import io.grpc.ServerImpl;
|
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.stub.StreamObserver;
|
||||||
import io.grpc.transport.netty.NettyServerBuilder;
|
import io.grpc.transport.netty.NettyServerBuilder;
|
||||||
|
|
||||||
|
|
@ -29,10 +29,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.examples;
|
package io.grpc.examples.routeguide;
|
||||||
|
|
||||||
import io.grpc.examples.RouteGuideOuterClass.Feature;
|
|
||||||
import io.grpc.examples.RouteGuideOuterClass.Point;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -29,14 +29,15 @@
|
||||||
|
|
||||||
syntax = "proto3";
|
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.
|
// The greeting service definition.
|
||||||
service Greeter {
|
service Greeter {
|
||||||
// Sends a greeting
|
// Sends a greeting
|
||||||
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
rpc SayHello (HelloRequest) returns (HelloResponse) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The request message containing the user's name.
|
// The request message containing the user's name.
|
||||||
|
|
@ -45,6 +46,6 @@ message HelloRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The response message containing the greetings
|
// The response message containing the greetings
|
||||||
message HelloReply {
|
message HelloResponse {
|
||||||
string message = 1;
|
string message = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -29,9 +29,10 @@
|
||||||
|
|
||||||
syntax = "proto3";
|
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.
|
// Interface exported by the server.
|
||||||
service RouteGuide {
|
service RouteGuide {
|
||||||
|
|
@ -66,18 +67,18 @@ service RouteGuide {
|
||||||
// Latitudes should be in the range +/- 90 degrees and longitude should be in
|
// Latitudes should be in the range +/- 90 degrees and longitude should be in
|
||||||
// the range +/- 180 degrees (inclusive).
|
// the range +/- 180 degrees (inclusive).
|
||||||
message Point {
|
message Point {
|
||||||
optional int32 latitude = 1;
|
int32 latitude = 1;
|
||||||
optional int32 longitude = 2;
|
int32 longitude = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A latitude-longitude rectangle, represented as two diagonally opposite
|
// A latitude-longitude rectangle, represented as two diagonally opposite
|
||||||
// points "lo" and "hi".
|
// points "lo" and "hi".
|
||||||
message Rectangle {
|
message Rectangle {
|
||||||
// One corner of the rectangle.
|
// One corner of the rectangle.
|
||||||
optional Point lo = 1;
|
Point lo = 1;
|
||||||
|
|
||||||
// The other corner of the rectangle.
|
// The other corner of the rectangle.
|
||||||
optional Point hi = 2;
|
Point hi = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A feature names something at a given point.
|
// 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.
|
// If a feature could not be named, the name is empty.
|
||||||
message Feature {
|
message Feature {
|
||||||
// The name of the feature.
|
// The name of the feature.
|
||||||
optional string name = 1;
|
string name = 1;
|
||||||
|
|
||||||
// The point where the feature is detected.
|
// 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.
|
// A RouteNote is a message sent while at a given point.
|
||||||
message RouteNote {
|
message RouteNote {
|
||||||
// The location from which the message is sent.
|
// The location from which the message is sent.
|
||||||
optional Point location = 1;
|
Point location = 1;
|
||||||
|
|
||||||
// The message to be sent.
|
// The message to be sent.
|
||||||
optional string message = 2;
|
string message = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A RouteSummary is received in response to a RecordRoute rpc.
|
// A RouteSummary is received in response to a RecordRoute rpc.
|
||||||
|
|
@ -107,14 +108,14 @@ message RouteNote {
|
||||||
// the distance between each point.
|
// the distance between each point.
|
||||||
message RouteSummary {
|
message RouteSummary {
|
||||||
// The number of points received.
|
// The number of points received.
|
||||||
optional int32 point_count = 1;
|
int32 point_count = 1;
|
||||||
|
|
||||||
// The number of known features passed while traversing the route.
|
// The number of known features passed while traversing the route.
|
||||||
optional int32 feature_count = 2;
|
int32 feature_count = 2;
|
||||||
|
|
||||||
// The distance covered in metres.
|
// The distance covered in metres.
|
||||||
optional int32 distance = 3;
|
int32 distance = 3;
|
||||||
|
|
||||||
// The duration of the traversal in seconds.
|
// The duration of the traversal in seconds.
|
||||||
optional int32 elapsed_time = 4;
|
int32 elapsed_time = 4;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue