Skip to content
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.

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

Produce EventLoopGroup build item #33239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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