Merge pull request #49 from nmittler/example_updates

Updating examples based on recent changes.
This commit is contained in:
Nathan Mittler 2015-01-29 09:57:57 -08:00
commit 0f1e24a7ea
4 changed files with 23 additions and 26 deletions

View File

@ -32,13 +32,13 @@
package io.grpc.examples; package io.grpc.examples;
import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.SettableFuture;
import com.google.protos.net.stubby.examples.CalcGrpc; import com.google.protos.io.grpc.examples.CalcGrpc;
import com.google.protos.net.stubby.examples.CalcGrpc.CalcBlockingStub; import com.google.protos.io.grpc.examples.CalcGrpc.CalcBlockingStub;
import com.google.protos.net.stubby.examples.CalcGrpc.CalcStub; import com.google.protos.io.grpc.examples.CalcGrpc.CalcStub;
import com.google.protos.net.stubby.examples.Math.DivArgs; import com.google.protos.io.grpc.examples.Math.DivArgs;
import com.google.protos.net.stubby.examples.Math.DivReply; import com.google.protos.io.grpc.examples.Math.DivReply;
import com.google.protos.net.stubby.examples.Math.FibArgs; import com.google.protos.io.grpc.examples.Math.FibArgs;
import com.google.protos.net.stubby.examples.Math.Num; import com.google.protos.io.grpc.examples.Math.Num;
import io.grpc.ChannelImpl; import io.grpc.ChannelImpl;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;

View File

@ -31,11 +31,11 @@
package io.grpc.examples; package io.grpc.examples;
import com.google.protos.net.stubby.examples.CalcGrpc; import com.google.protos.io.grpc.examples.CalcGrpc;
import com.google.protos.net.stubby.examples.Math.DivArgs; import com.google.protos.io.grpc.examples.Math.DivArgs;
import com.google.protos.net.stubby.examples.Math.DivReply; import com.google.protos.io.grpc.examples.Math.DivReply;
import com.google.protos.net.stubby.examples.Math.FibArgs; import com.google.protos.io.grpc.examples.Math.FibArgs;
import com.google.protos.net.stubby.examples.Math.Num; import com.google.protos.io.grpc.examples.Math.Num;
import io.grpc.ServerImpl; import io.grpc.ServerImpl;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
@ -60,7 +60,7 @@ public class MathServer {
public void start() { public void start() {
gRpcServer = NettyServerBuilder.forPort(port) gRpcServer = NettyServerBuilder.forPort(port)
.addService(CalcGrpc.bindService(new CalcService())) .addService(CalcGrpc.bindService(new CalcService()))
.buildAndWaitForRunning(); .build().start();
logger.info("Server started, listening on " + port); logger.info("Server started, listening on " + port);
// TODO(simonma): gRPC server should register JVM shutdown hook to shutdown itself, remove this // TODO(simonma): gRPC server should register JVM shutdown hook to shutdown itself, remove this
// after we support that. // after we support that.
@ -77,15 +77,13 @@ public class MathServer {
public void stop() { public void stop() {
if (gRpcServer != null) { if (gRpcServer != null) {
gRpcServer.stopAsync(); gRpcServer.shutdown();
gRpcServer.awaitTerminated();
} }
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
MathServer server = new MathServer(8980); MathServer server = new MathServer(8980);
server.start(); server.start();
server.gRpcServer.awaitTerminated();
} }
/** /**

View File

@ -31,11 +31,11 @@
package io.grpc.examples; package io.grpc.examples;
import com.google.protos.net.stubby.examples.StockGrpc; import com.google.protos.io.grpc.examples.StockGrpc;
import com.google.protos.net.stubby.examples.StockGrpc.StockBlockingStub; import com.google.protos.io.grpc.examples.StockGrpc.StockBlockingStub;
import com.google.protos.net.stubby.examples.StockGrpc.StockStub; import com.google.protos.io.grpc.examples.StockGrpc.StockStub;
import com.google.protos.net.stubby.examples.StockOuterClass.StockReply; import com.google.protos.io.grpc.examples.StockOuterClass.StockReply;
import com.google.protos.net.stubby.examples.StockOuterClass.StockRequest; import com.google.protos.io.grpc.examples.StockOuterClass.StockRequest;
import io.grpc.ChannelImpl; import io.grpc.ChannelImpl;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;

View File

@ -31,9 +31,9 @@
package io.grpc.examples; package io.grpc.examples;
import com.google.protos.net.stubby.examples.StockGrpc; import com.google.protos.io.grpc.examples.StockGrpc;
import com.google.protos.net.stubby.examples.StockOuterClass.StockReply; import com.google.protos.io.grpc.examples.StockOuterClass.StockReply;
import com.google.protos.net.stubby.examples.StockOuterClass.StockRequest; import com.google.protos.io.grpc.examples.StockOuterClass.StockRequest;
import io.grpc.ServerImpl; import io.grpc.ServerImpl;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
@ -134,8 +134,7 @@ public class StockServer implements StockGrpc.Stock {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ServerImpl server = NettyServerBuilder.forPort(8980) ServerImpl server = NettyServerBuilder.forPort(8980)
.addService(StockGrpc.bindService(new StockServer())) .addService(StockGrpc.bindService(new StockServer()))
.buildAndWaitForRunning(); .build().start();
System.out.println("Server started"); System.out.println("Server started");
server.awaitTerminated();
} }
} }