// Path: falchion-jetty9-connector/src/main/java/net/unit8/falchion/jetty9/ReusePortConnector.java
// public class ReusePortConnector extends ServerConnector {
//     public ReusePortConnector(@Name("server") Server server) {
//         super(server);
//     }
// 
//     public ReusePortConnector(@Name("server") Server server, @Name("factories") ConnectionFactory... factories) {
//         super(server, factories);
//     }
// 
//     @Override
//     public void open() throws IOException {
//         ServerSocketChannel serverChannel = ServerSocketChannel.open();
//         serverChannel.setOption(StandardSocketOptions.SO_REUSEPORT, true);
// 
//         InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
//         serverChannel.socket().setReuseAddress(getReuseAddress());
//         serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
//         serverChannel.configureBlocking(true);
//         addBean(serverChannel);
//         try {
//             Field acceptChannel = ServerConnector.class.getDeclaredField("_acceptChannel");
//             acceptChannel.setAccessible(true);
//             acceptChannel.set(this, serverChannel);
//         } catch (Exception ex) {
//             throw new IOException(ex);
//         }
//     }
// }


import enkan.Env;
import enkan.component.ApplicationComponent;
import enkan.component.falchion.FalchionStartNotifier;
import enkan.component.freemarker.FreemarkerTemplateEngine;
import enkan.component.jetty.JettyComponent;
import enkan.component.metrics.MetricsComponent;
import enkan.config.EnkanSystemFactory;
import enkan.system.EnkanSystem;
import net.unit8.falchion.jetty9.ReusePortConnector;
import org.eclipse.jetty.server.ServerConnector;
import java.util.Objects;
import static enkan.component.ComponentRelationship.component;
import static enkan.util.BeanBuilder.builder;
package net.unit8.falchion.example;




public class ExampleSystemFactory implements EnkanSystemFactory {
    @Override
    public EnkanSystem create() {
        EnkanSystem system =  EnkanSystem.of(
                "http", builder(new JettyComponent())
                        .set(JettyComponent::setServerConnectorFactory, (server, options) -> {
                            ServerConnector connector = new ReusePortConnector(server);
                            connector.setPort(3000);
                            return connector;
                        })
                        .build(),
                "app", new ApplicationComponent("net.unit8.falchion.example.ExampleApplicationFactory"),
                "template", new FreemarkerTemplateEngine(),
                "metrics", new MetricsComponent()
// Path: falchion-jetty9-connector/src/main/java/net/unit8/falchion/jetty9/ReusePortConnector.java
// public class ReusePortConnector extends ServerConnector {
//     public ReusePortConnector(@Name("server") Server server) {
//         super(server);
//     }
// 
//     public ReusePortConnector(@Name("server") Server server, @Name("factories") ConnectionFactory... factories) {
//         super(server, factories);
//     }
// 
//     @Override
//     public void open() throws IOException {
//         ServerSocketChannel serverChannel = ServerSocketChannel.open();
//         serverChannel.setOption(StandardSocketOptions.SO_REUSEPORT, true);
// 
//         InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
//         serverChannel.socket().setReuseAddress(getReuseAddress());
//         serverChannel.socket().bind(bindAddress, getAcceptQueueSize());
//         serverChannel.configureBlocking(true);
//         addBean(serverChannel);
//         try {
//             Field acceptChannel = ServerConnector.class.getDeclaredField("_acceptChannel");
//             acceptChannel.setAccessible(true);
//             acceptChannel.set(this, serverChannel);
//         } catch (Exception ex) {
//             throw new IOException(ex);
//         }
//     }
// }


// Path: falchion-example-enkan/src/main/java/net/unit8/falchion/example/ExampleSystemFactory.java
import enkan.Env;
import enkan.component.ApplicationComponent;
import enkan.component.falchion.FalchionStartNotifier;
import enkan.component.freemarker.FreemarkerTemplateEngine;
import enkan.component.jetty.JettyComponent;
import enkan.component.metrics.MetricsComponent;
import enkan.config.EnkanSystemFactory;
import enkan.system.EnkanSystem;
import net.unit8.falchion.jetty9.ReusePortConnector;
import org.eclipse.jetty.server.ServerConnector;
import java.util.Objects;
import static enkan.component.ComponentRelationship.component;
import static enkan.util.BeanBuilder.builder;

package net.unit8.falchion.example;




public class ExampleSystemFactory implements EnkanSystemFactory {
    @Override
    public EnkanSystem create() {
        EnkanSystem system =  EnkanSystem.of(
                "http", builder(new JettyComponent())
                        .set(JettyComponent::setServerConnectorFactory, (server, options) -> {
                            ServerConnector connector = new ReusePortConnector(server);
                            connector.setPort(3000);
                            return connector;
                        })
                        .build(),
                "app", new ApplicationComponent("net.unit8.falchion.example.ExampleApplicationFactory"),
                "template", new FreemarkerTemplateEngine(),
                "metrics", new MetricsComponent()
        ).relationships(