Skip to content

Commit

Permalink
Reduce chances of type check scalability issues (Fixes eclipse-vertx#…
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Dec 21, 2023
1 parent 446a85a commit f2ecf6b
Showing 1 changed file with 44 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
class VertxHttp2ConnectionHandler<C extends Http2ConnectionBase> extends Http2ConnectionHandler implements Http2FrameListener, Http2Connection.Listener {
class VertxHttp2ConnectionHandler<C extends Http2ConnectionBase> extends Http2ConnectionHandler implements Http2FrameListener {

private final Function<VertxHttp2ConnectionHandler<C>, C> connectionFactory;
private C connection;
Expand Down Expand Up @@ -60,7 +60,44 @@ public VertxHttp2ConnectionHandler(
connection.onStreamWritabilityChanged(s);
}
});
connection().addListener(this);

// Uses companion a class due to https://github.com/eclipse-vertx/vert.x/issues/5039
connection().addListener(new Http2Connection.Listener() {
@Override
public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) {
connection.onGoAwaySent(new GoAway().setErrorCode(errorCode).setLastStreamId(lastStreamId).setDebugData(Buffer.buffer(debugData)));
}

@Override
public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) {
connection.onGoAwayReceived(new GoAway().setErrorCode(errorCode).setLastStreamId(lastStreamId).setDebugData(Buffer.buffer(debugData)));
}

@Override
public void onStreamAdded(Http2Stream stream) {

}

@Override
public void onStreamActive(Http2Stream stream) {

}

@Override
public void onStreamHalfClosed(Http2Stream stream) {

}

@Override
public void onStreamClosed(Http2Stream stream) {
connection.onStreamClosed(stream);
}

@Override
public void onStreamRemoved(Http2Stream stream) {

}
});
}

public Future<C> connectFuture() {
Expand Down Expand Up @@ -183,39 +220,6 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc

//

@Override
public void onStreamClosed(Http2Stream stream) {
connection.onStreamClosed(stream);
}

@Override
public void onStreamAdded(Http2Stream stream) {
}

@Override
public void onStreamActive(Http2Stream stream) {
}

@Override
public void onStreamHalfClosed(Http2Stream stream) {
}

@Override
public void onStreamRemoved(Http2Stream stream) {
}

@Override
public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) {
connection.onGoAwaySent(new GoAway().setErrorCode(errorCode).setLastStreamId(lastStreamId).setDebugData(Buffer.buffer(debugData)));
}

@Override
public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) {
connection.onGoAwayReceived(new GoAway().setErrorCode(errorCode).setLastStreamId(lastStreamId).setDebugData(Buffer.buffer(debugData)));
}

//

void writeHeaders(Http2Stream stream, Http2Headers headers, boolean end, int streamDependency, short weight, boolean exclusive, boolean checkFlush, FutureListener<Void> listener) {
ChannelPromise promise = listener == null ? chctx.voidPromise() : chctx.newPromise().addListener(listener);
encoder().writeHeaders(chctx, stream.id(), headers, streamDependency, weight, exclusive, 0, end, promise);
Expand Down Expand Up @@ -402,6 +406,11 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) th
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
read = true;
// fast-path first
if (msg instanceof ByteBuf) {
super.channelRead(ctx, msg);
return;
}
if (msg instanceof Http2StreamFrame) {
// Handle HTTP/2 clear text upgrade request
if (msg instanceof Http2HeadersFrame) {
Expand Down

0 comments on commit f2ecf6b

Please sign in to comment.