GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Replace *FutureListener* usage with Lambda where possible (#16032) by normanmaurer · Pull Request #16037 · netty/netty

Replace *FutureListener* usage with Lambda where possible (#16032) #16037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 2 commits into 4.2 from lambda42
Dec 19, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Replace *FutureListener* usage with Lambda where possible (#16032) #16037

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
a613e88
Replace *FutureListener* usage with Lambda where possible (#16032)
normanmaurer Dec 14, 2025
670997d
Fix
normanmaurer Dec 16, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
Replace *FutureListener* usage with Lambda where possible (#16032)
Motivation:

We should just use lambdas when possible.

Modifications:

Use lambdas when possible for listeners

Result:

Cleanup
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer committed Dec 14, 2025
commit a613e881da5230e20cf3126db194a7a69515cd76

There are no files selected for viewing

9 changes: 3 additions & 6 deletions 9 codec-base/src/main/java/io/netty/handler/codec/MessageAggregator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,9 @@ protected void decode(final ChannelHandlerContext ctx, I msg, List<Object> out)
// Cache the write listener for reuse.
ChannelFutureListener listener = continueResponseWriteListener;
if (listener == null) {
continueResponseWriteListener = listener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
continueResponseWriteListener = listener = future -> {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
};
}
Expand Down
14 changes: 5 additions & 9 deletions 14 codec-compression/src/main/java/io/netty/handler/codec/compression/EncoderUtil.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.netty.handler.codec.compression;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.util.concurrent.Future;
Expand All @@ -37,14 +36,11 @@ public void run() {
}
}, THREAD_POOL_DELAY_SECONDS, TimeUnit.SECONDS);

finishFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture f) {
// Cancel the scheduled timeout.
future.cancel(true);
if (!promise.isDone()) {
ctx.close(promise);
}
finishFuture.addListener(f -> {
// Cancel the scheduled timeout.
future.cancel(true);
if (!promise.isDone()) {
ctx.close(promise);
}
});
} else {
Expand Down
13 changes: 5 additions & 8 deletions 13 codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,11 @@ public void run() {
}
}, THREAD_POOL_DELAY_SECONDS, TimeUnit.SECONDS);

f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture f) {
// Cancel the scheduled timeout.
future.cancel(true);
if (!promise.isDone()) {
ctx.close(promise);
}
f.addListener(f1 -> {
// Cancel the scheduled timeout.
future.cancel(true);
if (!promise.isDone()) {
ctx.close(promise);
}
});
} else {
Expand Down
19 changes: 7 additions & 12 deletions 19 codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
Expand Down Expand Up @@ -280,16 +278,13 @@ public void run() {
final int size = 27;
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(size, size);
finalClientChannel.writeAndFlush(buf.writerIndex(buf.writerIndex() + size))
.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
try {
writeFailCauseRef.set(future.cause());
} finally {
latch.countDown();
}
}
});
.addListener(future -> {
try {
writeFailCauseRef.set(future.cause());
} finally {
latch.countDown();
}
});
}
});
latch.await();
Expand Down
23 changes: 8 additions & 15 deletions 23 codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectAggregator.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
Expand Down Expand Up @@ -249,23 +248,17 @@ protected void handleOversizedMessage(final ChannelHandlerContext ctx, HttpMessa
if (oversized instanceof FullHttpMessage ||
!HttpUtil.is100ContinueExpected(oversized) && !HttpUtil.isKeepAlive(oversized)) {
ChannelFuture future = ctx.writeAndFlush(TOO_LARGE_CLOSE.retainedDuplicate());
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
logger.debug("Failed to send a 413 Request Entity Too Large.", future.cause());
}
ctx.close();
future.addListener(f -> {
if (!f.isSuccess()) {
logger.debug("Failed to send a 413 Request Entity Too Large.", f.cause());
}
ctx.close();
});
} else {
ctx.writeAndFlush(TOO_LARGE.retainedDuplicate()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
logger.debug("Failed to send a 413 Request Entity Too Large.", future.cause());
ctx.close();
}
ctx.writeAndFlush(TOO_LARGE.retainedDuplicate()).addListener(future -> {
if (!future.isSuccess()) {
logger.debug("Failed to send a 413 Request Entity Too Large.", future.cause());
ctx.close();
}
});
}
Expand Down
78 changes: 32 additions & 46 deletions 78 ...-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;
import io.netty.channel.ChannelInboundHandlerAdapter;
Expand Down Expand Up @@ -287,7 +286,7 @@ public ChannelFuture handshake(Channel channel) {
* the {@link ChannelPromise} to be notified when the opening handshake is sent
*/
public final ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
ChannelPipeline pipeline = channel.pipeline();
final ChannelPipeline pipeline = channel.pipeline();
HttpResponseDecoder decoder = pipeline.get(HttpResponseDecoder.class);
if (decoder == null) {
HttpClientCodec codec = pipeline.get(HttpClientCodec.class);
Expand Down Expand Up @@ -322,26 +321,22 @@ public final ChannelFuture handshake(Channel channel, final ChannelPromise promi

FullHttpRequest request = newHandshakeRequest();

channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
if (future.isSuccess()) {
ChannelPipeline p = future.channel().pipeline();
ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class);
if (ctx == null) {
ctx = p.context(HttpClientCodec.class);
}
if (ctx == null) {
promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
"an HttpRequestEncoder or HttpClientCodec"));
return;
}
p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder());

promise.setSuccess();
} else {
promise.setFailure(future.cause());
channel.writeAndFlush(request).addListener(future -> {
if (future.isSuccess()) {
ChannelHandlerContext ctx = pipeline.context(HttpRequestEncoder.class);
if (ctx == null) {
ctx = pipeline.context(HttpClientCodec.class);
}
if (ctx == null) {
promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
"an HttpRequestEncoder or HttpClientCodec"));
return;
}
pipeline.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder());

promise.setSuccess();
} else {
promise.setFailure(future.cause());
}
});
return promise;
Expand Down Expand Up @@ -687,32 +682,23 @@ private ChannelFuture close0(final ChannelOutboundInvoker invoker, final Channel
return promise;
}

promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
// If flush operation failed, there is no reason to expect
// a server to receive CloseFrame. Thus this should be handled
// by the application separately.
// Also, close might be called twice from different threads.
if (future.isSuccess() && channel.isActive() &&
FORCE_CLOSE_INIT_UPDATER.compareAndSet(handshaker, 0, 1)) {
final Future<?> forceCloseFuture = channel.eventLoop().schedule(new Runnable() {
@Override
public void run() {
if (channel.isActive()) {
invoker.close();
forceCloseComplete = true;
}
promise.addListener(future -> {
// If flush operation failed, there is no reason to expect
// a server to receive CloseFrame. Thus this should be handled
// by the application separately.
// Also, close might be called twice from different threads.
if (future.isSuccess() && channel.isActive() &&
FORCE_CLOSE_INIT_UPDATER.compareAndSet(handshaker, 0, 1)) {
final Future<?> forceCloseFuture = channel.eventLoop().schedule(new Runnable() {
@Override
public void run() {
if (channel.isActive()) {
invoker.close();
forceCloseComplete = true;
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);

channel.closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
forceCloseFuture.cancel(false);
}
});
}
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);
channel.closeFuture().addListener(f -> forceCloseFuture.cancel(false));
}
});
return promise;
Expand Down
28 changes: 9 additions & 19 deletions 28 .../java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
package io.netty.handler.codec.http.websocketx;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;

import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -54,17 +52,14 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {

@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
handshaker.handshake(ctx.channel()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
handshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
ctx.fireUserEventTriggered(
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_ISSUED);
}
ctx.fireChannelActive();
handshaker.handshake(ctx.channel()).addListener(future -> {
if (!future.isSuccess()) {
handshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
ctx.fireUserEventTriggered(
ClientHandshakeStateEvent.HANDSHAKE_ISSUED);
}
});
applyHandshakeTimeout();
Expand Down Expand Up @@ -125,12 +120,7 @@ public void run() {
}, 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(f -> timeoutFuture.cancel(false));
}

/**
Expand Down
14 changes: 2 additions & 12 deletions 14 ...c-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketProtocolHandler.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ public void close(final ChannelHandlerContext ctx, final ChannelPromise promise)
}
flush(ctx);
applyCloseSentTimeout(ctx);
closeSent.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
ctx.close(promise);
}
});
closeSent.addListener(future -> ctx.close(promise));
}
}

Expand Down Expand Up @@ -138,12 +133,7 @@ public void run() {
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);

closeSent.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
timeoutTask.cancel(false);
}
});
closeSent.addListener(future -> timeoutTask.cancel(false));
}

/**
Expand Down
17 changes: 7 additions & 10 deletions 17 ...-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,13 @@ public final ChannelFuture handshake(Channel channel, FullHttpRequest req,
encoderName = p.context(HttpResponseEncoder.class).name();
p.addBefore(encoderName, "wsencoder", newWebSocketEncoder());
}
channel.writeAndFlush(response).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
ChannelPipeline p = future.channel().pipeline();
p.remove(encoderName);
promise.setSuccess();
} else {
promise.setFailure(future.cause());
}
channel.writeAndFlush(response).addListener(future -> {
if (future.isSuccess()) {
ChannelPipeline p1 = channel.pipeline();
p1.remove(encoderName);
Comment thread
Comment on lines +233 to +234

@chrisvest chrisvest Dec 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could inline p1

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
promise.setSuccess();
} else {
promise.setFailure(future.cause());
}
});
return promise;
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.