Skip to content

Commit 3328bfc

Browse files
committed
Update shutdown API documentation
1 parent 6784bca commit 3328bfc

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

api/src/main/java/io/grpc/Server.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ public List<ServerServiceDefinition> getMutableServices() {
104104

105105
/**
106106
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
107-
* This call will not wait for preexisting calls finish before returning. After this call returns,
108-
* this server has released the listening socket(s) and may be reused by another server.
107+
* After this call returns, this server has released the listening socket(s) and may be reused by
108+
* another server.
109+
*
110+
* Note that this method will not wait for preexisting calls to finish before returning.
111+
* {@link #awaitTermination()} or {@link #awaitTermination(long, TimeUnit)} needs to be called to
112+
* wait for existing calls to finish.
109113
*
110114
* @return {@code this} object
111115
* @since 1.0.0

examples/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ targetCompatibility = 1.7
2222

2323
// Feel free to delete the comment at the next line. It is just for safely
2424
// updating the version in our release process.
25-
def grpcVersion = '1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
25+
def grpcVersion = '1.24.2' // CURRENT_GRPC_VERSION
2626
def protobufVersion = '3.11.0'
2727
def protocVersion = protobufVersion
2828

examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ public class HelloWorldServer {
3434
private void start() throws IOException {
3535
/* The port on which the server should run */
3636
int port = 50051;
37-
server = ServerBuilder.forPort(port)
38-
.addService(new GreeterImpl())
39-
.build()
40-
.start();
37+
server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
4138
logger.info("Server started, listening on " + port);
4239
Runtime.getRuntime().addShutdownHook(new Thread() {
4340
@Override
4441
public void run() {
45-
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
42+
// Use stderr here since the logger may have been reset by its JVM shutdown
43+
// hook.
4644
System.err.println("*** shutting down gRPC server since JVM is shutting down");
47-
HelloWorldServer.this.stop();
45+
// HelloWorldServer.this.stop();
4846
System.err.println("*** server shut down");
4947
}
5048
});
@@ -61,7 +59,8 @@ private void stop() {
6159
}
6260

6361
/**
64-
* Await termination on the main thread since the grpc library uses daemon threads.
62+
* Await termination on the main thread since the grpc library uses daemon
63+
* threads.
6564
*/
6665
private void blockUntilShutdown() throws InterruptedException {
6766
if (server != null) {
@@ -82,6 +81,13 @@ static class GreeterImpl extends GreeterGrpc.GreeterImplBase {
8281

8382
@Override
8483
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
84+
logger.info("!!! Received call");
85+
try {
86+
Thread.sleep(15000);
87+
} catch (InterruptedException e) {
88+
// TODO Auto-generated catch block
89+
e.printStackTrace();
90+
}
8591
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
8692
responseObserver.onNext(reply);
8793
responseObserver.onCompleted();

0 commit comments

Comments
 (0)