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 by normanmaurer · Pull Request #16032 · netty/netty

Replace *FutureListener* usage with Lambda where possible #16032

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 4 commits into 5.0 from lambda
Dec 14, 2025

Uh oh!

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

Merged

Replace *FutureListener* usage with Lambda where possible #16032

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
4c807f9
Replace *FutureListener* usage with Lambda where possible
normanmaurer Dec 13, 2025
bb8b932
Fix
normanmaurer Dec 13, 2025
91a5922
Fix metadata
normanmaurer Dec 13, 2025
a9d2c4d
Metadata
normanmaurer Dec 13, 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

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) {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
continueResponseWriteListener = listener = future -> {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
};
}
Expand Down
13 changes: 5 additions & 8 deletions 13 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 @@ -37,14 +37,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
17 changes: 7 additions & 10 deletions 17 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 @@ -280,16 +280,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) {
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) {
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) {
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
76 changes: 32 additions & 44 deletions 76 ...-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 @@ -287,7 +287,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 +322,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 +683,24 @@ 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.executor().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.executor().schedule(new Runnable() {
@Override
public void run() {
if (channel.isActive()) {
invoker.close();
forceCloseComplete = true;
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);
}
}, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS);

channel.closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
forceCloseFuture.cancel(false);
}
});
}
channel.closeFuture().addListener(f -> forceCloseFuture.cancel(false));
}
});
return promise;
Expand Down
26 changes: 8 additions & 18 deletions 26 .../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.ChannelInboundHandler;
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 @@ -55,16 +53,13 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
handshaker.handshake(ctx.channel()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
if (!future.isSuccess()) {
handshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
ctx.fireUserEventTriggered(
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_ISSUED);
}
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) {
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 @@ -99,12 +99,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 @@ -139,12 +134,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) {
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);
promise.setSuccess();
} else {
promise.setFailure(future.cause());
}
});
return promise;
Expand Down
36 changes: 13 additions & 23 deletions 36 .../java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.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.http.websocketx;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline;
Expand All @@ -28,7 +27,6 @@
import io.netty.handler.ssl.SslHandler;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;

import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -84,21 +82,18 @@ public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exce
ctx.pipeline().remove(this);

final ChannelFuture handshakeFuture = handshaker.handshake(ctx.channel(), req);
handshakeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
if (!future.isSuccess()) {
localHandshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
localHandshakePromise.trySuccess();
// Kept for compatibility
ctx.fireUserEventTriggered(
WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE);
ctx.fireUserEventTriggered(
new WebSocketServerProtocolHandler.HandshakeComplete(
req.uri(), req.headers(), handshaker.selectedSubprotocol()));
}
handshakeFuture.addListener(future -> {
if (!future.isSuccess()) {
localHandshakePromise.tryFailure(future.cause());
ctx.fireExceptionCaught(future.cause());
} else {
localHandshakePromise.trySuccess();
// Kept for compatibility
ctx.fireUserEventTriggered(
ServerHandshakeStateEvent.HANDSHAKE_COMPLETE);
ctx.fireUserEventTriggered(
new WebSocketServerProtocolHandler.HandshakeComplete(
req.uri(), req.headers(), handshaker.selectedSubprotocol()));
}
});
applyHandshakeTimeout();
Expand Down Expand Up @@ -160,11 +155,6 @@ 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) {
timeoutFuture.cancel(false);
}
});
localHandshakePromise.addListener(f -> timeoutFuture.cancel(false));
}
}
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.