Skip to content

Commit

Permalink
Make http2 connection extend ConnectionBase
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Mar 14, 2016
1 parent b4fbb11 commit 0d404c7
Show file tree
Hide file tree
Showing 11 changed files with 618 additions and 691 deletions.
Expand Up @@ -23,11 +23,8 @@
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http2.DefaultHttp2Headers; import io.netty.handler.codec.http2.DefaultHttp2Headers;
import io.netty.handler.codec.http2.Http2Connection; import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
import io.netty.handler.codec.http2.Http2Exception; import io.netty.handler.codec.http2.Http2Exception;
import io.netty.handler.codec.http2.Http2Headers; import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.codec.http2.Http2Stream; import io.netty.handler.codec.http2.Http2Stream;
import io.vertx.core.Context; import io.vertx.core.Context;
import io.vertx.core.MultiMap; import io.vertx.core.MultiMap;
Expand All @@ -47,47 +44,40 @@
/** /**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a> * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/ */
class VertxHttp2ClientHandler extends VertxHttp2ConnectionHandler implements HttpClientConnection { class Http2ClientConnection extends Http2ConnectionBase implements HttpClientConnection {


final Http2Pool http2Pool; final Http2Pool http2Pool;
long streamCount; long streamCount;


public VertxHttp2ClientHandler(Http2Pool http2Pool, public Http2ClientConnection(Http2Pool http2Pool,
ChannelHandlerContext handlerCtx, ChannelHandlerContext handlerCtx,
ContextImpl context, ContextImpl context,
Channel channel, Channel channel,
Http2ConnectionDecoder decoder, VertxHttp2ConnectionHandler connHandler) {
Http2ConnectionEncoder encoder, super(handlerCtx, channel, context, connHandler);
Http2Settings initialSettings) {
super(handlerCtx, channel, context, decoder, encoder, initialSettings);
this.http2Pool = http2Pool; this.http2Pool = http2Pool;
} }


@Override @Override
public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) { public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) {
http2Pool.discard(VertxHttp2ClientHandler.this); http2Pool.discard(Http2ClientConnection.this);
} }


@Override @Override
public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) {
super.onGoAwayReceived(lastStreamId, errorCode, debugData); super.onGoAwayReceived(lastStreamId, errorCode, debugData);
http2Pool.discard(VertxHttp2ClientHandler.this); http2Pool.discard(Http2ClientConnection.this);
} }


@Override @Override
public void onStreamClosed(Http2Stream nettyStream) { public void onStreamClosed(Http2Stream nettyStream) {
super.onStreamClosed(nettyStream); super.onStreamClosed(nettyStream);
http2Pool.recycle(VertxHttp2ClientHandler.this); http2Pool.recycle(Http2ClientConnection.this);
}

@Override
public Context getContext() {
return context;
} }


HttpClientStream createStream() { HttpClientStream createStream() {
try { try {
Http2Connection conn = connection(); Http2Connection conn = connHandler.connection();
Http2Stream stream = conn.local().createStream(conn.local().incrementAndGetNextStreamId(), false); Http2Stream stream = conn.local().createStream(conn.local().incrementAndGetNextStreamId(), false);
Http2ClientStream clientStream = new Http2ClientStream(this, stream); Http2ClientStream clientStream = new Http2ClientStream(this, stream);
streams.put(clientStream.stream.id(), clientStream); streams.put(clientStream.stream.id(), clientStream);
Expand All @@ -107,7 +97,7 @@ public void reportBytesRead(long s) {


@Override @Override
public boolean isValid() { public boolean isValid() {
Http2Connection conn = connection(); Http2Connection conn = connHandler.connection();
return !conn.goAwaySent() && !conn.goAwayReceived(); return !conn.goAwaySent() && !conn.goAwayReceived();
} }


Expand Down Expand Up @@ -143,15 +133,15 @@ public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promi
String uri = headers.path().toString(); String uri = headers.path().toString();
String host = headers.authority() != null ? headers.authority().toString() : null; String host = headers.authority() != null ? headers.authority().toString() : null;
MultiMap headersMap = new Http2HeadersAdaptor(headers); MultiMap headersMap = new Http2HeadersAdaptor(headers);
Http2Stream promisedStream = connection().stream(promisedStreamId); Http2Stream promisedStream = connHandler.connection().stream(promisedStreamId);
HttpClientRequestPushPromise promisedReq = new HttpClientRequestPushPromise(this, promisedStream, http2Pool.client, method, uri, host, headersMap); HttpClientRequestPushPromise promisedReq = new HttpClientRequestPushPromise(this, promisedStream, http2Pool.client, method, uri, host, headersMap);
streams.put(promisedStreamId, promisedReq.getStream()); streams.put(promisedStreamId, promisedReq.getStream());
stream.handlePushPromise(promisedReq); stream.handlePushPromise(promisedReq);
} }


static class Http2ClientStream extends VertxHttp2Stream implements HttpClientStream { static class Http2ClientStream extends VertxHttp2Stream implements HttpClientStream {


private final VertxHttp2ClientHandler handler; private final Http2ClientConnection handler;
private final ContextImpl context; private final ContextImpl context;
private final ChannelHandlerContext handlerCtx; private final ChannelHandlerContext handlerCtx;
private final Http2Connection conn; private final Http2Connection conn;
Expand All @@ -160,16 +150,16 @@ static class Http2ClientStream extends VertxHttp2Stream implements HttpClientStr
private HttpClientResponseImpl resp; private HttpClientResponseImpl resp;
private boolean ended; private boolean ended;


public Http2ClientStream(VertxHttp2ClientHandler handler, Http2Stream stream) throws Http2Exception { public Http2ClientStream(Http2ClientConnection handler, Http2Stream stream) throws Http2Exception {
this(handler, null, stream); this(handler, null, stream);
} }


public Http2ClientStream(VertxHttp2ClientHandler handler, HttpClientRequestBase req, Http2Stream stream) throws Http2Exception { public Http2ClientStream(Http2ClientConnection handler, HttpClientRequestBase req, Http2Stream stream) throws Http2Exception {
super(handler.http2Pool.client.getVertx(), handler.context, handler.handlerCtx, handler.encoder(), handler.decoder(), stream); super(handler.http2Pool.client.getVertx(), handler.context, handler.handlerCtx, handler.connHandler.encoder(), handler.connHandler.decoder(), stream);
this.handler = handler; this.handler = handler;
this.context = handler.context; this.context = handler.context;
this.handlerCtx = handler.handlerCtx; this.handlerCtx = handler.handlerCtx;
this.conn = handler.connection(); this.conn = handler.connHandler.connection();
this.stream = stream; this.stream = stream;
this.req = req; this.req = req;
} }
Expand Down Expand Up @@ -303,6 +293,7 @@ public void writeBuffer(ByteBuf buf, boolean end) {
public Context getContext() { public Context getContext() {
return context; return context;
} }

@Override @Override
public void doSetWriteQueueMaxSize(int size) { public void doSetWriteQueueMaxSize(int size) {
} }
Expand Down

0 comments on commit 0d404c7

Please sign in to comment.