Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
panxiaojun233 committed Dec 27, 2020
1 parent 29feca6 commit ac1cc65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpServerUpgradeHandler;
import io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
Expand All @@ -18,10 +16,13 @@
import static io.netty.util.CharsetUtil.UTF_8;

public class DubboHttp2ConnectionHandler extends Http2ConnectionHandler {
private ChannelHandlerContext ctx;

static final long GRACEFUL_SHUTDOWN_PING = 0x97ACEF001L;
private final Http2ConnectionEncoder encoder;

protected DubboHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) {
super(decoder, encoder, initialSettings);
this.encoder = encoder;
}

@Override
Expand All @@ -33,6 +34,7 @@ public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exce
ByteBufUtil.writeAscii(ctx.alloc(), "app_requested"),
ctx.newPromise());

encoder.writePing(ctx, false /* isAck */, GRACEFUL_SHUTDOWN_PING, ctx.newPromise());

super.close(ctx, promise);
}
Expand All @@ -51,8 +53,6 @@ public ChannelFuture goAway(final ChannelHandlerContext ctx, final int lastStrea
return promise;
}

// Need to retain before we write the buffer because if we do it after the refCnt could already be 0 and
// result in an IllegalRefCountException.
debugData.retain();
ChannelFuture future = encoder.frameWriter().writeGoAway(ctx, lastStreamId, errorCode, debugData, promise);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import org.apache.dubbo.rpc.model.ServiceRepository;

import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http2.Http2Error.NO_ERROR;
import static io.netty.util.CharsetUtil.UTF_8;

public class GrpcHttp2FrameListener extends Http2FrameAdapter {
private TripleProtocol TRIPLE_PROTOCOL = TripleProtocol.getTripleProtocol();
Expand Down Expand Up @@ -96,9 +94,9 @@ public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int
ByteBuf byteBuf = Marshaller.marshaller.marshaller(ctx.alloc(), response.getValue());
StreamData streamData = new StreamData(false, streamId, byteBuf);
ctx.channel().write(streamData);
//final Http2Headers trailers = new DefaultHttp2Headers()
// .setInt(GrpcElf.GRPC_STATUS, Status.Code.OK.value());
//ctx.channel().write(new StreamHeader(streamId, trailers, true));
final Http2Headers trailers = new DefaultHttp2Headers()
.setInt(GrpcElf.GRPC_STATUS, Status.Code.OK.value());
ctx.channel().write(new StreamHeader(streamId, trailers, true));
}
} else {
}
Expand All @@ -115,6 +113,7 @@ private Invocation buildInvocation(Http2Headers http2Headers, ByteBuf data) {
RpcInvocation inv = new RpcInvocation();
final String path = http2Headers.path().toString();
String[] parts = path.split("/");
// todo
String serviceName = "io.grpc.examples.helloworld.IGreeter";
String methodName = "sayHello";
ServiceRepository repo = ApplicationModel.getServiceRepository();
Expand Down Expand Up @@ -187,10 +186,6 @@ public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers
Http2Request request = new Http2Request(streamId, http2Stream, headers, streamKey, marshaller,
ctx.alloc());
http2Stream.setProperty(streamKey, request);

if (endStream) {

}
}

}

0 comments on commit ac1cc65

Please sign in to comment.