core,netty: block server shutdown until the socket is unbound

This commit is contained in:
Carl Mastrangelo 2019-06-19 17:23:08 -07:00 committed by GitHub
parent 9739e5b8b6
commit 74e945ceb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -29,8 +29,10 @@ import javax.annotation.concurrent.ThreadSafe;
*/
@ThreadSafe
public abstract class Server {
/**
* Bind and start the server.
* Bind and start the server. After this call returns, clients may begin connecting to the
* listening socket(s).
*
* @return {@code this} object
* @throws IllegalStateException if already started
@ -102,6 +104,8 @@ public abstract class Server {
/**
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected.
* After this call returns, this server has released the listening socket(s) and may be reused by
* another server.
*
* @return {@code this} object
* @since 1.0.0
@ -111,7 +115,8 @@ public abstract class Server {
/**
* Initiates a forceful shutdown in which preexisting and new calls are rejected. Although
* forceful, the shutdown process is still not instantaneous; {@link #isTerminated()} will likely
* return {@code false} immediately after this method returns.
* return {@code false} immediately after this method returns. After this call returns, this
* server has released the listening socket(s) and may be reused by another server.
*
* @return {@code this} object
* @since 1.0.0

View File

@ -42,7 +42,9 @@ public interface InternalServer {
/**
* Initiates an orderly shutdown of the server. Existing transports continue, but new transports
* will not be created (once {@link ServerListener#serverShutdown()} callback is called). This
* method may only be called once.
* method may only be called once. Blocks until the listening socket(s) have been closed. If
* interrupted, this method will not wait for the close to complete, but it will happen
* asynchronously.
*/
void shutdown();

View File

@ -283,6 +283,12 @@ class NettyServer implements InternalServer, InternalWithLogId {
eventLoopReferenceCounter.release();
}
});
try {
channel.closeFuture().sync();
} catch (InterruptedException e) {
log.log(Level.FINE, "Interrupted while shutting down", e);
Thread.currentThread().interrupt();
}
}
@Override