Skip to content

Commit

Permalink
Produce EventLoopGroup build item
Browse files Browse the repository at this point in the history
  • Loading branch information
scrocquesel committed Jun 19, 2023
1 parent 2971d53 commit f032a0b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<EventLoopGroup> bossEventLoopGroup;
private final Supplier<EventLoopGroup> mainEventLoopGroup;

public EventLoopGroupBuildItem(Supplier<EventLoopGroup> boss, Supplier<EventLoopGroup> main) {
this.bossEventLoopGroup = boss;
this.mainEventLoopGroup = main;
}

public Supplier<EventLoopGroup> getBossEventLoopGroup() {
return bossEventLoopGroup;
}

public Supplier<EventLoopGroup> getMainEventLoopGroup() {
return mainEventLoopGroup;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventLoopGroup> mainSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ public void eagerlyInitClass(NettyRecorder recorder) {
@Record(ExecutionTime.RUNTIME_INIT)
void registerEventLoopBeans(BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
Optional<EventLoopSupplierBuildItem> loopSupplierBuildItem,
NettyRecorder recorder) {
Supplier<Object> boss;
Supplier<Object> main;
NettyRecorder recorder,
BuildProducer<EventLoopGroupBuildItem> eventLoopGroups) {
Supplier<EventLoopGroup> boss;
Supplier<EventLoopGroup> main;
if (loopSupplierBuildItem.isPresent()) {
boss = (Supplier) loopSupplierBuildItem.get().getBossSupplier();
main = (Supplier) loopSupplierBuildItem.get().getMainSupplier();
Expand All @@ -209,6 +210,8 @@ void registerEventLoopBeans(BuildProducer<SyntheticBeanBuildItem> syntheticBeans
.unremovable()
.setRuntimeInit()
.done());

eventLoopGroups.produce(new EventLoopGroupBuildItem(boss, main));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void run() {
}).start();
}

public Supplier<Object> createEventLoop(int nThreads) {
return new Supplier<Object>() {
public Supplier<EventLoopGroup> createEventLoop(int nThreads) {
return new Supplier<EventLoopGroup>() {

volatile EventLoopGroup val;

Expand Down

0 comments on commit f032a0b

Please sign in to comment.