Use lambdas whenever possible (#9979)

Motivation:

We should update our code to use lamdas whenever possible

Modifications:

Use lambdas when possible

Result:

Cleanup code for Java8
This commit is contained in:
Norman Maurer 2020-01-30 09:28:24 +01:00 committed by GitHub
parent 6b6782ea01
commit 6a43807843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 283 additions and 643 deletions

View File

@ -22,7 +22,6 @@ import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.internal.MathUtil;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil;
@ -1173,12 +1172,7 @@ public final class ByteBufUtil {
static final class ThreadLocalUnsafeDirectByteBuf extends UnpooledUnsafeDirectByteBuf {
private static final ObjectPool<ThreadLocalUnsafeDirectByteBuf> RECYCLER =
ObjectPool.newPool(new ObjectCreator<ThreadLocalUnsafeDirectByteBuf>() {
@Override
public ThreadLocalUnsafeDirectByteBuf newObject(Handle<ThreadLocalUnsafeDirectByteBuf> handle) {
return new ThreadLocalUnsafeDirectByteBuf(handle);
}
});
ObjectPool.newPool(ThreadLocalUnsafeDirectByteBuf::new);
static ThreadLocalUnsafeDirectByteBuf newInstance() {
ThreadLocalUnsafeDirectByteBuf buf = RECYCLER.get();
@ -1207,12 +1201,7 @@ public final class ByteBufUtil {
static final class ThreadLocalDirectByteBuf extends UnpooledDirectByteBuf {
private static final ObjectPool<ThreadLocalDirectByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<ThreadLocalDirectByteBuf>() {
@Override
public ThreadLocalDirectByteBuf newObject(Handle<ThreadLocalDirectByteBuf> handle) {
return new ThreadLocalDirectByteBuf(handle);
}
});
ThreadLocalDirectByteBuf::new);
static ThreadLocalDirectByteBuf newInstance() {
ThreadLocalDirectByteBuf buf = RECYCLER.get();

View File

@ -23,7 +23,6 @@ import io.netty.buffer.PoolArena.SizeClass;
import io.netty.util.internal.MathUtil;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -493,12 +492,6 @@ final class PoolThreadCache {
}
@SuppressWarnings("rawtypes")
private static final ObjectPool<Entry> RECYCLER = ObjectPool.newPool(new ObjectCreator<Entry>() {
@SuppressWarnings("unchecked")
@Override
public Entry newObject(Handle<Entry> handle) {
return new Entry(handle);
}
});
private static final ObjectPool<Entry> RECYCLER = ObjectPool.newPool(handle -> new Entry(handle));
}
}

View File

@ -18,7 +18,6 @@ package io.netty.buffer;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import java.io.IOException;
import java.io.InputStream;
@ -28,12 +27,7 @@ import java.nio.ByteBuffer;
final class PooledDirectByteBuf extends PooledByteBuf<ByteBuffer> {
private static final ObjectPool<PooledDirectByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledDirectByteBuf>() {
@Override
public PooledDirectByteBuf newObject(Handle<PooledDirectByteBuf> handle) {
return new PooledDirectByteBuf(handle, 0);
}
});
handle -> new PooledDirectByteBuf(handle, 0));
static PooledDirectByteBuf newInstance(int maxCapacity) {
PooledDirectByteBuf buf = RECYCLER.get();

View File

@ -19,7 +19,6 @@ package io.netty.buffer;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import java.io.IOException;
import java.io.InputStream;
@ -31,13 +30,8 @@ import java.nio.channels.ScatteringByteChannel;
final class PooledDuplicatedByteBuf extends AbstractPooledDerivedByteBuf {
private static final ObjectPool<PooledDuplicatedByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledDuplicatedByteBuf>() {
@Override
public PooledDuplicatedByteBuf newObject(Handle<PooledDuplicatedByteBuf> handle) {
return new PooledDuplicatedByteBuf(handle);
}
});
private static final ObjectPool<PooledDuplicatedByteBuf> RECYCLER =
ObjectPool.newPool(PooledDuplicatedByteBuf::new);
static PooledDuplicatedByteBuf newInstance(AbstractByteBuf unwrapped, ByteBuf wrapped,
int readerIndex, int writerIndex) {

View File

@ -27,12 +27,7 @@ import java.nio.ByteBuffer;
class PooledHeapByteBuf extends PooledByteBuf<byte[]> {
private static final ObjectPool<PooledHeapByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledHeapByteBuf>() {
@Override
public PooledHeapByteBuf newObject(Handle<PooledHeapByteBuf> handle) {
return new PooledHeapByteBuf(handle, 0);
}
});
handle -> new PooledHeapByteBuf(handle, 0));
static PooledHeapByteBuf newInstance(int maxCapacity) {
PooledHeapByteBuf buf = RECYCLER.get();

View File

@ -19,7 +19,6 @@ package io.netty.buffer;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import java.io.IOException;
import java.io.InputStream;
@ -33,13 +32,7 @@ import static io.netty.buffer.AbstractUnpooledSlicedByteBuf.checkSliceOutOfBound
final class PooledSlicedByteBuf extends AbstractPooledDerivedByteBuf {
private static final ObjectPool<PooledSlicedByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledSlicedByteBuf>() {
@Override
public PooledSlicedByteBuf newObject(Handle<PooledSlicedByteBuf> handle) {
return new PooledSlicedByteBuf(handle);
}
});
private static final ObjectPool<PooledSlicedByteBuf> RECYCLER = ObjectPool.newPool(PooledSlicedByteBuf::new);
static PooledSlicedByteBuf newInstance(AbstractByteBuf unwrapped, ByteBuf wrapped,
int index, int length) {

View File

@ -28,12 +28,7 @@ import java.nio.ByteBuffer;
final class PooledUnsafeDirectByteBuf extends PooledByteBuf<ByteBuffer> {
private static final ObjectPool<PooledUnsafeDirectByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledUnsafeDirectByteBuf>() {
@Override
public PooledUnsafeDirectByteBuf newObject(Handle<PooledUnsafeDirectByteBuf> handle) {
return new PooledUnsafeDirectByteBuf(handle, 0);
}
});
handle -> new PooledUnsafeDirectByteBuf(handle, 0));
static PooledUnsafeDirectByteBuf newInstance(int maxCapacity) {
PooledUnsafeDirectByteBuf buf = RECYCLER.get();

View File

@ -17,18 +17,12 @@ package io.netty.buffer;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.PlatformDependent;
final class PooledUnsafeHeapByteBuf extends PooledHeapByteBuf {
private static final ObjectPool<PooledUnsafeHeapByteBuf> RECYCLER = ObjectPool.newPool(
new ObjectCreator<PooledUnsafeHeapByteBuf>() {
@Override
public PooledUnsafeHeapByteBuf newObject(Handle<PooledUnsafeHeapByteBuf> handle) {
return new PooledUnsafeHeapByteBuf(handle, 0);
}
});
handle -> new PooledUnsafeHeapByteBuf(handle, 0));
static PooledUnsafeHeapByteBuf newUnsafeInstance(int maxCapacity) {
PooledUnsafeHeapByteBuf buf = RECYCLER.get();

View File

@ -585,34 +585,19 @@ public class ByteBufUtilTest {
@Test
public void testWriteUtf8InvalidSubsequences() {
testInvalidSubsequences(new TestMethod() {
@Override
public int invoke(Object... args) {
return ByteBufUtil.writeUtf8((ByteBuf) args[0], (String) args[1],
(Integer) args[2], (Integer) args[3]);
}
});
testInvalidSubsequences(args -> ByteBufUtil.writeUtf8((ByteBuf) args[0], (String) args[1],
(Integer) args[2], (Integer) args[3]));
}
@Test
public void testReserveAndWriteUtf8InvalidSubsequences() {
testInvalidSubsequences(new TestMethod() {
@Override
public int invoke(Object... args) {
return ByteBufUtil.reserveAndWriteUtf8((ByteBuf) args[0], (String) args[1],
(Integer) args[2], (Integer) args[3], 32);
}
});
testInvalidSubsequences(args -> ByteBufUtil.reserveAndWriteUtf8((ByteBuf) args[0], (String) args[1],
(Integer) args[2], (Integer) args[3], 32));
}
@Test
public void testUtf8BytesInvalidSubsequences() {
testInvalidSubsequences(new TestMethod() {
@Override
public int invoke(Object... args) {
return ByteBufUtil.utf8Bytes((String) args[1], (Integer) args[2], (Integer) args[3]);
}
});
testInvalidSubsequences(args -> ByteBufUtil.utf8Bytes((String) args[1], (Integer) args[2], (Integer) args[3]));
}
@Test

View File

@ -15,7 +15,6 @@
*/
package io.netty.buffer;
import io.netty.util.ByteProcessor;
import io.netty.util.ResourceLeakTracker;
import org.hamcrest.CoreMatchers;
import org.junit.After;
@ -146,12 +145,7 @@ public class SimpleLeakAwareCompositeByteBufTest extends WrappedCompositeByteBuf
comp.addComponent(true, inner);
buf.addComponent(true, comp);
assertEquals(-1, buf.forEachByte(new ByteProcessor() {
@Override
public boolean process(byte value) {
return true;
}
}));
assertEquals(-1, buf.forEachByte(value -> true));
assertTrue(buf.release());
}

View File

@ -97,9 +97,7 @@ class WebSocketClientProtocolHandshakeHandler implements ChannelHandler {
return;
}
final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
final Future<?> timeoutFuture = ctx.executor().schedule(() -> {
if (localHandshakePromise.isDone()) {
return;
}
@ -109,16 +107,10 @@ class WebSocketClientProtocolHandshakeHandler implements ChannelHandler {
.fireUserEventTriggered(ClientHandshakeStateEvent.HANDSHAKE_TIMEOUT)
.close();
}
}
}, handshakeTimeoutMillis, TimeUnit.MILLISECONDS);
// Cancel the handshake timeout when handshake is finished.
localHandshakePromise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> f) throws Exception {
timeoutFuture.cancel(false);
}
});
localHandshakePromise.addListener((FutureListener<Void>) f -> timeoutFuture.cancel(false));
}
/**

View File

@ -51,12 +51,7 @@ final class WebSocketCloseFrameHandler implements ChannelHandler {
}
flush(ctx);
applyCloseSentTimeout(ctx);
closeSent.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
ctx.close(promise);
}
});
closeSent.addListener((ChannelFutureListener) future -> ctx.close(promise));
}
@Override
@ -78,20 +73,12 @@ final class WebSocketCloseFrameHandler implements ChannelHandler {
return;
}
final ScheduledFuture<?> timeoutTask = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
final ScheduledFuture<?> timeoutTask = ctx.executor().schedule(() -> {
if (!closeSent.isDone()) {
closeSent.tryFailure(new WebSocketHandshakeException("send close frame timed out"));
}
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);
closeSent.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
timeoutTask.cancel(false);
}
});
closeSent.addListener((ChannelFutureListener) future -> timeoutTask.cancel(false));
}
}

View File

@ -139,24 +139,16 @@ class WebSocketServerProtocolHandshakeHandler implements ChannelHandler {
return;
}
final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
final Future<?> timeoutFuture = ctx.executor().schedule(() -> {
if (!localHandshakePromise.isDone() &&
localHandshakePromise.tryFailure(new WebSocketHandshakeException("handshake timed out"))) {
ctx.flush()
.fireUserEventTriggered(ServerHandshakeStateEvent.HANDSHAKE_TIMEOUT)
.close();
}
}
}, handshakeTimeoutMillis, TimeUnit.MILLISECONDS);
// Cancel the handshake timeout when handshake is finished.
localHandshakePromise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> f) {
timeoutFuture.cancel(false);
}
});
localHandshakePromise.addListener((FutureListener<Void>) f -> timeoutFuture.cancel(false));
}
}

View File

@ -27,23 +27,13 @@ public interface WebSocketExtensionFilter {
* A {@link WebSocketExtensionFilter} that never skip the evaluation of an
* any given extensions {@link WebSocketExtension}.
*/
WebSocketExtensionFilter NEVER_SKIP = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return false;
}
};
WebSocketExtensionFilter NEVER_SKIP = frame -> false;
/**
* A {@link WebSocketExtensionFilter} that always skip the evaluation of an
* any given extensions {@link WebSocketExtension}.
*/
WebSocketExtensionFilter ALWAYS_SKIP = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return true;
}
};
WebSocketExtensionFilter ALWAYS_SKIP = frame -> true;
/**
* Returns {@code true} if the evaluation of the extension must skipped

View File

@ -204,12 +204,7 @@ public class WebSocketHandshakeHandOverTest {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt == ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
ctx.channel().closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
clientForceClosed = true;
}
});
ctx.channel().closeFuture().addListener((ChannelFutureListener) future -> clientForceClosed = true);
handshaker.close(ctx.channel(), new CloseWebSocketFrame());
}
}

View File

@ -221,12 +221,8 @@ public class PerMessageDeflateDecoderTest {
@Test
public void testSelectivityDecompressionSkip() {
WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame instanceof TextWebSocketFrame && frame.content().readableBytes() < 100;
}
};
WebSocketExtensionFilter selectivityDecompressionFilter =
frame -> frame instanceof TextWebSocketFrame && frame.content().readableBytes() < 100;
EmbeddedChannel encoderChannel = new EmbeddedChannel(
ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
EmbeddedChannel decoderChannel = new EmbeddedChannel(
@ -266,12 +262,7 @@ public class PerMessageDeflateDecoderTest {
@Test(expected = DecoderException.class)
public void testIllegalStateWhenDecompressionInProgress() {
WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame.content().readableBytes() < 100;
}
};
WebSocketExtensionFilter selectivityDecompressionFilter = frame -> frame.content().readableBytes() < 100;
EmbeddedChannel encoderChannel = new EmbeddedChannel(
ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));

View File

@ -190,13 +190,9 @@ public class PerMessageDeflateEncoderTest {
@Test
public void testSelectivityCompressionSkip() {
WebSocketExtensionFilter selectivityCompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return (frame instanceof TextWebSocketFrame || frame instanceof BinaryWebSocketFrame)
WebSocketExtensionFilter selectivityCompressionFilter =
frame -> (frame instanceof TextWebSocketFrame || frame instanceof BinaryWebSocketFrame)
&& frame.content().readableBytes() < 100;
}
};
EmbeddedChannel encoderChannel = new EmbeddedChannel(
new PerMessageDeflateEncoder(9, 15, false, selectivityCompressionFilter));
EmbeddedChannel decoderChannel = new EmbeddedChannel(
@ -238,12 +234,7 @@ public class PerMessageDeflateEncoderTest {
@Test(expected = EncoderException.class)
public void testIllegalStateWhenCompressionInProgress() {
WebSocketExtensionFilter selectivityCompressionFilter = new WebSocketExtensionFilter() {
@Override
public boolean mustSkip(WebSocketFrame frame) {
return frame.content().readableBytes() < 100;
}
};
WebSocketExtensionFilter selectivityCompressionFilter = frame -> frame.content().readableBytes() < 100;
EmbeddedChannel encoderChannel = new EmbeddedChannel(
new PerMessageDeflateEncoder(9, 15, false, selectivityCompressionFilter));

View File

@ -114,12 +114,8 @@ abstract class AbstractHttp2StreamChannel extends DefaultAttributeMap implements
}
}
private final ChannelFutureListener windowUpdateFrameWriteListener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
private final ChannelFutureListener windowUpdateFrameWriteListener = future ->
windowUpdateFrameWriteComplete(future, AbstractHttp2StreamChannel.this);
}
};
/**
* The current status of the read-processing for a {@link AbstractHttp2StreamChannel}.

View File

@ -497,14 +497,11 @@ public class Http2ConnectionHandler extends ByteToMessageDecoder implements Http
closeListener = listener;
} else if (promise != null) {
final ChannelFutureListener oldCloseListener = closeListener;
closeListener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
closeListener = future1 -> {
try {
oldCloseListener.operationComplete(future);
oldCloseListener.operationComplete(future1);
} finally {
listener.operationComplete(future);
}
listener.operationComplete(future1);
}
};
}

View File

@ -249,12 +249,7 @@ public class Http2FrameCodec extends Http2ConnectionHandler {
// We schedule this on the EventExecutor to allow to have any extra handlers added to the pipeline
// before we pass the event to the next handler. This is needed as the event may be called from within
// handlerAdded(...) which will be run before other handlers will be added to the pipeline.
ctx.executor().execute(new Runnable() {
@Override
public void run() {
ctx.fireUserEventTriggered(evt);
}
});
ctx.executor().execute(() -> ctx.fireUserEventTriggered(evt));
} else if (evt instanceof UpgradeEvent) {
UpgradeEvent upgrade = (UpgradeEvent) evt;
try {

View File

@ -27,7 +27,6 @@ import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.eq;
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 static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@ -43,7 +42,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
@ -81,12 +79,7 @@ public class DefaultHttp2LocalFlowControllerTest {
reset(ctx);
when(ctx.newPromise()).thenReturn(promise);
if (allowFlush) {
when(ctx.flush()).then(new Answer<ChannelHandlerContext>() {
@Override
public ChannelHandlerContext answer(InvocationOnMock invocationOnMock) {
return ctx;
}
});
when(ctx.flush()).then((Answer<ChannelHandlerContext>) invocationOnMock -> ctx);
} else {
when(ctx.flush()).thenThrow(new AssertionFailedError("forbidden"));
}

View File

@ -41,7 +41,6 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.util.concurrent.CountDownLatch;
@ -743,38 +742,23 @@ public class Http2ConnectionHandlerTest {
when(stream.id()).thenReturn(STREAM_ID);
final AtomicBoolean resetSent = new AtomicBoolean();
when(stream.resetSent()).then(new Answer<Http2Stream>() {
@Override
public Http2Stream answer(InvocationOnMock invocationOnMock) {
when(stream.resetSent()).then((Answer<Http2Stream>) invocationOnMock -> {
resetSent.set(true);
return stream;
}
});
when(stream.isResetSent()).then(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocationOnMock) {
return resetSent.get();
}
});
when(stream.isResetSent()).then((Answer<Boolean>) invocationOnMock -> resetSent.get());
when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class)))
.then(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
.then((Answer<ChannelFuture>) invocationOnMock -> {
ChannelPromise promise = invocationOnMock.getArgument(3);
return promise.setSuccess();
}
});
ChannelPromise promise =
new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
final ChannelPromise promise2 =
new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
handler.resetStream(ctx, STREAM_ID, STREAM_CLOSED.code(), promise2);
}
});
promise.addListener((ChannelFutureListener) future ->
handler.resetStream(ctx, STREAM_ID, STREAM_CLOSED.code(), promise2));
handler.resetStream(ctx, STREAM_ID, CANCEL.code(), promise);
verify(frameWriter).writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class));

View File

@ -25,7 +25,6 @@ import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelPromise;
import io.netty.channel.DefaultChannelPromise;
import io.netty.channel.DefaultMessageSizeEstimator;
import io.netty.handler.codec.http2.Http2Exception.ShutdownHint;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.ImmediateEventExecutor;
@ -92,39 +91,23 @@ public class Http2ControlFrameLimitEncoderTest {
when(frameSizePolicy.maxFrameSize()).thenReturn(DEFAULT_MAX_FRAME_SIZE);
when(writer.writeRstStream(eq(ctx), anyInt(), anyLong(), any(ChannelPromise.class)))
.thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) {
return handlePromise(invocationOnMock, 3);
}
});
.thenAnswer((Answer<ChannelFuture>) invocationOnMock -> handlePromise(invocationOnMock, 3));
when(writer.writeSettingsAck(any(ChannelHandlerContext.class), any(ChannelPromise.class)))
.thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) {
return handlePromise(invocationOnMock, 1);
}
});
.thenAnswer((Answer<ChannelFuture>) invocationOnMock -> handlePromise(invocationOnMock, 1));
when(writer.writePing(any(ChannelHandlerContext.class), anyBoolean(), anyLong(), any(ChannelPromise.class)))
.thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) {
.thenAnswer((Answer<ChannelFuture>) invocationOnMock -> {
ChannelPromise promise = handlePromise(invocationOnMock, 3);
if (invocationOnMock.getArgument(1) == Boolean.FALSE) {
promise.trySuccess();
}
return promise;
}
});
when(writer.writeGoAway(any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class),
any(ChannelPromise.class))).thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) {
any(ChannelPromise.class))).thenAnswer((Answer<ChannelFuture>) invocationOnMock -> {
ReferenceCountUtil.release(invocationOnMock.getArgument(3));
ChannelPromise promise = invocationOnMock.getArgument(4);
goAwayPromises.offer(promise);
return promise;
}
});
Http2Connection connection = new DefaultHttp2Connection(false);
connection.remote().flowController(new DefaultHttp2RemoteFlowController(connection));
@ -144,12 +127,7 @@ public class Http2ControlFrameLimitEncoderTest {
when(ctx.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
when(channel.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
when(executor.inEventLoop()).thenReturn(true);
doAnswer(new Answer<ChannelPromise>() {
@Override
public ChannelPromise answer(InvocationOnMock invocation) throws Throwable {
return newPromise();
}
}).when(ctx).newPromise();
doAnswer((Answer<ChannelPromise>) invocation -> newPromise()).when(ctx).newPromise();
when(ctx.executor()).thenReturn(executor);
when(channel.isActive()).thenReturn(false);
when(channel.config()).thenReturn(config);

View File

@ -17,7 +17,6 @@ package io.netty.handler.codec.http2;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.junit.Assert.assertNull;
@ -33,12 +32,8 @@ public class Http2EmptyDataFrameConnectionDecoderTest {
Http2ConnectionDecoder delegate = mock(Http2ConnectionDecoder.class);
final ArgumentCaptor<Http2FrameListener> listenerArgumentCaptor =
ArgumentCaptor.forClass(Http2FrameListener.class);
when(delegate.frameListener()).then(new Answer<Http2FrameListener>() {
@Override
public Http2FrameListener answer(InvocationOnMock invocationOnMock) {
return listenerArgumentCaptor.getValue();
}
});
when(delegate.frameListener()).then(
(Answer<Http2FrameListener>) invocationOnMock -> listenerArgumentCaptor.getValue());
Http2FrameListener listener = mock(Http2FrameListener.class);
Http2EmptyDataFrameConnectionDecoder decoder = new Http2EmptyDataFrameConnectionDecoder(delegate, 2);
decoder.frameListener(listener);

View File

@ -20,8 +20,6 @@ import io.netty.util.concurrent.FastThreadLocalThread;
import reactor.blockhound.BlockHound;
import reactor.blockhound.integration.BlockHoundIntegration;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* Contains classes that must be have public visibility but are not public API.
@ -64,18 +62,8 @@ class Hidden {
"confirmShutdown"
);
builder.nonBlockingThreadPredicate(new Function<Predicate<Thread>, Predicate<Thread>>() {
@Override
public Predicate<Thread> apply(final Predicate<Thread> p) {
return new Predicate<Thread>() {
@Override
@SuppressJava6Requirement(reason = "Predicate#test")
public boolean test(Thread thread) {
return p.test(thread) || thread instanceof FastThreadLocalThread;
}
};
}
});
builder.nonBlockingThreadPredicate(p -> thread ->
p.test(thread) || thread instanceof FastThreadLocalThread);
}
}
}

View File

@ -18,18 +18,12 @@ package io.netty.util.internal;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.Promise;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
/**
* Some pending write which should be picked up later.
*/
public final class PendingWrite {
private static final ObjectPool<PendingWrite> RECYCLER = ObjectPool.newPool(new ObjectCreator<PendingWrite>() {
@Override
public PendingWrite newObject(Handle<PendingWrite> handle) {
return new PendingWrite(handle);
}
});
private static final ObjectPool<PendingWrite> RECYCLER = ObjectPool.newPool(PendingWrite::new);
/**
* Create a new empty {@link RecyclableArrayList} instance

View File

@ -19,7 +19,6 @@ package io.netty.util.internal;
import static java.util.Objects.requireNonNull;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import java.util.ArrayList;
import java.util.Collection;
@ -35,13 +34,7 @@ public final class RecyclableArrayList extends ArrayList<Object> {
private static final int DEFAULT_INITIAL_CAPACITY = 8;
private static final ObjectPool<RecyclableArrayList> RECYCLER = ObjectPool.newPool(
new ObjectCreator<RecyclableArrayList>() {
@Override
public RecyclableArrayList newObject(Handle<RecyclableArrayList> handle) {
return new RecyclableArrayList(handle);
}
});
private static final ObjectPool<RecyclableArrayList> RECYCLER = ObjectPool.newPool(RecyclableArrayList::new);
private boolean insertSinceRecycled;

View File

@ -52,12 +52,7 @@ public final class ThreadExecutorMap {
public static Executor apply(final Executor executor, final EventExecutor eventExecutor) {
Objects.requireNonNull(executor, "executor");
Objects.requireNonNull(eventExecutor, "eventExecutor");
return new Executor() {
@Override
public void execute(final Runnable command) {
executor.execute(apply(command, eventExecutor));
}
};
return command -> executor.execute(apply(command, eventExecutor));
}
/**
@ -67,16 +62,13 @@ public final class ThreadExecutorMap {
public static Runnable apply(final Runnable command, final EventExecutor eventExecutor) {
Objects.requireNonNull(command, "command");
Objects.requireNonNull(eventExecutor, "eventExecutor");
return new Runnable() {
@Override
public void run() {
return () -> {
setCurrentEventExecutor(eventExecutor);
try {
command.run();
} finally {
setCurrentEventExecutor(null);
}
}
};
}
@ -87,11 +79,6 @@ public final class ThreadExecutorMap {
public static ThreadFactory apply(final ThreadFactory threadFactory, final EventExecutor eventExecutor) {
Objects.requireNonNull(threadFactory, "command");
Objects.requireNonNull(eventExecutor, "eventExecutor");
return new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return threadFactory.newThread(apply(r, eventExecutor));
}
};
return r -> threadFactory.newThread(apply(r, eventExecutor));
}
}

View File

@ -193,10 +193,7 @@ public class SingleThreadEventExecutorTest {
}
};
final Runnable dummyTask = new Runnable() {
@Override
public void run() {
}
final Runnable dummyTask = () -> {
};
final LinkedBlockingQueue<Future<?>> submittedTasks = new LinkedBlockingQueue<Future<?>>();

View File

@ -29,34 +29,22 @@ public class ThreadExecutorMapTest {
@Test
public void testDecorateExecutor() {
Executor executor = ThreadExecutorMap.apply(ImmediateExecutor.INSTANCE, ImmediateEventExecutor.INSTANCE);
executor.execute(new Runnable() {
@Override
public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor());
}
});
executor.execute(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor()));
}
@Test
public void testDecorateRunnable() {
ThreadExecutorMap.apply(new Runnable() {
@Override
public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor());
}
}, ImmediateEventExecutor.INSTANCE).run();
ThreadExecutorMap.apply(() ->
Assert.assertSame(ImmediateEventExecutor.INSTANCE,
ThreadExecutorMap.currentExecutor()), ImmediateEventExecutor.INSTANCE).run();
}
@Test
public void testDecorateThreadFactory() throws InterruptedException {
ThreadFactory threadFactory =
ThreadExecutorMap.apply(Executors.defaultThreadFactory(), ImmediateEventExecutor.INSTANCE);
Thread thread = threadFactory.newThread(new Runnable() {
@Override
public void run() {
Assert.assertSame(ImmediateEventExecutor.INSTANCE, ThreadExecutorMap.currentExecutor());
}
});
Thread thread = threadFactory.newThread(() -> Assert.assertSame(ImmediateEventExecutor.INSTANCE,
ThreadExecutorMap.currentExecutor()));
thread.start();
thread.join();
}

View File

@ -26,7 +26,6 @@ import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -218,12 +217,7 @@ public class FlowControlHandler implements ChannelHandler {
private static final int DEFAULT_NUM_ELEMENTS = 2;
private static final ObjectPool<RecyclableArrayDeque> RECYCLER = ObjectPool.newPool(
new ObjectCreator<RecyclableArrayDeque>() {
@Override
public RecyclableArrayDeque newObject(Handle<RecyclableArrayDeque> handle) {
return new RecyclableArrayDeque(DEFAULT_NUM_ELEMENTS, handle);
}
});
handle -> new RecyclableArrayDeque(DEFAULT_NUM_ELEMENTS, handle));
public static RecyclableArrayDeque newInstance() {
return RECYCLER.get();

View File

@ -1351,9 +1351,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
if (task == null) {
return null;
}
return new Runnable() {
@Override
public void run() {
return () -> {
if (isDestroyed()) {
// The engine was destroyed in the meantime, just return.
return;
@ -1364,7 +1362,6 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
// The task was run, reset needTask to false so getHandshakeStatus() returns the correct value.
needTask = false;
}
}
};
}

View File

@ -945,14 +945,11 @@ public class SslHandler extends ByteToMessageDecoder {
SSLEngineResult result = wrap(alloc, engine, Unpooled.EMPTY_BUFFER, out);
if (result.bytesProduced() > 0) {
ctx.write(out).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
ctx.write(out).addListener((ChannelFutureListener) future -> {
Throwable cause = future.cause();
if (cause != null) {
setHandshakeFailureTransportFailure(ctx, cause);
}
}
});
if (inUnwrap) {
needsFlush = true;

View File

@ -18,8 +18,6 @@ package io.netty.handler.flush;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
@ -163,12 +161,7 @@ public class FlushConsolidationHandlerTest {
public void testResend() throws Exception {
final AtomicInteger flushCount = new AtomicInteger();
final EmbeddedChannel channel = newChannel(flushCount, true);
channel.writeAndFlush(1L).addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
channel.writeAndFlush(1L);
}
});
channel.writeAndFlush(1L).addListener(future -> channel.writeAndFlush(1L));
channel.flushOutbound();
assertEquals(1L, ((Long) channel.readOutbound()).longValue());
assertEquals(1L, ((Long) channel.readOutbound()).longValue());

View File

@ -62,7 +62,6 @@ import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -100,12 +99,7 @@ public class OpenSslPrivateKeyMethodTest {
GROUP = new MultithreadEventLoopGroup(LocalHandler.newFactory());
CERT = new SelfSignedCertificate();
EXECUTOR = Executors.newCachedThreadPool(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new DelegateThread(r);
}
});
EXECUTOR = Executors.newCachedThreadPool(DelegateThread::new);
}
@AfterClass

View File

@ -123,12 +123,9 @@ public class SslHandlerTest {
try {
final CountDownLatch writeCauseLatch = new CountDownLatch(1);
final AtomicReference<Throwable> failureRef = new AtomicReference<Throwable>();
ch.write(Unpooled.wrappedBuffer(new byte[]{1})).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
ch.write(Unpooled.wrappedBuffer(new byte[]{1})).addListener((ChannelFutureListener) future -> {
failureRef.compareAndSet(null, future.cause());
writeCauseLatch.countDown();
}
});
writeLatch.await();

View File

@ -513,12 +513,9 @@ public class ChunkedWriteHandlerTest {
final CountDownLatch listenerInvoked = new CountDownLatch(1);
ChannelFuture writeFuture = ch.write(input);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
writeFuture.addListener((ChannelFutureListener) future -> {
inputClosedWhenListenerInvoked.set(input.isClosed());
listenerInvoked.countDown();
}
});
ch.flush();
@ -537,12 +534,9 @@ public class ChunkedWriteHandlerTest {
final CountDownLatch listenerInvoked = new CountDownLatch(1);
ChannelFuture writeFuture = ch.write(input);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
writeFuture.addListener((ChannelFutureListener) future -> {
inputClosedWhenListenerInvoked.set(input.isClosed());
listenerInvoked.countDown();
}
});
ch.flush();
@ -562,12 +556,9 @@ public class ChunkedWriteHandlerTest {
final CountDownLatch listenerInvoked = new CountDownLatch(1);
ChannelFuture writeFuture = ch.write(input);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
writeFuture.addListener((ChannelFutureListener) future -> {
inputClosedWhenListenerInvoked.set(input.isClosed());
listenerInvoked.countDown();
}
});
ch.close(); // close channel to make handler discard the input on subsequent flush
ch.flush();
@ -588,12 +579,9 @@ public class ChunkedWriteHandlerTest {
final CountDownLatch listenerInvoked = new CountDownLatch(1);
ChannelFuture writeFuture = ch.write(input);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
writeFuture.addListener((ChannelFutureListener) future -> {
inputClosedWhenListenerInvoked.set(input.isClosed());
listenerInvoked.countDown();
}
});
ch.close(); // close channel to make handler discard the input on subsequent flush
ch.flush();

View File

@ -37,10 +37,7 @@ import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark {
private static final Runnable runnable = new Runnable() {
@Override
public void run() { }
};
private static final Runnable runnable = () -> { };
private EventLoopGroup group;
private Channel serverChan;

View File

@ -1211,9 +1211,7 @@ public class DnsNameResolver extends InetNameResolver {
.group(executor())
.channelFactory(socketChannelFactory)
.handler(TCP_ENCODER);
bs.connect(res.sender()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
bs.connect(res.sender()).addListener((ChannelFutureListener) future -> {
if (!future.isSuccess()) {
if (logger.isDebugEnabled()) {
logger.debug("{} Unable to fallback to TCP [{}]", queryId, future.cause());
@ -1234,36 +1232,36 @@ public class DnsNameResolver extends InetNameResolver {
channel.pipeline().addLast(new TcpDnsResponseDecoder());
channel.pipeline().addLast(new ChannelHandler() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
Channel channel = ctx.channel();
DnsResponse response = (DnsResponse) msg;
int queryId = response.id();
public void channelRead(ChannelHandlerContext ctx1, Object msg1) {
Channel channel = ctx1.channel();
DnsResponse response = (DnsResponse) msg1;
int queryId1 = response.id();
if (logger.isDebugEnabled()) {
logger.debug("{} RECEIVED: TCP [{}: {}], {}", channel, queryId,
logger.debug("{} RECEIVED: TCP [{}: {}], {}", channel, queryId1,
channel.remoteAddress(), response);
}
DnsQueryContext foundCtx = queryContextManager.get(res.sender(), queryId);
DnsQueryContext foundCtx = queryContextManager.get(res.sender(), queryId1);
if (foundCtx == tcpCtx) {
tcpCtx.finish(new AddressedEnvelopeAdapter(
(InetSocketAddress) ctx.channel().remoteAddress(),
(InetSocketAddress) ctx.channel().localAddress(),
(InetSocketAddress) ctx1.channel().remoteAddress(),
(InetSocketAddress) ctx1.channel().localAddress(),
response));
} else {
response.release();
tcpCtx.tryFailure("Received TCP response with unexpected ID", null, false);
logger.warn("{} Received a DNS response with an unexpected ID: {}",
channel, queryId);
channel, queryId1);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
public void exceptionCaught(ChannelHandlerContext ctx1, Throwable cause) {
if (tcpCtx.tryFailure("TCP fallback error", cause, false) && logger.isDebugEnabled()) {
logger.debug("{} Error during processing response: TCP [{}: {}]",
ctx.channel(), queryId,
ctx.channel().remoteAddress(), cause);
ctx1.channel(), queryId,
ctx1.channel().remoteAddress(), cause);
}
}
});
@ -1285,7 +1283,6 @@ public class DnsNameResolver extends InetNameResolver {
}
});
tcpCtx.query(true, future.channel().newPromise());
}
});
}

View File

@ -2467,10 +2467,7 @@ public class DnsNameResolverTest {
final String txt1 = "some text";
final String txt2 = "some more text";
TestDnsServer server = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) {
TestDnsServer server = new TestDnsServer(question -> {
if (question.getDomainName().equals(hostname)) {
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put(DnsAttribute.CHARACTER_STRING.toLowerCase(), txt1);
@ -2484,7 +2481,6 @@ public class DnsNameResolverTest {
return records;
}
return Collections.emptySet();
}
});
server.start();
DnsNameResolver resolver = newResolver(ResolvedAddressTypes.IPV4_ONLY)
@ -2536,9 +2532,7 @@ public class DnsNameResolverTest {
public void testNotIncludeDuplicates() throws IOException {
final String name = "netty.io";
final String ipv4Addr = "1.2.3.4";
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) {
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
Set<ResourceRecord> records = new LinkedHashSet<ResourceRecord>(4);
String qName = question.getDomainName().toLowerCase();
if (qName.equals(name)) {
@ -2555,7 +2549,6 @@ public class DnsNameResolverTest {
DnsAttribute.IP_ADDRESS.toLowerCase(), ipv4Addr)));
}
return records;
}
});
dnsServer2.start();
DnsNameResolver resolver = null;
@ -2582,9 +2575,7 @@ public class DnsNameResolverTest {
public void testIncludeDuplicates() throws IOException {
final String name = "netty.io";
final String ipv4Addr = "1.2.3.4";
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) {
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
Set<ResourceRecord> records = new LinkedHashSet<ResourceRecord>(2);
String qName = question.getDomainName().toLowerCase();
records.add(new TestDnsServer.TestResourceRecord(qName,
@ -2594,7 +2585,6 @@ public class DnsNameResolverTest {
RecordType.A, Collections.<String, Object>singletonMap(
DnsAttribute.IP_ADDRESS.toLowerCase(), ipv4Addr)));
return records;
}
});
dnsServer2.start();
DnsNameResolver resolver = null;
@ -2674,9 +2664,7 @@ public class DnsNameResolverTest {
@Test(timeout = 2000)
public void testDropAAAAResolveAllFast() throws IOException {
final String host = "somehost.netty.io";
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) throws DnsException {
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
String name = question.getDomainName();
if (name.equals(host)) {
Set<ResourceRecord> records = new HashSet<ResourceRecord>(2);
@ -2689,7 +2677,6 @@ public class DnsNameResolverTest {
return records;
}
return null;
}
});
dnsServer2.start(true);
DnsNameResolver resolver = null;
@ -2756,9 +2743,7 @@ public class DnsNameResolverTest {
final String txt = "this is a txt record";
final AtomicReference<DnsMessage> messageRef = new AtomicReference<DnsMessage>();
TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {
@Override
public Set<ResourceRecord> getRecords(QuestionRecord question) {
TestDnsServer dnsServer2 = new TestDnsServer(question -> {
String name = question.getDomainName();
if (name.equals(host)) {
return Collections.<ResourceRecord>singleton(
@ -2767,7 +2752,6 @@ public class DnsNameResolverTest {
DnsAttribute.CHARACTER_STRING.toLowerCase(), txt)));
}
return null;
}
}) {
@Override
protected DnsMessage filterMessage(DnsMessage message) {

View File

@ -24,7 +24,6 @@ import static org.ops4j.pax.exam.CoreOptions.url;
import static org.osgi.framework.Constants.FRAMEWORK_BOOTDELEGATION;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -45,12 +44,8 @@ public class OsgiBundleTest {
final Set<String> links = new HashSet<String>();
final File directory = new File("target/generated-test-resources/alta/");
File[] files = directory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.startsWith("io.netty") || name.startsWith("com.barchart.udt")) && name.endsWith(".link");
}
});
File[] files = directory.listFiles((dir, name) ->
(name.startsWith("io.netty") || name.startsWith("com.barchart.udt")) && name.endsWith(".link"));
if (files == null) {
throw new IllegalStateException(directory + " is not found or is not a directory");
}

View File

@ -86,12 +86,7 @@ public abstract class AbstractSingleThreadEventLoopTest {
public void gracefulShutdownAfterStart() throws Exception {
EventLoop loop = new MultithreadEventLoopGroup(newIoHandlerFactory()).next();
final CountDownLatch latch = new CountDownLatch(1);
loop.execute(new Runnable() {
@Override
public void run() {
latch.countDown();
}
});
loop.execute(latch::countDown);
// Wait for the event loop thread to start.
latch.await();
@ -105,10 +100,7 @@ public abstract class AbstractSingleThreadEventLoopTest {
assertRejection(loop);
}
private static final Runnable NOOP = new Runnable() {
@Override
public void run() { }
};
private static final Runnable NOOP = () -> { };
private static void assertRejection(EventExecutor loop) {
try {

View File

@ -20,7 +20,6 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
@ -87,13 +86,10 @@ public abstract class AbstractSocketReuseFdTest extends AbstractSocketTest {
}
});
ChannelFutureListener listener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
ChannelFutureListener listener = future -> {
if (!future.isSuccess()) {
clientDonePromise.tryFailure(future.cause());
}
}
};
Channel sc = sb.bind().sync().channel();

View File

@ -24,7 +24,6 @@ import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.internal.InternalThreadLocalMap;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.Handle;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.PromiseNotificationUtil;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
@ -788,12 +787,7 @@ public final class ChannelOutboundBuffer {
}
static final class Entry {
private static final ObjectPool<Entry> RECYCLER = ObjectPool.newPool(new ObjectCreator<Entry>() {
@Override
public Entry newObject(Handle<Entry> handle) {
return new Entry(handle);
}
});
private static final ObjectPool<Entry> RECYCLER = ObjectPool.newPool(Entry::new);
private final Handle<Entry> handle;
Entry next;

View File

@ -966,13 +966,7 @@ final class DefaultChannelHandlerContext implements ChannelHandlerContext, Resou
static final class WriteTask extends AbstractWriteTask implements SingleThreadEventLoop.NonWakeupRunnable {
private static final ObjectPool<WriteTask> RECYCLER = ObjectPool.newPool(
new ObjectPool.ObjectCreator<WriteTask>() {
@Override
public WriteTask newObject(ObjectPool.Handle<WriteTask> handle) {
return new WriteTask(handle);
}
});
private static final ObjectPool<WriteTask> RECYCLER = ObjectPool.newPool(WriteTask::new);
static WriteTask newInstance(
DefaultChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
@ -993,13 +987,7 @@ final class DefaultChannelHandlerContext implements ChannelHandlerContext, Resou
static final class WriteAndFlushTask extends AbstractWriteTask {
private static final ObjectPool<WriteAndFlushTask> RECYCLER = ObjectPool.newPool(
new ObjectPool.ObjectCreator<WriteAndFlushTask>() {
@Override
public WriteAndFlushTask newObject(ObjectPool.Handle<WriteAndFlushTask> handle) {
return new WriteAndFlushTask(handle);
}
});
private static final ObjectPool<WriteAndFlushTask> RECYCLER = ObjectPool.newPool(WriteAndFlushTask::new);
static WriteAndFlushTask newInstance(
DefaultChannelHandlerContext ctx, Object msg, ChannelPromise promise) {

View File

@ -20,7 +20,6 @@ import static java.util.Objects.requireNonNull;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.PromiseCombiner;
import io.netty.util.internal.ObjectPool;
import io.netty.util.internal.ObjectPool.ObjectCreator;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -286,12 +285,7 @@ public final class PendingWriteQueue {
* Holds all meta-data and construct the linked-list structure.
*/
static final class PendingWrite {
private static final ObjectPool<PendingWrite> RECYCLER = ObjectPool.newPool(new ObjectCreator<PendingWrite>() {
@Override
public PendingWrite newObject(ObjectPool.Handle<PendingWrite> handle) {
return new PendingWrite(handle);
}
});
private static final ObjectPool<PendingWrite> RECYCLER = ObjectPool.newPool(PendingWrite::new);
private final ObjectPool.Handle<PendingWrite> handle;
private PendingWrite next;

View File

@ -1608,9 +1608,7 @@ public class DefaultChannelPipelineTest {
assertEquals(expectedNumber, pipeline.names().size());
assertEquals(expectedNumber, pipeline.toMap().size());
pipeline.executor().submit(new Runnable() {
@Override
public void run() {
pipeline.executor().submit(() -> {
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) pipeline.firstContext();
int handlerNumber = 0;
if (ctx != null) {
@ -1623,7 +1621,6 @@ public class DefaultChannelPipelineTest {
}
}
assertEquals(expectedNumber, handlerNumber);
}
}).syncUninterruptibly();
}

View File

@ -295,13 +295,10 @@ public class PendingWriteQueueTest {
});
ChannelPromise promise2 = channel.newPromise();
promise2.addListener((ChannelFutureListener) future -> failOrder.add(2));
channel.eventLoop().execute(new Runnable() {
@Override
public void run() {
channel.eventLoop().execute(() -> {
queue.add(1L, promise);
queue.add(2L, promise2);
queue.removeAndFailAll(new Exception());
}
});
assertTrue(promise.isDone());