Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
panxiaojun233 committed Jan 16, 2021
1 parent 11f914c commit 97861c9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public synchronized void onRefer(RegistryProtocol registryProtocol, ClusterInvok

@Override
public void onDestroy() {
configuration.removeListener(RULE_KEY, this);
if (configuration != null)
configuration.removeListener(RULE_KEY, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ protected void doClose() throws Throwable {
}

channelGroup.close();
Thread.sleep(1000000);
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void gracefulShutdown() {
.writeAscii(ctx.alloc(), goAwayMessage));
goAwayFrame.setExtraStreamIds(Integer.MAX_VALUE);
ctx.write(goAwayFrame);

pingFuture = ctx.executor().schedule(
() -> secondGoAwayAndClose(ctx),
GRACEFUL_SHUTDOWN_PING_TIMEOUT_NANOS,
Expand All @@ -53,6 +52,10 @@ void secondGoAwayAndClose(ChannelHandlerContext ctx) {
pingFuture.cancel(false);

try {
Http2GoAwayFrame goAwayFrame = new DefaultHttp2GoAwayFrame(Http2Error.NO_ERROR, ByteBufUtil.writeAscii(this.ctx.alloc(), this.goAwayMessage));
ctx.write(goAwayFrame);
ctx.flush();
//gracefulShutdownTimeoutMillis
ctx.close();
} catch (Exception e) {
ctx.fireExceptionCaught(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
package org.apache.dubbo.rpc.protocol.tri;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler.Sharable;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
import io.netty.handler.codec.http2.Http2FrameCodec;
import io.netty.handler.codec.http2.Http2FrameCodecBuilder;
import io.netty.handler.codec.http2.Http2MultiplexHandler;
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.ssl.SslContext;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.remoting.netty4.Http2WireProtocol;

import io.netty.handler.codec.http2.Http2ChannelDuplexHandler;

public class GracefulShutdownHandler extends Http2FrameCodec {

public GracefulShutdownHandler() {
}
public class GracefulShutdownHandler extends Http2ChannelDuplexHandler {

@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
super.close(ctx, promise);
new GracefulShutdown(ctx,"app_requested", null).gracefulShutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,4 @@ public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame msg) {
serverStream.halfClose();
}
}

private GracefulShutdown gracefulShutdown;

@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
if (gracefulShutdown == null) {
gracefulShutdown = new GracefulShutdown(ctx,"app_requested", null);
gracefulShutdown.gracefulShutdown();
ctx.flush();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public void configServerPipeline(ChannelPipeline pipeline) {
.frameLogger(SERVER_LOGGER)
.build();
final Http2MultiplexHandler handler = new Http2MultiplexHandler(new TripleServerInitializer());
pipeline.addLast("gracefulShutdown", new GracefulShutdownHandler());
pipeline.addLast(codec, handler);
pipeline.addLast(codec, new GracefulShutdownHandler(), handler);
}

@Override
Expand Down

0 comments on commit 97861c9

Please sign in to comment.