Skip to content

Commit

Permalink
Update server to await termination in the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-mastrangelo committed Sep 8, 2015
1 parent 091749e commit f06c7eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,22 @@ private void stop() {
}
}

/**
* Await termination on the main thread since the grpc library uses daemon threads.
*/
private void blockUntilShutdown() throws InterruptedException {
if (server != null) {
server.awaitTermination();
}
}

/**
* Main launches the server from the command line.
*/
public static void main(String[] args) throws Exception {
final CustomHeaderServer server = new CustomHeaderServer();
server.start();
server.blockUntilShutdown();
}

private class GreeterImpl implements GreeterGrpc.Greeter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,22 @@ private void stop() {
}
}

/**
* Await termination on the main thread since the grpc library uses daemon threads.
*/
private void blockUntilShutdown() throws InterruptedException {
if (server != null) {
server.awaitTermination();
}
}

/**
* Main launches the server from the command line.
*/
public static void main(String[] args) throws Exception {
final HelloWorldServer server = new HelloWorldServer();
server.start();
server.blockUntilShutdown();
}

private class GreeterImpl implements GreeterGrpc.Greeter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,22 @@ public void stop() {
}
}

/**
* Await termination on the main thread since the grpc library uses daemon threads.
*/
private void blockUntilShutdown() throws InterruptedException {
if (grpcServer != null) {
grpcServer.awaitTermination();
}
}

/**
* Main method. This comment makes the linter happy.
*/
public static void main(String[] args) throws Exception {
RouteGuideServer server = new RouteGuideServer(8980);
server.start();
server.blockUntilShutdown();
}

/**
Expand Down

0 comments on commit f06c7eb

Please sign in to comment.