Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
panxiaojun233 committed Jan 18, 2021
1 parent 0c68ca4 commit 9a76441
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.remoting.api;

import io.netty.channel.group.ChannelGroupFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
Expand Down Expand Up @@ -156,24 +157,30 @@ protected void doClose() throws Throwable {
channel.close();
channel = null;
}
long start = System.currentTimeMillis();
channelGroup.close().addListener(new GenericFutureListener<Future<? super Void>>() {

ChannelGroupFuture closeFuture = channelGroup.close();
closeFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(final Future future) throws Exception {
System.out.println("1shut operationComplete..");
if (!future.isSuccess()) {
logger.warn("Error shutting down server", future.cause());
}
System.out.println("shut operationComplete..");
long now = System.currentTimeMillis();
long start = System.currentTimeMillis();
long now = start;
while (now - start <= 15000 || channelGroup.size() > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
now = System.currentTimeMillis();
}
}
}).await(15000);
System.out.println("close cost:" + (System.currentTimeMillis()-start));
});
closeFuture.await(15000);

System.out.println("close ...");
} catch (InterruptedException e) {
System.out.println("Interrupted while shutting down" + e.getMessage());
logger.warn("Interrupted while shutting down", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http2.DefaultHttp2GoAwayFrame;
import io.netty.handler.codec.http2.DefaultHttp2PingFrame;
import io.netty.handler.codec.http2.Http2Error;
Expand Down Expand Up @@ -56,7 +57,7 @@ void secondGoAwayAndClose(ChannelHandlerContext ctx) {
ctx.write(goAwayFrame);
ctx.flush();
//gracefulShutdownTimeoutMillis
//ctx.close();
ctx.close();
} catch (Exception e) {
ctx.fireExceptionCaught(e);
}
Expand Down

0 comments on commit 9a76441

Please sign in to comment.