Skip to content

Commit d54f332

Browse files
committed
code cleanup: remove List.of application
1 parent 6112d76 commit d54f332

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

jooby/src/main/java/io/jooby/buffer/README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ Copy from: https://github.com/spring-projects/spring-framework/tree/main/spring-
88
- replace reactive stream classes references by JDK reactive streams
99
- DataBufferUtils is a limited version of original - remove Deprecated methods
1010
- Remove all deprecated since 6.0 from DataBuffer and DataBufferFactory
11+
12+
13+
= NEW BUFFER API
14+
15+
== JETTY
16+
- https://github.com/jetty/jetty.project/issues/10476
17+
- https://javadoc.jetty.org/jetty-12/org/eclipse/jetty/util/BufferUtil.html
18+
- https://stackoverflow.com/questions/78659372/how-do-you-set-in-jetty-12-a-max-request-size-programmatically

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class JettyServer extends io.jooby.Server.Base {
4747
private Server server;
4848

4949
private ThreadPool threadPool;
50-
private List<Jooby> applications = new ArrayList<>();
5150

5251
private ServerOptions options = new ServerOptions().setServer("jetty").setWorkerThreads(THREADS);
5352
private Consumer<HttpConfiguration> httpConfigurer;
@@ -96,20 +95,19 @@ public io.jooby.Server start(@NonNull Jooby application) {
9695
"org.eclipse.jetty.server.Request.maxFormContentSize",
9796
Long.toString(options.getMaxRequestSize()));
9897

99-
applications.add(application);
100-
10198
addShutdownHook();
10299

103100
if (threadPool == null) {
104101
threadPool = new QueuedThreadPool(options.getWorkerThreads());
105102
((QueuedThreadPool) threadPool).setName("worker");
106103
}
107104

108-
fireStart(applications, threadPool);
105+
fireStart(List.of(application), threadPool);
109106

110107
var acceptors = 1;
111108
var selectors = options.getIoThreads();
112109
this.server = new Server(threadPool);
110+
server.addBean(application);
113111
server.setStopAtShutdown(false);
114112

115113
JettyHttp2Configurer http2 =
@@ -217,7 +215,7 @@ public io.jooby.Server start(@NonNull Jooby application) {
217215
Handler handler =
218216
new JettyHandler(
219217
invocationType,
220-
applications.get(0),
218+
application,
221219
options.getBufferSize(),
222220
options.getMaxRequestSize(),
223221
options.getDefaultHeaders());
@@ -255,7 +253,7 @@ public io.jooby.Server start(@NonNull Jooby application) {
255253
server.setHandler(context);
256254
server.start();
257255

258-
fireReady(applications);
256+
fireReady(List.of(application));
259257
} catch (Exception x) {
260258
if (io.jooby.Server.isAddressInUse(x.getCause())) {
261259
x = new BindException("Address already in use: " + options.getPort());
@@ -289,9 +287,9 @@ private void isNotInUse(List<String> protocols, String protocol, Consumer<String
289287

290288
@NonNull @Override
291289
public synchronized io.jooby.Server stop() {
292-
fireStop(applications);
293-
applications.clear();
294290
if (server != null) {
291+
var app = server.getBean(Jooby.class);
292+
fireStop(List.of(app));
295293
try {
296294
server.stop();
297295
} catch (Exception x) {

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static java.util.concurrent.Executors.newFixedThreadPool;
1111

1212
import java.net.BindException;
13-
import java.util.ArrayList;
1413
import java.util.Arrays;
1514
import java.util.List;
1615
import java.util.concurrent.ExecutionException;
@@ -54,13 +53,13 @@ public class NettyServer extends Server.Base {
5453

5554
private static final int _100 = 100;
5655

57-
private List<Jooby> applications = new ArrayList<>();
5856
private EventLoopGroup acceptorloop;
5957
private EventLoopGroup eventloop;
6058
private EventLoopGroup dateLoop;
6159
private ExecutorService worker;
6260

6361
private NettyDataBufferFactory bufferFactory;
62+
private Jooby application;
6463

6564
private ServerOptions options = new ServerOptions().setServer("netty");
6665

@@ -116,6 +115,7 @@ public String getName() {
116115
@NonNull @Override
117116
public Server start(@NonNull Jooby application) {
118117
try {
118+
this.application = application;
119119
/* Worker: Application blocking code */
120120
if (worker == null) {
121121
worker = newFixedThreadPool(options.getWorkerThreads(), new DefaultThreadFactory("worker"));
@@ -125,14 +125,13 @@ public Server start(@NonNull Jooby application) {
125125
}
126126
// Make sure context use same buffer factory
127127
application.setBufferFactory(bufferFactory);
128-
applications.add(application);
129128

130129
addShutdownHook();
131130

132-
fireStart(applications, worker);
131+
fireStart(List.of(application), worker);
133132

134133
/* Disk attributes: */
135-
String tmpdir = applications.get(0).getTmpdir().toString();
134+
String tmpdir = application.getTmpdir().toString();
136135
DiskFileUpload.baseDirectory = tmpdir;
137136
DiskAttribute.baseDirectory = tmpdir;
138137

@@ -174,7 +173,7 @@ public Server start(@NonNull Jooby application) {
174173
"Server configured for httpsOnly, but ssl options not set");
175174
}
176175

177-
fireReady(applications);
176+
fireReady(List.of(application));
178177
} catch (InterruptedException x) {
179178
throw SneakyThrows.propagate(x);
180179
} catch (ExecutionException x) {
@@ -207,7 +206,6 @@ private ClientAuth toClientAuth(SslOptions.ClientAuth clientAuth) {
207206

208207
private NettyPipeline newPipeline(
209208
SslContext sslContext, HttpDataFactory factory, NettyDateService dateService, boolean http2) {
210-
var router = applications.get(0);
211209
var bufferSize = options.getBufferSize();
212210
var headersFactory = HeadersMultiMap.httpHeadersFactory();
213211
var decoderConfig =
@@ -222,7 +220,7 @@ private NettyPipeline newPipeline(
222220
dateService,
223221
factory,
224222
decoderConfig,
225-
router,
223+
application,
226224
options.getMaxRequestSize(),
227225
bufferSize,
228226
options.getDefaultHeaders(),
@@ -233,8 +231,7 @@ private NettyPipeline newPipeline(
233231

234232
@NonNull @Override
235233
public synchronized Server stop() {
236-
fireStop(applications);
237-
applications.clear();
234+
fireStop(List.of(application));
238235
// only for jooby build where close events may take longer.
239236
NettyWebSocket.all.clear();
240237

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import static io.undertow.UndertowOptions.ENABLE_HTTP2;
99

1010
import java.net.BindException;
11-
import java.util.ArrayList;
12-
import java.util.Collections;
1311
import java.util.List;
1412
import java.util.Optional;
1513

@@ -50,8 +48,7 @@ public class UndertowServer extends Server.Base {
5048
private static final int _10 = 10;
5149

5250
private Undertow server;
53-
54-
private List<Jooby> applications = new ArrayList<>();
51+
private Jooby application;
5552

5653
private ServerOptions options =
5754
new ServerOptions().setIoThreads(ServerOptions.IO_THREADS).setServer("utow");
@@ -76,13 +73,13 @@ public String getName() {
7673
@Override
7774
public @NonNull Server start(@NonNull Jooby application) {
7875
try {
79-
applications.add(application);
76+
this.application = application;
8077

8178
addShutdownHook();
8279

8380
HttpHandler handler =
8481
new UndertowHandler(
85-
applications.get(0),
82+
application,
8683
options.getBufferSize(),
8784
options.getMaxRequestSize(),
8885
options.getDefaultHeaders());
@@ -151,11 +148,11 @@ public String getName() {
151148
} else if (options.isHttpsOnly()) {
152149
throw new StartupException("Server configured for httpsOnly, but ssl options not set");
153150
}
154-
fireStart(applications, worker);
151+
fireStart(List.of(application), worker);
155152
server = builder.build();
156153
server.start();
157154

158-
fireReady(Collections.singletonList(application));
155+
fireReady(List.of(application));
159156

160157
return this;
161158
} catch (Exception x) {
@@ -184,8 +181,7 @@ private SslClientAuthMode toSslClientAuthMode(SslOptions.ClientAuth clientAuth)
184181
@NonNull @Override
185182
public synchronized Server stop() {
186183
try {
187-
fireStop(applications);
188-
applications.clear();
184+
fireStop(List.of(application));
189185
} catch (Exception x) {
190186
throw SneakyThrows.propagate(x);
191187
} finally {

0 commit comments

Comments
 (0)