diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java index 04f01b9341..4d91377550 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java @@ -40,7 +40,7 @@ import io.netty.handler.codec.compression.ZlibWrapper; public class CompressorHttp2ConnectionEncoder extends DecoratingHttp2ConnectionEncoder { private static final Http2ConnectionAdapter CLEAN_UP_LISTENER = new Http2ConnectionAdapter() { @Override - public void streamRemoved(Http2Stream stream) { + public void onStreamRemoved(Http2Stream stream) { final EmbeddedChannel compressor = stream.getProperty(CompressorHttp2ConnectionEncoder.class); if (compressor != null) { cleanup(stream, compressor); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java index 408f17dc4e..cd507c953d 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java @@ -33,6 +33,8 @@ import static io.netty.handler.codec.http2.Http2Stream.State.OPEN; import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_LOCAL; import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_REMOTE; import static io.netty.util.internal.ObjectUtil.checkNotNull; + +import io.netty.buffer.ByteBuf; import io.netty.handler.codec.http2.Http2StreamRemovalPolicy.Action; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; @@ -150,19 +152,20 @@ public class DefaultHttp2Connection implements Http2Connection { return remoteEndpoint; } - @Override - public boolean isGoAway() { - return goAwaySent() || goAwayReceived(); - } - @Override public boolean goAwayReceived() { return localEndpoint.lastKnownStream >= 0; } @Override - public void goAwayReceived(int lastKnownStream) { + public void goAwayReceived(int lastKnownStream, long errorCode, ByteBuf debugData) { + boolean alreadyNotified = goAwayReceived(); localEndpoint.lastKnownStream(lastKnownStream); + if (!alreadyNotified) { + for (Listener listener : listeners) { + listener.onGoAwayReceived(lastKnownStream, errorCode, debugData); + } + } } @Override @@ -171,14 +174,20 @@ public class DefaultHttp2Connection implements Http2Connection { } @Override - public void goAwaySent(int lastKnownStream) { + public void goAwaySent(int lastKnownStream, long errorCode, ByteBuf debugData) { + boolean alreadyNotified = goAwaySent(); remoteEndpoint.lastKnownStream(lastKnownStream); + if (!alreadyNotified) { + for (Listener listener : listeners) { + listener.onGoAwaySent(lastKnownStream, errorCode, debugData); + } + } } private void removeStream(DefaultStream stream) { // Notify the listeners of the event first. for (Listener listener : listeners) { - listener.streamRemoved(stream); + listener.onStreamRemoved(stream); } // Remove it from the map and priority tree. @@ -353,7 +362,7 @@ public class DefaultHttp2Connection implements Http2Connection { // Notify the listeners. for (Listener listener : listeners) { - listener.streamActive(this); + listener.onStreamActive(this); } } return this; @@ -373,7 +382,7 @@ public class DefaultHttp2Connection implements Http2Connection { // Notify the listeners. for (Listener listener : listeners) { - listener.streamClosed(this); + listener.onStreamClosed(this); } } finally { // Mark this stream for removal. @@ -417,7 +426,7 @@ public class DefaultHttp2Connection implements Http2Connection { private void notifyHalfClosed(Http2Stream stream) { for (Listener listener : listeners) { - listener.streamHalfClosed(stream); + listener.onStreamHalfClosed(stream); } } @@ -604,7 +613,7 @@ public class DefaultHttp2Connection implements Http2Connection { * @param l The listener to notify */ public void notifyListener(Listener l) { - l.priorityTreeParentChanged(stream, oldParent); + l.onPriorityTreeParentChanged(stream, oldParent); } } @@ -623,7 +632,7 @@ public class DefaultHttp2Connection implements Http2Connection { private void notifyParentChanging(Http2Stream stream, Http2Stream newParent) { for (Listener l : listeners) { - l.priorityTreeParentChanging(stream, newParent); + l.onPriorityTreeParentChanging(stream, newParent); } } @@ -759,7 +768,7 @@ public class DefaultHttp2Connection implements Http2Connection { // Notify the listeners of the event. for (Listener listener : listeners) { - listener.streamAdded(stream); + listener.onStreamAdded(stream); } notifyParentChanged(events); @@ -804,17 +813,7 @@ public class DefaultHttp2Connection implements Http2Connection { } private void lastKnownStream(int lastKnownStream) { - boolean alreadyNotified = isGoAway(); this.lastKnownStream = lastKnownStream; - if (!alreadyNotified) { - notifyGoingAway(); - } - } - - private void notifyGoingAway() { - for (Listener listener : listeners) { - listener.goingAway(); - } } @Override @@ -833,7 +832,7 @@ public class DefaultHttp2Connection implements Http2Connection { } private void checkNewStreamAllowed(int streamId) throws Http2Exception { - if (isGoAway()) { + if (goAwaySent() || goAwayReceived()) { throw connectionError(PROTOCOL_ERROR, "Cannot create a stream since the connection is going away"); } if (streamId < 0) { 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 f71f5dcd92..f839e6d039 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 @@ -169,7 +169,7 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder { void onGoAwayRead0(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { // Don't allow any more connections to be created. - connection.goAwayReceived(lastStreamId); + connection.goAwayReceived(lastStreamId, errorCode, debugData); listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoder.java index 3f908bcb2f..0f86aca84b 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoder.java @@ -112,7 +112,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { final boolean endOfStream, ChannelPromise promise) { final Http2Stream stream; try { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { throw new IllegalStateException("Sending data after connection going away."); } @@ -151,7 +151,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { final boolean exclusive, final int padding, final boolean endOfStream, final ChannelPromise promise) { try { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { throw connectionError(PROTOCOL_ERROR, "Sending headers after connection going away."); } Http2Stream stream = connection.stream(streamId); @@ -190,7 +190,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { public ChannelFuture writePriority(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive, ChannelPromise promise) { try { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { throw connectionError(PROTOCOL_ERROR, "Sending priority after connection going away."); } @@ -227,7 +227,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { ChannelPromise promise) { outstandingLocalSettingsQueue.add(settings); try { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { throw connectionError(PROTOCOL_ERROR, "Sending settings after connection going away."); } @@ -254,7 +254,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { @Override public ChannelFuture writePing(ChannelHandlerContext ctx, boolean ack, ByteBuf data, ChannelPromise promise) { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { data.release(); return promise.setFailure(connectionError(PROTOCOL_ERROR, "Sending ping after connection going away.")); } @@ -268,7 +268,7 @@ public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { public ChannelFuture writePushPromise(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding, ChannelPromise promise) { try { - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { throw connectionError(PROTOCOL_ERROR, "Sending push promise after connection going away."); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java index b4b1e18930..b1cb8e133b 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java @@ -64,12 +64,12 @@ public class DefaultHttp2LocalFlowController implements Http2LocalFlowController // Register for notification of new streams. connection.addListener(new Http2ConnectionAdapter() { @Override - public void streamAdded(Http2Stream stream) { + public void onStreamAdded(Http2Stream stream) { stream.setProperty(FlowState.class, new FlowState(stream, 0)); } @Override - public void streamActive(Http2Stream stream) { + public void onStreamActive(Http2Stream stream) { // Need to be sure the stream's initial window is adjusted for SETTINGS // frames which may have been exchanged while it was in IDLE state(stream).window(initialWindowSize); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java index 2c6a4b0045..12feeceb80 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java @@ -48,27 +48,27 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll // Register for notification of new streams. connection.addListener(new Http2ConnectionAdapter() { @Override - public void streamAdded(Http2Stream stream) { + public void onStreamAdded(Http2Stream stream) { // Just add a new flow state to the stream. stream.setProperty(FlowState.class, new FlowState(stream, 0)); } @Override - public void streamActive(Http2Stream stream) { + public void onStreamActive(Http2Stream stream) { // Need to be sure the stream's initial window is adjusted for SETTINGS // frames which may have been exchanged while it was in IDLE state(stream).window(initialWindowSize); } @Override - public void streamClosed(Http2Stream stream) { + public void onStreamClosed(Http2Stream stream) { // Any pending frames can never be written, cancel and // write errors for any pending frames. state(stream).cancel(); } @Override - public void streamHalfClosed(Http2Stream stream) { + public void onStreamHalfClosed(Http2Stream stream) { if (State.HALF_CLOSED_LOCAL.equals(stream.state())) { /** * When this method is called there should not be any @@ -86,7 +86,7 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll } @Override - public void priorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { + public void onPriorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { Http2Stream parent = stream.parent(); if (parent != null) { int delta = state(stream).streamableBytesForTree(); @@ -97,7 +97,7 @@ public class DefaultHttp2RemoteFlowController implements Http2RemoteFlowControll } @Override - public void priorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { + public void onPriorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { Http2Stream parent = stream.parent(); if (parent != null) { int delta = -state(stream).streamableBytesForTree(); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java index 060e327932..9cff863d5a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java @@ -40,7 +40,7 @@ import io.netty.handler.codec.compression.ZlibWrapper; public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecorator { private static final Http2ConnectionAdapter CLEAN_UP_LISTENER = new Http2ConnectionAdapter() { @Override - public void streamRemoved(Http2Stream stream) { + public void onStreamRemoved(Http2Stream stream) { final Http2Decompressor decompressor = decompressor(stream); if (decompressor != null) { cleanup(stream, decompressor); diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Connection.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Connection.java index 008fe84c7f..92f2848f81 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Connection.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2Connection.java @@ -15,6 +15,8 @@ package io.netty.handler.codec.http2; +import io.netty.buffer.ByteBuf; + import java.util.Collection; /** @@ -30,31 +32,31 @@ public interface Http2Connection { * Notifies the listener that the given stream was added to the connection. This stream may * not yet be active (i.e. {@code OPEN} or {@code HALF CLOSED}). */ - void streamAdded(Http2Stream stream); + void onStreamAdded(Http2Stream stream); /** * Notifies the listener that the given stream was made active (i.e. {@code OPEN} or {@code HALF CLOSED}). */ - void streamActive(Http2Stream stream); + void onStreamActive(Http2Stream stream); /** * Notifies the listener that the given stream is now {@code HALF CLOSED}. The stream can be * inspected to determine which side is {@code CLOSED}. */ - void streamHalfClosed(Http2Stream stream); + void onStreamHalfClosed(Http2Stream stream); /** * Notifies the listener that the given stream is now {@code CLOSED} in both directions and will no longer * be returned by {@link #activeStreams()}. */ - void streamClosed(Http2Stream stream); + void onStreamClosed(Http2Stream stream); /** * Notifies the listener that the given stream has now been removed from the connection and * will no longer be returned via {@link Http2Connection#stream(int)}. The connection may * maintain inactive streams for some time before removing them. */ - void streamRemoved(Http2Stream stream); + void onStreamRemoved(Http2Stream stream); /** * Notifies the listener that a priority tree parent change has occurred. This method will be invoked @@ -64,7 +66,7 @@ public interface Http2Connection { * @param stream The stream which had a parent change (new parent and children will be steady state) * @param oldParent The old parent which {@code stream} used to be a child of (may be {@code null}) */ - void priorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent); + void onPriorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent); /** * Notifies the listener that a parent dependency is about to change @@ -73,7 +75,7 @@ public interface Http2Connection { * @param stream The stream which the parent is about to change to {@code newParent} * @param newParent The stream which will be the parent of {@code stream} */ - void priorityTreeParentChanging(Http2Stream stream, Http2Stream newParent); + void onPriorityTreeParentChanging(Http2Stream stream, Http2Stream newParent); /** * Notifies the listener that the weight has changed for {@code stream} @@ -83,9 +85,26 @@ public interface Http2Connection { void onWeightChanged(Http2Stream stream, short oldWeight); /** - * Called when a GO_AWAY frame has either been sent or received for the connection. + * Called when a {@code GOAWAY} frame was sent for the connection. + * + * @param lastStreamId the last known stream of the remote endpoint. + * @param errorCode the error code, if abnormal closure. + * @param debugData application-defined debug data. */ - void goingAway(); + void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData); + + /** + * Called when a {@code GOAWAY} was received from the remote endpoint. This event handler duplicates {@link + * Http2FrameListener#onGoAwayRead(io.netty.channel.ChannelHandlerContext, int, long, io.netty.buffer.ByteBuf)} + * but is added here in order to simplify application logic for handling {@code GOAWAY} in a uniform way. An + * application should generally not handle both events, but if it does this method is called first, before + * notifying the {@link Http2FrameListener}. + * + * @param lastStreamId the last known stream of the remote endpoint. + * @param errorCode the error code, if abnormal closure. + * @param debugData application-defined debug data. + */ + void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData); } /** @@ -269,7 +288,7 @@ public interface Http2Connection { /** * Indicates that a {@code GOAWAY} was received from the remote endpoint and sets the last known stream. */ - void goAwayReceived(int lastKnownStream); + void goAwayReceived(int lastKnownStream, long errorCode, ByteBuf message); /** * Indicates whether or not a {@code GOAWAY} was sent to the remote endpoint. @@ -279,10 +298,5 @@ public interface Http2Connection { /** * Indicates that a {@code GOAWAY} was sent to the remote endpoint and sets the last known stream. */ - void goAwaySent(int lastKnownStream); - - /** - * Indicates whether or not either endpoint has received a GOAWAY. - */ - boolean isGoAway(); + void goAwaySent(int lastKnownStream, long errorCode, ByteBuf message); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionAdapter.java index b6b878d636..ae39ccbee0 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionAdapter.java @@ -14,41 +14,47 @@ */ package io.netty.handler.codec.http2; +import io.netty.buffer.ByteBuf; + /** * Provides empty implementations of all {@link Http2Connection.Listener} methods. */ public class Http2ConnectionAdapter implements Http2Connection.Listener { @Override - public void streamAdded(Http2Stream stream) { + public void onStreamAdded(Http2Stream stream) { } @Override - public void streamActive(Http2Stream stream) { + public void onStreamActive(Http2Stream stream) { } @Override - public void streamHalfClosed(Http2Stream stream) { + public void onStreamHalfClosed(Http2Stream stream) { } @Override - public void streamClosed(Http2Stream stream) { + public void onStreamClosed(Http2Stream stream) { } @Override - public void streamRemoved(Http2Stream stream) { + public void onStreamRemoved(Http2Stream stream) { } @Override - public void goingAway() { + public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) { } @Override - public void priorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { + public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { } @Override - public void priorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { + public void onPriorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { + } + + @Override + public void onPriorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { } @Override 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 46e6e01a30..67bd5a7783 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 @@ -526,15 +526,16 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http public ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData, ChannelPromise promise) { Http2Connection connection = connection(); - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { debugData.release(); return ctx.newSucceededFuture(); } + connection.goAwaySent(lastStreamId, errorCode, debugData); + ChannelFuture future = frameWriter().writeGoAway(ctx, lastStreamId, errorCode, debugData, promise); ctx.flush(); - connection.goAwaySent(lastStreamId); return future; } @@ -543,7 +544,7 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http */ private ChannelFuture writeGoAway(ChannelHandlerContext ctx, Http2Exception cause) { Http2Connection connection = connection(); - if (connection.isGoAway()) { + if (connection.goAwayReceived() || connection.goAwaySent()) { return ctx.newSucceededFuture(); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EventAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EventAdapter.java index 30a3f9a18a..9cbd6d0dba 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EventAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2EventAdapter.java @@ -84,31 +84,31 @@ public class Http2EventAdapter implements Http2Connection.Listener, Http2FrameLi } @Override - public void streamAdded(Http2Stream stream) { + public void onStreamAdded(Http2Stream stream) { } @Override - public void streamActive(Http2Stream stream) { + public void onStreamActive(Http2Stream stream) { } @Override - public void streamHalfClosed(Http2Stream stream) { + public void onStreamHalfClosed(Http2Stream stream) { } @Override - public void streamClosed(Http2Stream stream) { + public void onStreamClosed(Http2Stream stream) { } @Override - public void streamRemoved(Http2Stream stream) { + public void onStreamRemoved(Http2Stream stream) { } @Override - public void priorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { + public void onPriorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { } @Override - public void priorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { + public void onPriorityTreeParentChanging(Http2Stream stream, Http2Stream newParent) { } @Override @@ -116,6 +116,10 @@ public class Http2EventAdapter implements Http2Connection.Listener, Http2FrameLi } @Override - public void goingAway() { + public void onGoAwaySent(int lastStreamId, long errorCode, ByteBuf debugData) { + } + + @Override + public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java index 47f08a7c0f..2daef7d178 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpAdapter.java @@ -155,7 +155,7 @@ public class InboundHttp2ToHttpAdapter extends Http2EventAdapter { } @Override - public void streamRemoved(Http2Stream stream) { + public void onStreamRemoved(Http2Stream stream) { removeMessage(stream.id()); } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java index d36e3ad2c7..6b6ed9570a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/InboundHttp2ToHttpPriorityAdapter.java @@ -166,7 +166,7 @@ public final class InboundHttp2ToHttpPriorityAdapter extends InboundHttp2ToHttpA } @Override - public void priorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { + public void onPriorityTreeParentChanged(Http2Stream stream, Http2Stream oldParent) { Http2Stream parent = stream.parent(); FullHttpMessage msg = messageMap.get(stream.id()); if (msg == null) { 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 633ad61d1e..8e28fc2e58 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 @@ -271,7 +271,7 @@ public class DataCompressionHttp2Test { serverConnection.addListener(new Http2ConnectionAdapter() { @Override - public void streamHalfClosed(Http2Stream stream) { + public void onStreamHalfClosed(Http2Stream stream) { serverLatch.countDown(); } }); 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 5056c31bac..8231959714 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 @@ -491,7 +491,7 @@ public class DefaultHttp2ConnectionDecoderTest { @Test public void goAwayShouldReadShouldUpdateConnectionState() throws Exception { decode().onGoAwayRead(ctx, 1, 2L, EMPTY_BUFFER); - verify(connection).goAwayReceived(1); + verify(connection).goAwayReceived(eq(1), eq(2L), eq(EMPTY_BUFFER)); verify(listener).onGoAwayRead(eq(ctx), eq(1), eq(2L), eq(EMPTY_BUFFER)); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java index 3bcd70e0b9..7a40558c81 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionEncoderTest.java @@ -201,7 +201,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void dataWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); final ByteBuf data = dummyData(); try { ChannelFuture future = encoder.writeData(ctx, STREAM_ID, data, 0, true, promise); @@ -304,7 +304,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void headersWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); ChannelFuture future = encoder.writeHeaders( ctx, 5, EmptyHttp2Headers.INSTANCE, 0, (short) 255, false, 0, false, promise); verify(local, never()).createStream(anyInt()); @@ -345,7 +345,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void pushPromiseWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); ChannelFuture future = encoder.writePushPromise(ctx, STREAM_ID, PUSH_STREAM_ID, EmptyHttp2Headers.INSTANCE, 0, promise); @@ -362,7 +362,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void priorityWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); ChannelFuture future = encoder.writePriority(ctx, STREAM_ID, 0, (short) 255, true, promise); assertTrue(future.awaitUninterruptibly().cause() instanceof Http2Exception); } @@ -426,7 +426,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void pingWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); ChannelFuture future = encoder.writePing(ctx, false, emptyPingBuf(), promise); assertTrue(future.awaitUninterruptibly().cause() instanceof Http2Exception); } @@ -439,7 +439,7 @@ public class DefaultHttp2ConnectionEncoderTest { @Test public void settingsWriteAfterGoAwayShouldFail() throws Exception { - when(connection.isGoAway()).thenReturn(true); + when(connection.goAwayReceived()).thenReturn(true); ChannelFuture future = encoder.writeSettings(ctx, new Http2Settings(), promise); assertTrue(future.awaitUninterruptibly().cause() instanceof Http2Exception); } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java index 18e0ba9881..6fe7c5a28f 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java @@ -30,6 +30,8 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; + +import io.netty.buffer.Unpooled; import io.netty.handler.codec.http2.Http2Connection.Endpoint; import io.netty.handler.codec.http2.Http2Stream.State; @@ -176,7 +178,7 @@ public class DefaultHttp2ConnectionTest { @Test(expected = Http2Exception.class) public void goAwayReceivedShouldDisallowCreation() throws Http2Exception { - server.goAwayReceived(0); + server.goAwayReceived(0, 1L, Unpooled.EMPTY_BUFFER); server.remote().createStream(3).open(true); } @@ -321,10 +323,10 @@ public class DefaultHttp2ConnectionTest { streamD.setPriority(streamD.parent().id(), newWeight, false); verify(clientListener).onWeightChanged(eq(streamD), eq(oldWeight)); assertEquals(streamD.weight(), newWeight); - verify(clientListener, never()).priorityTreeParentChanging(any(Http2Stream.class), - any(Http2Stream.class)); - verify(clientListener, never()).priorityTreeParentChanged(any(Http2Stream.class), - any(Http2Stream.class)); + verify(clientListener, never()).onPriorityTreeParentChanging(any(Http2Stream.class), + any(Http2Stream.class)); + verify(clientListener, never()).onPriorityTreeParentChanged(any(Http2Stream.class), + any(Http2Stream.class)); } @Test @@ -552,8 +554,8 @@ public class DefaultHttp2ConnectionTest { assertSame(expectedArg1.size(), expectedArg2.size()); ArgumentCaptor arg1Captor = ArgumentCaptor.forClass(Http2Stream.class); ArgumentCaptor arg2Captor = ArgumentCaptor.forClass(Http2Stream.class); - verify(clientListener, times(expectedArg1.size())).priorityTreeParentChanging(arg1Captor.capture(), - arg2Captor.capture()); + verify(clientListener, times(expectedArg1.size())).onPriorityTreeParentChanging(arg1Captor.capture(), + arg2Captor.capture()); List capturedArg1 = arg1Captor.getAllValues(); List capturedArg2 = arg2Captor.getAllValues(); assertSame(capturedArg1.size(), capturedArg2.size()); @@ -568,8 +570,8 @@ public class DefaultHttp2ConnectionTest { assertSame(expectedArg1.size(), expectedArg2.size()); ArgumentCaptor arg1Captor = ArgumentCaptor.forClass(Http2Stream.class); ArgumentCaptor arg2Captor = ArgumentCaptor.forClass(Http2Stream.class); - verify(clientListener, times(expectedArg1.size())).priorityTreeParentChanged(arg1Captor.capture(), - arg2Captor.capture()); + verify(clientListener, times(expectedArg1.size())).onPriorityTreeParentChanged(arg1Captor.capture(), + arg2Captor.capture()); List capturedArg1 = arg1Captor.getAllValues(); List capturedArg2 = arg2Captor.getAllValues(); assertSame(capturedArg1.size(), capturedArg2.size()); @@ -597,10 +599,10 @@ public class DefaultHttp2ConnectionTest { } private void verifyParentChanging(Http2Stream stream, Http2Stream newParent) { - verify(clientListener).priorityTreeParentChanging(streamEq(stream), streamEq(newParent)); + verify(clientListener).onPriorityTreeParentChanging(streamEq(stream), streamEq(newParent)); } private void verifyParentChanged(Http2Stream stream, Http2Stream oldParent) { - verify(clientListener).priorityTreeParentChanged(streamEq(stream), streamEq(oldParent)); + verify(clientListener).onPriorityTreeParentChanged(streamEq(stream), streamEq(oldParent)); } }