Use j.u.Consumer interface instead of bespoke copy (#10520)
Motivation: Fix a TODO that was due since the "master" branch is baselined on at least Java 8. Modification: Remove our own copy of the Consumer interface and fix usage sites to use j.u.Consumer. Also some cleanup. Result: Cleaner code.
This commit is contained in:
parent
571e61ab36
commit
0fd525f859
@ -27,7 +27,6 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
import io.netty.handler.codec.http.HttpScheme;
|
import io.netty.handler.codec.http.HttpScheme;
|
||||||
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
import io.netty.handler.codec.http2.Http2Exception.StreamException;
|
||||||
import io.netty.handler.codec.http2.LastInboundHandler.Consumer;
|
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
@ -47,6 +46,7 @@ import java.util.concurrent.CompletionException;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise;
|
import static io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise;
|
||||||
import static io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings;
|
import static io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings;
|
||||||
@ -203,8 +203,8 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
|
|
||||||
assertEquals(headersFrame, inboundHandler.readInbound());
|
assertEquals(headersFrame, inboundHandler.readInbound());
|
||||||
|
|
||||||
assertEqualsAndRelease(dataFrame1, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame1, inboundHandler.readInbound());
|
||||||
assertEqualsAndRelease(dataFrame2, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame2, inboundHandler.readInbound());
|
||||||
|
|
||||||
assertNull(inboundHandler.readInbound());
|
assertNull(inboundHandler.readInbound());
|
||||||
}
|
}
|
||||||
@ -463,7 +463,7 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
assertFalse(inboundHandler.isChannelActive());
|
assertFalse(inboundHandler.isChannelActive());
|
||||||
|
|
||||||
// A RST_STREAM frame should NOT be emitted, as we received a RST_STREAM.
|
// A RST_STREAM frame should NOT be emitted, as we received a RST_STREAM.
|
||||||
verify(frameWriter, Mockito.never()).writeRstStream(any(ChannelHandlerContext.class), eqStreamId(channel),
|
verify(frameWriter, never()).writeRstStream(any(ChannelHandlerContext.class), eqStreamId(channel),
|
||||||
anyLong(), anyChannelPromise());
|
anyLong(), anyChannelPromise());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -885,8 +885,8 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
assertEqualsAndRelease(dataFrame3, inboundHandler.<Http2DataFrame>readInbound());
|
assertEqualsAndRelease(dataFrame3, inboundHandler.<Http2DataFrame>readInbound());
|
||||||
assertEqualsAndRelease(dataFrame4, inboundHandler.<Http2DataFrame>readInbound());
|
assertEqualsAndRelease(dataFrame4, inboundHandler.<Http2DataFrame>readInbound());
|
||||||
|
|
||||||
Http2ResetFrame resetFrame = useUserEventForResetFrame() ? inboundHandler.<Http2ResetFrame>readUserEvent() :
|
Http2ResetFrame resetFrame = useUserEventForResetFrame() ? inboundHandler.readUserEvent() :
|
||||||
inboundHandler.<Http2ResetFrame>readInbound();
|
inboundHandler.readInbound();
|
||||||
|
|
||||||
assertEquals(childChannel.stream(), resetFrame.stream());
|
assertEquals(childChannel.stream(), resetFrame.stream());
|
||||||
assertEquals(Http2Error.NO_ERROR.code(), resetFrame.errorCode());
|
assertEquals(Http2Error.NO_ERROR.code(), resetFrame.errorCode());
|
||||||
@ -1019,7 +1019,7 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
|
|
||||||
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("1"), 0, false);
|
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("1"), 0, false);
|
||||||
|
|
||||||
assertEqualsAndRelease(dataFrame1, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame1, inboundHandler.readInbound());
|
||||||
|
|
||||||
// We want one item to be in the queue, and allow the numReads to be larger than 1. This will ensure that
|
// We want one item to be in the queue, and allow the numReads to be larger than 1. This will ensure that
|
||||||
// when beginRead() is called the child channel is added to the readPending queue of the parent channel.
|
// when beginRead() is called the child channel is added to the readPending queue of the parent channel.
|
||||||
@ -1028,7 +1028,7 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
numReads.set(2);
|
numReads.set(2);
|
||||||
childChannel.read();
|
childChannel.read();
|
||||||
|
|
||||||
assertEqualsAndRelease(dataFrame2, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame2, inboundHandler.readInbound());
|
||||||
|
|
||||||
assertNull(inboundHandler.readInbound());
|
assertNull(inboundHandler.readInbound());
|
||||||
|
|
||||||
@ -1036,14 +1036,14 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
|||||||
// notify of readComplete().
|
// notify of readComplete().
|
||||||
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("3"), 0, false);
|
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("3"), 0, false);
|
||||||
|
|
||||||
assertEqualsAndRelease(dataFrame3, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame3, inboundHandler.readInbound());
|
||||||
|
|
||||||
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("4"), 0, false);
|
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("4"), 0, false);
|
||||||
assertNull(inboundHandler.readInbound());
|
assertNull(inboundHandler.readInbound());
|
||||||
|
|
||||||
childChannel.read();
|
childChannel.read();
|
||||||
|
|
||||||
assertEqualsAndRelease(dataFrame4, inboundHandler.<Http2Frame>readInbound());
|
assertEqualsAndRelease(dataFrame4, inboundHandler.readInbound());
|
||||||
|
|
||||||
assertNull(inboundHandler.readInbound());
|
assertNull(inboundHandler.readInbound());
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import io.netty.util.internal.PlatformDependent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
import java.util.concurrent.locks.LockSupport;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
@ -41,11 +42,6 @@ public class LastInboundHandler implements ChannelHandler {
|
|||||||
private boolean channelActive;
|
private boolean channelActive;
|
||||||
private String writabilityStates = "";
|
private String writabilityStates = "";
|
||||||
|
|
||||||
// TODO(scott): use JDK 8's Consumer
|
|
||||||
public interface Consumer<T> {
|
|
||||||
void accept(T obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Consumer<Object> NOOP_CONSUMER = obj -> {
|
private static final Consumer<Object> NOOP_CONSUMER = obj -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,7 +51,7 @@ public class LastInboundHandler implements ChannelHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LastInboundHandler() {
|
public LastInboundHandler() {
|
||||||
this(LastInboundHandler.noopConsumer());
|
this(noopConsumer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public LastInboundHandler(Consumer<ChannelHandlerContext> channelReadCompleteConsumer) {
|
public LastInboundHandler(Consumer<ChannelHandlerContext> channelReadCompleteConsumer) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user