Skip to content

Commit cca182d

Browse files
committed
server: serverPort is ignored fix #3731
1 parent 8419c28 commit cca182d

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,8 @@ public static void runApp(
12031203
@NonNull ExecutionMode executionMode,
12041204
@NonNull List<Supplier<Jooby>> provider) {
12051205
var cmd = parseArguments(args);
1206-
var options = ServerOptions.from(ConfigFactory.parseMap(cmd)).orElseGet(ServerOptions::new);
1207-
runApp(args, Server.loadServer(options), executionMode, provider);
1206+
var options = ServerOptions.from(ConfigFactory.parseMap(cmd)).orElse(null);
1207+
runApp(args, Server.loadServer(), options, executionMode, provider);
12081208
}
12091209

12101210
/**
@@ -1232,6 +1232,23 @@ public static void runApp(
12321232
@NonNull Server server,
12331233
@NonNull ExecutionMode executionMode,
12341234
@NonNull List<Supplier<Jooby>> provider) {
1235+
runApp(args, server, null, executionMode, provider);
1236+
}
1237+
1238+
/**
1239+
* Setup default environment, logging (logback or log4j2) and run application.
1240+
*
1241+
* @param args Application arguments.
1242+
* @param server Server.
1243+
* @param executionMode Default application execution mode. Can be overridden by application.
1244+
* @param provider Application provider.
1245+
*/
1246+
private static void runApp(
1247+
@NonNull String[] args,
1248+
@NonNull Server server,
1249+
@Nullable ServerOptions options,
1250+
@NonNull ExecutionMode executionMode,
1251+
@NonNull List<Supplier<Jooby>> provider) {
12351252

12361253
/* Dump command line as system properties. */
12371254
parseArguments(args).forEach(System::setProperty);
@@ -1241,13 +1258,17 @@ public static void runApp(
12411258
for (var factory : provider) {
12421259
var app = createApp(server, executionMode, factory);
12431260
/*
1244-
When running a single app instance, there is no issue with server options, when multiple
1245-
apps set options a warning will be printed
1261+
When running a single app instance, there is no issue with server options.
1262+
When multiple apps pick first on the provided order.
12461263
*/
1247-
ServerOptions.from(app.getConfig()).ifPresent(server::setOptions);
1264+
if (options == null) {
1265+
options = ServerOptions.from(app.getConfig()).orElse(null);
1266+
}
12481267
apps.add(app);
12491268
}
1250-
1269+
if (options != null) {
1270+
server.setOptions(options);
1271+
}
12511272
targetServer.start(apps.toArray(new Jooby[0]));
12521273
} catch (Throwable startupError) {
12531274
try {

jooby/src/main/java/io/jooby/ServerOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public class ServerOptions {
8080
public static final int IO_THREADS =
8181
Integer.parseInt(
8282
System.getProperty(
83-
"server.ioThreads", Integer.toString(Runtime.getRuntime().availableProcessors())));
83+
"__server_.ioThreads", Integer.toString(Runtime.getRuntime().availableProcessors())));
8484

85-
private static final String SERVER_NAME = System.getProperty("server.name");
85+
private static final String SERVER_NAME = System.getProperty("__server_.name");
8686

8787
/**
8888
* Number of worker (a.k.a application) threads. It is the number of processors multiply by <code>
@@ -91,7 +91,7 @@ public class ServerOptions {
9191
public static final int WORKER_THREADS =
9292
Integer.parseInt(
9393
System.getProperty(
94-
"server.workerThreads",
94+
"__server_.workerThreads",
9595
Integer.toString(Runtime.getRuntime().availableProcessors() * 8)));
9696

9797
/** HTTP port. Default is <code>8080</code> or <code>0</code> for random port. */

modules/jooby-jetty/src/main/java/io/jooby/jetty/JettyServer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public class JettyServer extends io.jooby.Server.Base {
5353
static {
5454
int cpus = ProcessorUtils.availableProcessors();
5555
var ioThreads = Math.max(1, Math.min(cpus / 2, THREADS / 16));
56-
System.setProperty("server.ioThreads", ioThreads + "");
57-
System.setProperty("server.workerThreads", THREADS + "");
58-
System.setProperty("server.name", NAME);
56+
System.setProperty("__server_.ioThreads", ioThreads + "");
57+
System.setProperty("__server_.workerThreads", THREADS + "");
58+
System.setProperty("__server_.name", NAME);
5959
}
6060

6161
private OutputFactory outputFactory;

modules/jooby-netty/src/main/java/io/jooby/netty/NettyServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class NettyServer extends Server.Base {
4949
private static final String NAME = "netty";
5050

5151
static {
52-
System.setProperty("server.name", NAME);
52+
System.setProperty("__server_.name", NAME);
5353
}
5454

5555
private static final int _50 = 50;
@@ -88,7 +88,9 @@ public NettyServer(@NonNull ServerOptions options) {
8888
super.setOptions(options);
8989
}
9090

91-
public NettyServer() {}
91+
public NettyServer() {
92+
System.out.println("ccc");
93+
}
9294

9395
@NonNull @Override
9496
public OutputFactory getOutputFactory() {

modules/jooby-undertow/src/main/java/io/jooby/undertow/UndertowServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UndertowServer extends Server.Base {
4646

4747
static {
4848
// Default values
49-
System.setProperty("server.name", NAME);
49+
System.setProperty("__server_.name", NAME);
5050
}
5151

5252
private static final int BACKLOG = 8192;

0 commit comments

Comments
 (0)