Skip to content

Commit 638ef73

Browse files
committed
Make controller compilation synchronous.
1 parent ffb84ea commit 638ef73

File tree

15 files changed

+91
-193
lines changed

15 files changed

+91
-193
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Proteus Changelog.
44
## Unreleased
55
### No issue
66

7+
**Migrate to Jakarta.**
8+
9+
10+
[ffb84eaddbbc01e](https://github.com/noboomu/proteus/commit/ffb84eaddbbc01e) Joshua Bauer *2023-09-27 18:41:05*
11+
712
**Switch to SourceBuddy from OpenHFT for dynamic complilation. Breaks < JDK 17 compatability however.**
813

914

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ Inspired by [Play](http://playframework.com), [Jooby](http://jooby.org), and [li
479479

480480
Dependencies
481481
----------
482-
* [JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
482+
* [JDK 17](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
483483
* [Maven 3](http://maven.apache.org/)
484484

485485

pom.xml

+7-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<commons-lang3.version>3.12.0</commons-lang3.version>
4848
<commons-text.version>1.9</commons-text.version>
4949
<guava.version>32.1.2-jre</guava.version>
50-
<guice.version>5.1.0</guice.version>
50+
<guice.version>6.0.0</guice.version>
5151
<jackson.version>2.15.2</jackson.version>
5252
<jakarta-ws-rs.version>3.1.0</jakarta-ws-rs.version>
5353
<jansi.version>1.18</jansi.version>
@@ -114,11 +114,11 @@
114114
<version>${micrometer-core.version}</version>
115115
</dependency>
116116

117-
<!-- <dependency>-->
118-
<!-- <groupId>com.javax0.sourcebuddy</groupId>-->
119-
<!-- <artifactId>SourceBuddy</artifactId>-->
120-
<!-- <version>2.3.0</version>-->
121-
<!-- </dependency>-->
117+
<!-- <dependency>-->
118+
<!-- <groupId>com.javax0.sourcebuddy</groupId>-->
119+
<!-- <artifactId>SourceBuddy</artifactId>-->
120+
<!-- <version>2.3.0</version>-->
121+
<!-- </dependency>-->
122122

123123
<dependency>
124124
<groupId>com.sun.xml.ws</groupId>
@@ -153,11 +153,6 @@
153153
<version>${project.version}</version>
154154
</dependency>
155155

156-
<dependency>
157-
<groupId>io.sinistral</groupId>
158-
<artifactId>proteus-swagger</artifactId>
159-
<version>${project.version}</version>
160-
</dependency>
161156

162157
</dependencies>
163158
</dependencyManagement>
@@ -253,6 +248,7 @@
253248
</plugin>
254249

255250
<plugin>
251+
<groupId>org.apache.maven.plugins</groupId>
256252
<artifactId>maven-surefire-plugin</artifactId>
257253
<version>${maven-surefire-plugin.version}</version>
258254
<dependencies>

proteus-core/pom.xml

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<groupId>io.sinistral</groupId>
88
<version>0.7.0-SNAPSHOT</version>
99
</parent>
10+
<properties>
11+
<jakarta.activation-api.version>2.1.2</jakarta.activation-api.version>
12+
</properties>
1013

1114
<modelVersion>4.0.0</modelVersion>
1215
<artifactId>proteus-core</artifactId>
@@ -192,6 +195,19 @@ Proteus Changelog.
192195
<version>${jakarta-ws-rs.version}</version>
193196
</dependency>
194197

198+
<dependency>
199+
<groupId>jakarta.validation</groupId>
200+
<artifactId>jakarta.validation-api</artifactId>
201+
<version>${jakarta-validation-api.version}</version>
202+
</dependency>
203+
204+
205+
<dependency>
206+
<groupId>jakarta.activation</groupId>
207+
<artifactId>jakarta.activation-api</artifactId>
208+
<version>${jakarta.activation-api.version}</version>
209+
</dependency>
210+
195211
<!-- <dependency>-->
196212
<!-- <groupId>net.openhft</groupId>-->
197213
<!-- <artifactId>compiler</artifactId>-->
@@ -244,12 +260,6 @@ Proteus Changelog.
244260
<version>${typesafe-config.version}</version>
245261
</dependency>
246262

247-
<dependency>
248-
<groupId>jakarta.validation</groupId>
249-
<artifactId>jakarta.validation-api</artifactId>
250-
<version>${jakarta-validation-api.version}</version>
251-
</dependency>
252-
253263

254264
<dependency>
255265
<groupId>org.yaml</groupId>

proteus-core/src/main/java/io/sinistral/proteus/ProteusApplication.java

+4-21
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,15 @@ public void buildServer() {
285285

286286
final Instant compilationStartTime = Instant.now();
287287

288-
ExecutorService handlerCompilationExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
289-
290-
CountDownLatch countDownLatch = new CountDownLatch(registeredControllers.size());
291-
292-
CopyOnWriteArrayList<Class<? extends Supplier<RoutingHandler>>> routerClasses = new CopyOnWriteArrayList<>();
293-
294-
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
288+
List<Class<? extends Supplier<RoutingHandler>>> routerClasses = new ArrayList<>();
289+
//
290+
// ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
295291

296292
log.info("Compiling route handlers...");
297293

298294
for (Class<?> controllerClass : registeredControllers) {
299295

300-
handlerCompilationExecutor.submit(() -> {
296+
301297

302298
try {
303299

@@ -311,15 +307,10 @@ public void buildServer() {
311307

312308
log.debug("Compiling {}...", controllerClass);
313309

314-
log.debug("Generating {}...", controllerClass);
315-
316310
final String source = generator.generateClassSource();
317311

318312
log.debug("Generated {}...", controllerClass);
319313

320-
321-
lock.writeLock().lock();
322-
323314
try {
324315

325316
final var compiled = Compiler.java().from(source).compile();
@@ -340,22 +331,14 @@ public void buildServer() {
340331
}
341332

342333

343-
lock.writeLock().unlock();
344334

345335
} catch (Exception e) {
346336
log.error("Failed to compile", e);
347337
}
348338

349-
countDownLatch.countDown();
350-
});
351339

352340
}
353341

354-
try {
355-
countDownLatch.await();
356-
} catch (Exception e) {
357-
log.error("Failed waiting for handlers to generate", e);
358-
}
359342

360343
log.debug("Compilation completed in {}", DurationFormatUtils.formatDurationHMS(Duration.between(compilationStartTime, Instant.now()).toMillis()));
361344

proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java

+10-29
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.undertow.server.handlers.Cookie;
1515
import io.undertow.server.handlers.ExceptionHandler;
1616
import io.undertow.util.*;
17-
import jakarta.ws.rs.core.Response;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019

@@ -33,7 +32,6 @@
3332
/**
3433
* @author jbauer
3534
* Base server response. Friendlier interface to underlying exchange.
36-
* @TODO extend jakarta.ws.rs.core.Response
3735
*/
3836

3937
public class ServerResponse<T>
@@ -57,7 +55,7 @@ public class ServerResponse<T>
5755
protected int status = StatusCodes.OK;
5856
protected final HeaderMap headers = new HeaderMap();
5957
protected final Map<String, Cookie> cookies = new HashMap<>();
60-
protected String contentType = jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
58+
protected String contentType = MediaType.APPLICATION_JSON.contentType();
6159
protected T entity;
6260
protected Throwable throwable;
6361
// protected Class<? extends JsonContext> jsonContext;
@@ -175,14 +173,7 @@ public void setStatus(int status)
175173
this.status = status;
176174
}
177175

178-
/**
179-
* @param status
180-
* the status to set
181-
*/
182-
public void setStatus(Response.Status status)
183-
{
184-
this.status = status.getStatusCode();
185-
}
176+
186177

187178
public ServerResponse<T> body(ByteBuffer body)
188179
{
@@ -266,11 +257,7 @@ public ServerResponse<T> throwable(Throwable throwable)
266257
return this;
267258
}
268259

269-
public ServerResponse<T> status(Response.Status status)
270-
{
271-
this.status = status.getStatusCode();
272-
return this;
273-
}
260+
274261

275262
public ServerResponse<T> status(int status)
276263
{
@@ -301,11 +288,11 @@ protected void setContentType(String contentType)
301288
{
302289
this.contentType = contentType;
303290

304-
if (this.contentType.contains(jakarta.ws.rs.core.MediaType.APPLICATION_JSON)) {
291+
if (this.contentType.contains(MediaType.APPLICATION_JSON.contentType())) {
305292
if (!this.preprocessed) {
306293
this.processJson = true;
307294
}
308-
} else if (this.contentType.contains(jakarta.ws.rs.core.MediaType.APPLICATION_XML)) {
295+
} else if (this.contentType.contains(MediaType.APPLICATION_XML.contentType())) {
309296
if (!this.preprocessed) {
310297
this.processXml = true;
311298
}
@@ -319,12 +306,6 @@ public ServerResponse<T> contentType(String contentType)
319306
}
320307

321308

322-
public ServerResponse<T> contentType(jakarta.ws.rs.core.MediaType mediaType)
323-
{
324-
this.setContentType(mediaType.toString());
325-
return this;
326-
}
327-
328309
public ServerResponse<T> contentType(MediaType mediaType)
329310
{
330311
this.setContentType(mediaType.contentType());
@@ -336,19 +317,19 @@ public ServerResponse<T> applicationJson()
336317
if (!this.preprocessed) {
337318
this.processJson = true;
338319
}
339-
this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
320+
this.contentType = MediaType.APPLICATION_JSON.contentType();
340321
return this;
341322
}
342323

343324
public ServerResponse<T> textHtml()
344325
{
345-
this.contentType = jakarta.ws.rs.core.MediaType.TEXT_HTML;
326+
this.contentType = MediaType.TEXT_HTML_UTF8.contentType();
346327
return this;
347328
}
348329

349330
public ServerResponse<T> applicationOctetStream()
350331
{
351-
this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
332+
this.contentType = MediaType.APPLICATION_OCTET_STREAM.contentType();
352333
return this;
353334
}
354335

@@ -357,13 +338,13 @@ public ServerResponse<T> applicationXml()
357338
if (!this.preprocessed) {
358339
this.processXml = true;
359340
}
360-
this.contentType = jakarta.ws.rs.core.MediaType.APPLICATION_XML;
341+
this.contentType = MediaType.APPLICATION_XML.contentType();
361342
return this;
362343
}
363344

364345
public ServerResponse<T> textPlain()
365346
{
366-
this.contentType = jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
347+
this.contentType = MediaType.TEXT_PLAIN_UTF8.contentType();
367348
return this;
368349
}
369350

proteus-core/src/main/java/io/sinistral/proteus/server/exceptions/ServerException.java

+2-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
package io.sinistral.proteus.server.exceptions;
55

6-
import jakarta.ws.rs.core.Response.Status;
6+
import io.undertow.util.StatusCodes;
77

88
/**
99
* @author jbauer
@@ -16,7 +16,7 @@ public class ServerException extends RuntimeException
1616
*/
1717
private static final long serialVersionUID = 8360356916374374408L;
1818

19-
private Integer status = Status.BAD_REQUEST.getStatusCode();
19+
private Integer status = StatusCodes.BAD_REQUEST;
2020

2121
public ServerException(int status)
2222
{
@@ -25,13 +25,6 @@ public ServerException(int status)
2525
this.status = status;
2626
}
2727

28-
public ServerException(Status status)
29-
{
30-
super();
31-
32-
this.status = status.getStatusCode();
33-
}
34-
3528
/**
3629
* @param message
3730
*/
@@ -42,15 +35,6 @@ public ServerException(String message, int status)
4235
this.status = status;
4336
}
4437

45-
/**
46-
* @param message
47-
*/
48-
public ServerException(String message, Status status)
49-
{
50-
super(message);
51-
52-
this.status = status.getStatusCode();
53-
}
5438

5539
/**
5640
* @param cause
@@ -62,15 +46,6 @@ public ServerException(Throwable cause, int status)
6246
this.status = status;
6347
}
6448

65-
/**
66-
* @param cause
67-
*/
68-
public ServerException(Throwable cause, Status status)
69-
{
70-
super(cause);
71-
72-
this.status = status.getStatusCode();
73-
}
7449

7550
public ServerException(String message, Throwable cause, int status)
7651
{
@@ -79,13 +54,6 @@ public ServerException(String message, Throwable cause, int status)
7954
this.status = status;
8055
}
8156

82-
public ServerException(String message, Throwable cause, Status status)
83-
{
84-
super(message, cause);
85-
86-
this.status = status.getStatusCode();
87-
}
88-
8957
/**
9058
* @return the status
9159
*/

proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
import java.lang.reflect.Type;
5454
import java.net.URI;
5555
import java.net.URL;
56-
import java.nio.file.Files;
57-
import java.nio.file.Paths;
5856
import java.util.ArrayList;
5957
import java.util.Arrays;
6058
import java.util.HashMap;

0 commit comments

Comments
 (0)