diff --git a/Step_1.md b/Step_1.md index c7aed326c38..1e9ca2b2a50 100644 --- a/Step_1.md +++ b/Step_1.md @@ -15,18 +15,17 @@ The gRPC Java Stub classes are created using a gRPC Java plugin, but first the plugin must be built and installed. To build the plugin: -``` +```sh $ pushd external/grpc_java $ make java_plugin $ popd ``` To use it to generate the code: -``` -$ mkdir -p src/main/java +```sh $ protoc -I . helloworld.proto --plugin=protoc-gen-grpc=external/grpc_java/bins/opt/java_plugin \ - --grpc_out=src/main/java \ - --java_out=src/main/java + --grpc_out=java/src/main/java \ + --java_out=java/src/main/java ``` Next, in [Step - 2](Step_2.md), we'll use the generated Stub implementation to diff --git a/Step_2.md b/Step_2.md index eafe70b6923..d2e1ae48b05 100644 --- a/Step_2.md +++ b/Step_2.md @@ -1,7 +1,7 @@ # Step-2: Write a service client. This step uses the generated code to write a simple client to access the hello -service. The full client is in [GreetingsClient.java](src/main/java/ex/grpc/GreetingsClient.java). +service. The full client is in [GreetingsClient.java](java/src/main/java/ex/grpc/GreetingsClient.java). ## Configuring the service to connect to. diff --git a/Step_3.md b/Step_3.md index 7b03cdf585f..9eb1009d2e6 100644 --- a/Step_3.md +++ b/Step_3.md @@ -3,17 +3,17 @@ This step extends the generated server skeleton code to write a simple server that provides the hello service. This introduces two new classes: -- a service implementation [GreetingsImpl.java](src/main/java/ex/grpc/GreetingsImpl.java). +- a service implementation [GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java). -- a server that hosts the service implementation and allows access over the network: [GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java). +- a server that hosts the service implementation and allows access over the network: [GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java). ## Service implementation -[GreetingsImpl.java](src/main/java/ex/grpc/GreetingsImpl.java) +[GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java) implements the behaviour we require of our GreetingService. There are a number of important features of gRPC being used here: -``` +```java public void hello(Helloworld.HelloRequest req, StreamObserver responseObserver) { Helloworld.HelloReply reply = Helloworld.HelloReply.newBuilder().setMessage( @@ -24,7 +24,7 @@ number of important features of gRPC being used here: ``` - it provides a class `GreetingsImpl` that implements a generated interface `GreetingsGrpc.Greetings` -- `GreetingsGrpc.Greetings` declares the method `hello` that was declared in the proto [IDL](src/main/proto/helloworld.proto) +- `GreetingsGrpc.Greetings` declares the method `hello` that was declared in the proto [IDL](java/src/main/proto/helloworld.proto) - `hello's` signature is typesafe: hello(Helloworld.HelloRequest req, StreamObserver responseObserver) - `hello` takes two parameters: @@ -38,11 +38,11 @@ number of important features of gRPC being used here: ## Server implementation -[GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java) shows the +[GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java) shows the other main feature required to provde the gRPC service; how to allow a service implementation to be accessed from the network. -``` +```java private void start() throws Exception { server = NettyServerBuilder.forPort(port) .addService(GreetingsGrpc.bindService(new GreetingsImpl())) @@ -62,7 +62,8 @@ implementation to be accessed from the network. This is the same as before: our client and server are part of the same maven package so the same command builds both. -``` +```sh +$ cd java $ mvn package ``` @@ -71,12 +72,12 @@ $ mvn package We've added simple shell scripts to simplifying running the examples. Now that they are built, you can run the server with: -``` +```sh $ ./run_greetings_server.sh ``` and in another terminal window confirm that it receives a message. -``` -$ ./run_greetings_client.sh +```sh +$ ./java/run_greetings_client.sh ``` diff --git a/pom.xml b/java/pom.xml similarity index 100% rename from pom.xml rename to java/pom.xml diff --git a/run_greetings_client.sh b/java/run_greetings_client.sh similarity index 100% rename from run_greetings_client.sh rename to java/run_greetings_client.sh diff --git a/run_greetings_server.sh b/java/run_greetings_server.sh similarity index 100% rename from run_greetings_server.sh rename to java/run_greetings_server.sh diff --git a/src/main/java/ex/grpc/GreetingsClient.java b/java/src/main/java/ex/grpc/GreetingsClient.java similarity index 100% rename from src/main/java/ex/grpc/GreetingsClient.java rename to java/src/main/java/ex/grpc/GreetingsClient.java diff --git a/src/main/java/ex/grpc/GreetingsGrpc.java b/java/src/main/java/ex/grpc/GreetingsGrpc.java similarity index 100% rename from src/main/java/ex/grpc/GreetingsGrpc.java rename to java/src/main/java/ex/grpc/GreetingsGrpc.java diff --git a/src/main/java/ex/grpc/GreetingsImpl.java b/java/src/main/java/ex/grpc/GreetingsImpl.java similarity index 100% rename from src/main/java/ex/grpc/GreetingsImpl.java rename to java/src/main/java/ex/grpc/GreetingsImpl.java diff --git a/src/main/java/ex/grpc/GreetingsServer.java b/java/src/main/java/ex/grpc/GreetingsServer.java similarity index 100% rename from src/main/java/ex/grpc/GreetingsServer.java rename to java/src/main/java/ex/grpc/GreetingsServer.java diff --git a/src/main/java/ex/grpc/Helloworld.java b/java/src/main/java/ex/grpc/Helloworld.java similarity index 100% rename from src/main/java/ex/grpc/Helloworld.java rename to java/src/main/java/ex/grpc/Helloworld.java diff --git a/src/main/proto/helloworld.proto b/java/src/main/proto/helloworld.proto similarity index 100% rename from src/main/proto/helloworld.proto rename to java/src/main/proto/helloworld.proto