Skip to content

Commit 15ad691

Browse files
committed
server: remove server from application
- we just need the buffered factory
1 parent 71e2581 commit 15ad691

3 files changed

Lines changed: 16 additions & 23 deletions

File tree

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class Jooby implements Router, Registry {
8787

8888
private static Jooby owner;
8989
private static ExecutionMode BOOT_EXECUTION_MODE = ExecutionMode.DEFAULT;
90-
private static Server BOOT_SERVER;
90+
private static BufferedOutputFactory BUFFER_FACTORY;
9191

9292
private RouterImpl router;
9393

@@ -121,8 +121,6 @@ public class Jooby implements Router, Registry {
121121

122122
private String version;
123123

124-
private Server server;
125-
126124
/** Creates a new Jooby instance. */
127125
public Jooby() {
128126
if (owner == null) {
@@ -133,14 +131,10 @@ public Jooby() {
133131
startingCallbacks = new ArrayList<>();
134132
readyCallbacks = new ArrayList<>();
135133
lateExtensions = new ArrayList<>();
136-
server = BOOT_SERVER;
137-
if (server != null) {
138-
router.setOutputFactory(server.getOutputFactory());
139-
} else {
140-
// NOTE: fallback to default, this is required for direct instance creation of class
141-
// app bootstrap always ensures server instance.
142-
router.setOutputFactory(BufferedOutputFactory.create());
143-
}
134+
// NOTE: fallback to default, this is required for direct instance creation of class
135+
// app bootstrap always ensures server instance.
136+
router.setOutputFactory(
137+
Optional.ofNullable(BUFFER_FACTORY).orElseGet(BufferedOutputFactory::create));
144138
} else {
145139
copyState(owner, this);
146140
}
@@ -1311,12 +1305,12 @@ public static Jooby createApp(
13111305

13121306
Jooby app;
13131307
try {
1314-
Jooby.BOOT_SERVER = server;
1308+
Jooby.BUFFER_FACTORY = server.getOutputFactory();
13151309
Jooby.BOOT_EXECUTION_MODE = executionMode;
13161310
app = provider.get();
13171311
} finally {
13181312
Jooby.BOOT_EXECUTION_MODE = executionMode;
1319-
Jooby.BOOT_SERVER = null;
1313+
Jooby.BUFFER_FACTORY = null;
13201314
}
13211315

13221316
return app;
@@ -1452,7 +1446,7 @@ private void joobyRunHook(ClassLoader loader, Server server) {
14521446
}
14531447

14541448
/**
1455-
* Copy internal state from one application into other.
1449+
* Copy the internal state from one application into others.
14561450
*
14571451
* @param source Source application.
14581452
* @param dest Destination application.
@@ -1471,6 +1465,5 @@ private static void copyState(Jooby source, Jooby dest) {
14711465
dest.readyCallbacks = source.readyCallbacks;
14721466
dest.startingCallbacks = source.startingCallbacks;
14731467
dest.stopCallbacks = source.stopCallbacks;
1474-
dest.server = source.server;
14751468
}
14761469
}

modules/jooby-test/src/main/java/io/jooby/test/JoobyExtension.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ private int port(int port, int fallback) {
232232
public void postProcessTestInstance(Object instance, ExtensionContext context) throws Exception {
233233
for (Field field : instance.getClass().getDeclaredFields()) {
234234
if (!Modifier.isStatic(field.getModifiers())) {
235-
Supplier<Object> injectionPoint =
236-
injectionPoint(context, field.getType(), () -> field.getName());
235+
Supplier<Object> injectionPoint = injectionPoint(context, field.getType(), field::getName);
237236
if (injectionPoint != null) {
238237
field.setAccessible(true);
239238
field.set(instance, injectionPoint.get());

tests/src/test/java/io/jooby/junit/ServerTestRunner.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.jupiter.api.condition.DisabledOnOs;
1919

2020
import io.jooby.*;
21+
import io.jooby.buffer.BufferedOutputFactory;
2122
import io.jooby.internal.MutedServer;
2223
import io.jooby.test.WebClient;
2324

@@ -89,7 +90,7 @@ public void ready(SneakyThrows.Consumer2<WebClient, WebClient> onReady) {
8990
Server server = this.server.get(serverOptions);
9091
String applogger = null;
9192
try {
92-
setBootServer(server);
93+
setBufferFactory(server.getOutputFactory());
9394
System.setProperty("___app_name__", testName);
9495
System.setProperty("___server_name__", server.getName());
9596
var app = provider.get();
@@ -141,15 +142,15 @@ public void ready(SneakyThrows.Consumer2<WebClient, WebClient> onReady) {
141142
} else {
142143
MutedServer.mute(server).stop();
143144
}
144-
setBootServer(null);
145+
setBufferFactory(null);
145146
}
146147
}
147148

148-
private static void setBootServer(Server server) {
149+
private static void setBufferFactory(BufferedOutputFactory bufferedOutputFactory) {
149150
try {
150-
var bootServer = Jooby.class.getDeclaredField("BOOT_SERVER");
151-
bootServer.setAccessible(true);
152-
bootServer.set(null, server);
151+
var field = Jooby.class.getDeclaredField("BUFFER_FACTORY");
152+
field.setAccessible(true);
153+
field.set(null, bufferedOutputFactory);
153154
} catch (NoSuchFieldException | IllegalAccessException e) {
154155
throw SneakyThrows.propagate(e);
155156
}

0 commit comments

Comments
 (0)