From f032a0bdba4314fdd9f5dfb3a820db84b63201de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crocquesel?= <88554524+scrocquesel@users.noreply.github.com> Date: Tue, 9 May 2023 21:45:50 +0200 Subject: [PATCH] Produce EventLoopGroup build item --- .../deployment/EventLoopGroupBuildItem.java | 30 +++++++++++++++++++ .../EventLoopSupplierBuildItem.java | 6 ++++ .../netty/deployment/NettyProcessor.java | 9 ++++-- .../quarkus/netty/runtime/NettyRecorder.java | 4 +-- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopGroupBuildItem.java diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopGroupBuildItem.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopGroupBuildItem.java new file mode 100644 index 0000000000000..6f14a38f0a336 --- /dev/null +++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopGroupBuildItem.java @@ -0,0 +1,30 @@ +package io.quarkus.netty.deployment; + +import java.util.function.Supplier; + +import io.netty.channel.EventLoopGroup; +import io.quarkus.builder.item.SimpleBuildItem; + +/** + * Provides suppliers that return EventLoopGroup used by the application. + * + * See EventLoopSupplierBuildItem to register custom EventLoopGroup + */ +public final class EventLoopGroupBuildItem extends SimpleBuildItem { + private final Supplier bossEventLoopGroup; + private final Supplier mainEventLoopGroup; + + public EventLoopGroupBuildItem(Supplier boss, Supplier main) { + this.bossEventLoopGroup = boss; + this.mainEventLoopGroup = main; + } + + public Supplier getBossEventLoopGroup() { + return bossEventLoopGroup; + } + + public Supplier getMainEventLoopGroup() { + return mainEventLoopGroup; + } + +} diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopSupplierBuildItem.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopSupplierBuildItem.java index 176a16bddeaf7..c4c9bf751d905 100644 --- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopSupplierBuildItem.java +++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/EventLoopSupplierBuildItem.java @@ -5,6 +5,12 @@ import io.netty.channel.EventLoopGroup; import io.quarkus.builder.item.SimpleBuildItem; +/** + * Register EventLoopGroup suppliers to be used to produce main EventLoopGroup and boss EventLoopGroup annotated beans. + * If not provided, both will be created from a default supplier. + * + * See EventLoopGroupBuildItem for actual supplier instances + */ public final class EventLoopSupplierBuildItem extends SimpleBuildItem { private final Supplier mainSupplier; diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java index 76174e603d396..766d2f8c00800 100644 --- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java +++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java @@ -180,9 +180,10 @@ public void eagerlyInitClass(NettyRecorder recorder) { @Record(ExecutionTime.RUNTIME_INIT) void registerEventLoopBeans(BuildProducer syntheticBeans, Optional loopSupplierBuildItem, - NettyRecorder recorder) { - Supplier boss; - Supplier main; + NettyRecorder recorder, + BuildProducer eventLoopGroups) { + Supplier boss; + Supplier main; if (loopSupplierBuildItem.isPresent()) { boss = (Supplier) loopSupplierBuildItem.get().getBossSupplier(); main = (Supplier) loopSupplierBuildItem.get().getMainSupplier(); @@ -209,6 +210,8 @@ void registerEventLoopBeans(BuildProducer syntheticBeans .unremovable() .setRuntimeInit() .done()); + + eventLoopGroups.produce(new EventLoopGroupBuildItem(boss, main)); } @BuildStep diff --git a/extensions/netty/runtime/src/main/java/io/quarkus/netty/runtime/NettyRecorder.java b/extensions/netty/runtime/src/main/java/io/quarkus/netty/runtime/NettyRecorder.java index 44c704cf24807..381bf2d8937e9 100644 --- a/extensions/netty/runtime/src/main/java/io/quarkus/netty/runtime/NettyRecorder.java +++ b/extensions/netty/runtime/src/main/java/io/quarkus/netty/runtime/NettyRecorder.java @@ -35,8 +35,8 @@ public void run() { }).start(); } - public Supplier createEventLoop(int nThreads) { - return new Supplier() { + public Supplier createEventLoop(int nThreads) { + return new Supplier() { volatile EventLoopGroup val;