diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DecoratingHttp2ConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DecoratingHttp2ConnectionDecoder.java index 4e056343cb..159c7ac70c 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DecoratingHttp2ConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DecoratingHttp2ConnectionDecoder.java @@ -47,8 +47,8 @@ public class DecoratingHttp2ConnectionDecoder implements Http2ConnectionDecoder } @Override - public Http2FrameListener listener() { - return delegate.listener(); + public void frameListener(Http2FrameListener listener) { + delegate.frameListener(listener); } @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java index e9437c60b2..545945b7a3 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java @@ -44,25 +44,22 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder { private Http2LifecycleManager lifecycleManager; private final Http2ConnectionEncoder encoder; private final Http2FrameReader frameReader; - private final Http2FrameListener listener; + private Http2FrameListener listener; private final Http2PromisedRequestVerifier requestVerifier; public DefaultHttp2ConnectionDecoder(Http2Connection connection, Http2ConnectionEncoder encoder, - Http2FrameReader frameReader, - Http2FrameListener listener) { - this(connection, encoder, frameReader, listener, ALWAYS_VERIFY); + Http2FrameReader frameReader) { + this(connection, encoder, frameReader, ALWAYS_VERIFY); } public DefaultHttp2ConnectionDecoder(Http2Connection connection, Http2ConnectionEncoder encoder, Http2FrameReader frameReader, - Http2FrameListener listener, Http2PromisedRequestVerifier requestVerifier) { this.connection = checkNotNull(connection, "connection"); this.frameReader = checkNotNull(frameReader, "frameReader"); this.encoder = checkNotNull(encoder, "encoder"); - this.listener = checkNotNull(listener, "listener"); this.requestVerifier = checkNotNull(requestVerifier, "requestVerifier"); if (connection.local().flowController() == null) { connection.local().flowController( @@ -86,8 +83,8 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder { } @Override - public Http2FrameListener listener() { - return listener; + public void frameListener(Http2FrameListener listener) { + this.listener = checkNotNull(listener, "listener"); } @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionDecoder.java index b2c68e79b0..6e169bee9e 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionDecoder.java @@ -44,9 +44,11 @@ public interface Http2ConnectionDecoder extends Closeable { Http2LocalFlowController flowController(); /** - * Provides direct access to the underlying frame listener. + * Set the {@link Http2FrameListener} which will be notified when frames are decoded. + *
+ * This must be set before frames are decoded.
*/
- Http2FrameListener listener();
+ void frameListener(Http2FrameListener listener);
/**
* Called by the {@link Http2ConnectionHandler} to decode the next frame from the input buffer.
diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
index a1e65b495e..14814d7e80 100644
--- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
+++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java
@@ -71,27 +71,27 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
private BaseDecoder byteDecoder;
private long gracefulShutdownTimeoutMillis = DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS;
- public Http2ConnectionHandler(boolean server, Http2FrameListener listener) {
- this(server, listener, true);
+ public Http2ConnectionHandler(boolean server) {
+ this(server, true);
}
- public Http2ConnectionHandler(boolean server, Http2FrameListener listener, boolean validateHeaders) {
- this(new DefaultHttp2Connection(server), listener, validateHeaders);
+ public Http2ConnectionHandler(boolean server, boolean validateHeaders) {
+ this(new DefaultHttp2Connection(server), validateHeaders);
}
- public Http2ConnectionHandler(Http2Connection connection, Http2FrameListener listener) {
- this(connection, listener, true);
+ public Http2ConnectionHandler(Http2Connection connection) {
+ this(connection, true);
}
- public Http2ConnectionHandler(Http2Connection connection, Http2FrameListener listener, boolean validateHeaders) {
- this(connection, new DefaultHttp2FrameReader(validateHeaders), new DefaultHttp2FrameWriter(), listener);
+ public Http2ConnectionHandler(Http2Connection connection, boolean validateHeaders) {
+ this(connection, new DefaultHttp2FrameReader(validateHeaders), new DefaultHttp2FrameWriter());
}
public Http2ConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
- Http2FrameWriter frameWriter, Http2FrameListener listener) {
+ Http2FrameWriter frameWriter) {
initialSettings = null;
encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
- decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader, listener);
+ decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);
}
/**
@@ -108,18 +108,16 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
}
}
- public Http2ConnectionHandler(Http2Connection connection, Http2FrameListener listener,
- Http2Settings initialSettings) {
- this(connection, new DefaultHttp2FrameReader(), new DefaultHttp2FrameWriter(), listener,
+ public Http2ConnectionHandler(Http2Connection connection, Http2Settings initialSettings) {
+ this(connection, new DefaultHttp2FrameReader(), new DefaultHttp2FrameWriter(),
initialSettings);
}
public Http2ConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
- Http2FrameWriter frameWriter, Http2FrameListener listener,
- Http2Settings initialSettings) {
+ Http2FrameWriter frameWriter, Http2Settings initialSettings) {
this.initialSettings = initialSettings;
encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
- decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader, listener);
+ decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);
}
public Http2ConnectionHandler(Http2ConnectionDecoder decoder,
diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java
index 6a8328190b..f390c0f3e6 100644
--- a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java
+++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java
@@ -36,33 +36,32 @@ public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler {
private final boolean validateHeaders;
private int currentStreamId;
- public HttpToHttp2ConnectionHandler(boolean server, Http2FrameListener listener) {
- this(server, listener, true);
+ public HttpToHttp2ConnectionHandler(boolean server) {
+ this(server, true);
}
- public HttpToHttp2ConnectionHandler(boolean server, Http2FrameListener listener, boolean validateHeaders) {
- super(server, listener);
+ public HttpToHttp2ConnectionHandler(boolean server, boolean validateHeaders) {
+ super(server);
this.validateHeaders = validateHeaders;
}
- public HttpToHttp2ConnectionHandler(Http2Connection connection, Http2FrameListener listener) {
- this(connection, listener, true);
+ public HttpToHttp2ConnectionHandler(Http2Connection connection) {
+ this(connection, true);
}
- public HttpToHttp2ConnectionHandler(Http2Connection connection, Http2FrameListener listener,
- boolean validateHeaders) {
- super(connection, listener);
+ public HttpToHttp2ConnectionHandler(Http2Connection connection, boolean validateHeaders) {
+ super(connection);
this.validateHeaders = validateHeaders;
}
public HttpToHttp2ConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
- Http2FrameWriter frameWriter, Http2FrameListener listener) {
- this(connection, frameReader, frameWriter, listener, true);
+ Http2FrameWriter frameWriter) {
+ this(connection, frameReader, frameWriter, true);
}
public HttpToHttp2ConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
- Http2FrameWriter frameWriter, Http2FrameListener listener, boolean validateHeaders) {
- super(connection, frameReader, frameWriter, listener);
+ Http2FrameWriter frameWriter, boolean validateHeaders) {
+ super(connection, frameReader, frameWriter);
this.validateHeaders = validateHeaders;
}
diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java
index b7416bc39e..d0abe212fb 100644
--- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java
+++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java
@@ -299,9 +299,8 @@ public class DataCompressionHttp2Test {
Http2ConnectionEncoder encoder = new CompressorHttp2ConnectionEncoder(
new DefaultHttp2ConnectionEncoder(serverConnection, new DefaultHttp2FrameWriter()));
Http2ConnectionDecoder decoder =
- new DefaultHttp2ConnectionDecoder(serverConnection, encoder, new DefaultHttp2FrameReader(),
- new DelegatingDecompressorFrameListener(serverConnection,
- serverListener));
+ new DefaultHttp2ConnectionDecoder(serverConnection, encoder, new DefaultHttp2FrameReader());
+ decoder.frameListener(new DelegatingDecompressorFrameListener(serverConnection, serverListener));
Http2ConnectionHandler connectionHandler = new Http2ConnectionHandler(decoder, encoder);
p.addLast(connectionHandler);
serverChannelLatch.countDown();
@@ -318,9 +317,8 @@ public class DataCompressionHttp2Test {
new DefaultHttp2ConnectionEncoder(clientConnection, new DefaultHttp2FrameWriter()));
Http2ConnectionDecoder decoder =
new DefaultHttp2ConnectionDecoder(clientConnection, clientEncoder,
- new DefaultHttp2FrameReader(),
- new DelegatingDecompressorFrameListener(clientConnection,
- clientListener));
+ new DefaultHttp2FrameReader());
+ decoder.frameListener(new DelegatingDecompressorFrameListener(clientConnection, clientListener));
clientHandler = new Http2ConnectionHandler(decoder, clientEncoder);
// By default tests don't wait for server to gracefully shutdown streams
diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java
index 8b88bcd8e8..8c41d38bdc 100644
--- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java
+++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java
@@ -150,8 +150,9 @@ public class DefaultHttp2ConnectionDecoderTest {
when(ctx.newPromise()).thenReturn(promise);
when(ctx.write(any())).thenReturn(future);
- decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, reader, listener);
+ decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, reader);
decoder.lifecycleManager(lifecycleManager);
+ decoder.frameListener(listener);
// Simulate receiving the initial settings from the remote endpoint.
decode().onSettingsRead(ctx, new Http2Settings());
diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java
index 54c3497107..b259599699 100644
--- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java
+++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java
@@ -482,7 +482,9 @@ public class Http2ConnectionRoundtripTest {
serverFrameCountDown =
new FrameCountDown(serverListener, serverSettingsAckLatch,
requestLatch, dataLatch, trailersLatch, goAwayLatch);
- p.addLast(new Http2ConnectionHandler(true, serverFrameCountDown, false));
+ Http2ConnectionHandler handler = new Http2ConnectionHandler(true, false);
+ handler.decoder().frameListener(serverFrameCountDown);
+ p.addLast(handler);
}
});
@@ -492,7 +494,9 @@ public class Http2ConnectionRoundtripTest {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
- p.addLast(new Http2ConnectionHandler(false, clientListener, false));
+ Http2ConnectionHandler handler = new Http2ConnectionHandler(false, false);
+ handler.decoder().frameListener(clientListener);
+ p.addLast(handler);
}
});
diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java
index ebe2302de8..93af70853c 100644
--- a/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java
+++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandlerTest.java
@@ -487,7 +487,9 @@ public class HttpToHttp2ConnectionHandlerTest {
ChannelPipeline p = ch.pipeline();
serverFrameCountDown =
new FrameCountDown(serverListener, serverSettingsAckLatch, requestLatch, null, trailersLatch);
- p.addLast(new HttpToHttp2ConnectionHandler(true, serverFrameCountDown));
+ HttpToHttp2ConnectionHandler handler = new HttpToHttp2ConnectionHandler(true);
+ handler.decoder().frameListener(serverFrameCountDown);
+ p.addLast(handler);
}
});
@@ -497,7 +499,8 @@ public class HttpToHttp2ConnectionHandlerTest {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
- HttpToHttp2ConnectionHandler handler = new HttpToHttp2ConnectionHandler(false, clientListener);
+ HttpToHttp2ConnectionHandler handler = new HttpToHttp2ConnectionHandler(false);
+ handler.decoder().frameListener(clientListener);
handler.gracefulShutdownTimeoutMillis(0);
p.addLast(handler);
}
diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/StreamBufferingEncoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/StreamBufferingEncoderTest.java
index fe1aa928d6..124a8b4d67 100644
--- a/codec-http2/src/test/java/io/netty/handler/codec/http2/StreamBufferingEncoderTest.java
+++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/StreamBufferingEncoderTest.java
@@ -110,8 +110,8 @@ public class StreamBufferingEncoderTest {
new DefaultHttp2ConnectionEncoder(connection, writer);
encoder = new StreamBufferingEncoder(defaultEncoder);
DefaultHttp2ConnectionDecoder decoder =
- new DefaultHttp2ConnectionDecoder(connection, encoder,
- mock(Http2FrameReader.class), mock(Http2FrameListener.class));
+ new DefaultHttp2ConnectionDecoder(connection, encoder, mock(Http2FrameReader.class));
+ decoder.frameListener(mock(Http2FrameListener.class));
Http2ConnectionHandler handler = new Http2ConnectionHandler(decoder, encoder);
// Set LifeCycleManager on encoder and decoder
diff --git a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java
index ab58c58bae..4e569a0194 100644
--- a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java
+++ b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2ClientInitializer.java
@@ -62,10 +62,8 @@ public class Http2ClientInitializer extends ChannelInitializer