From 27859ed20498e520a9addeaad2ca01e315c6b5f9 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Tue, 16 Jul 2024 16:39:46 +0200 Subject: [PATCH] Issue #12047 allow disabling opening connectors before starting --- .../java/org/eclipse/jetty/server/Server.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 166c70b0952b..9c79d3a642ba 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -86,6 +86,7 @@ public class Server extends Handler.Wrapper implements Attributes private final AutoLock _dateLock = new AutoLock(); private final MimeTypes.Mutable _mimeTypes = new MimeTypes.Mutable(); private String _serverInfo = __serverInfo; + private boolean _bindEarly = true; private boolean _stopAtShutdown; private boolean _dumpAfterStart; private boolean _dumpBeforeStop; @@ -276,6 +277,22 @@ public InvocationType getInvocationType() return type; } + public boolean isBindEarly() + { + return _bindEarly; + } + + /** + * Allows to disable early binding of network sockets. Network sockets are bound early by default. + * @param bindEarly If {@code bindEarly} is {@code true} (default), network sockets are bound before + * starting other components. If {@code bindEarly} is {@code false}, network connectors open sockets + * when they're started. + */ + public void setBindEarly(boolean bindEarly) + { + _bindEarly = bindEarly; + } + public boolean isDryRun() { return _dryRun; @@ -543,7 +560,7 @@ protected void doStart() throws Exception final ExceptionUtil.MultiException multiException = new ExceptionUtil.MultiException(); // Open network connector to ensure ports are available - if (!_dryRun) + if (!_dryRun && _bindEarly) { _connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(connector -> {