Skip to content

Commit 86bcd44

Browse files
Merge pull request #9556 from spericas/helidon-4.1.5-test2
Upgrades to Helidon 4.1.5
2 parents 902d4e0 + 437a76e commit 86bcd44

File tree

11 files changed

+313
-158
lines changed

11 files changed

+313
-158
lines changed

frameworks/Java/helidon/nima/pom.xml

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>io.helidon.applications</groupId>
2323
<artifactId>helidon-se</artifactId>
24-
<version>4.1.2</version>
24+
<version>4.1.5</version>
2525
<relativePath/>
2626
</parent>
2727

@@ -38,6 +38,7 @@
3838
<rocker.version>1.3.0</rocker.version>
3939
<vertx-pg-client.version>4.5.3</vertx-pg-client.version>
4040
<jsoniter.version>0.9.23</jsoniter.version>
41+
<jte.version>3.1.15</jte.version>
4142
</properties>
4243

4344
<dependencies>
@@ -78,9 +79,9 @@
7879
<version>42.6.1</version>
7980
</dependency>
8081
<dependency>
81-
<groupId>com.fizzed</groupId>
82-
<artifactId>rocker-runtime</artifactId>
83-
<version>${rocker.version}</version>
82+
<groupId>gg.jte</groupId>
83+
<artifactId>jte</artifactId>
84+
<version>${jte.version}</version>
8485
</dependency>
8586
<dependency>
8687
<groupId>io.helidon.common.testing</groupId>
@@ -98,7 +99,6 @@
9899
<scope>test</scope>
99100
</dependency>
100101
</dependencies>
101-
102102
<build>
103103
<plugins>
104104
<plugin>
@@ -125,20 +125,21 @@
125125
</execution>
126126
</executions>
127127
</plugin>
128+
128129
<plugin>
129-
<groupId>com.fizzed</groupId>
130-
<artifactId>rocker-maven-plugin</artifactId>
131-
<version>${rocker.version}</version>
130+
<groupId>gg.jte</groupId>
131+
<artifactId>jte-maven-plugin</artifactId>
132+
<version>${jte.version}</version>
133+
<configuration>
134+
<sourceDirectory>${project.basedir}/src/main/resources/views</sourceDirectory>
135+
<contentType>Html</contentType>
136+
</configuration>
132137
<executions>
133138
<execution>
134-
<id>generate-rocker-templates</id>
135139
<phase>generate-sources</phase>
136140
<goals>
137141
<goal>generate</goal>
138142
</goals>
139-
<configuration>
140-
<templateDirectory>src/main/resources</templateDirectory>
141-
</configuration>
142143
</execution>
143144
</executions>
144145
</plugin>

frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/JsonSerializer.java

+23-18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44
import java.util.Arrays;
5-
import java.util.Map;
65
import java.util.List;
6+
import java.util.Map;
77

88
import com.jsoniter.output.JsonStream;
99
import com.jsoniter.output.JsonStreamPool;
@@ -15,7 +15,7 @@ private JsonSerializer() {
1515
}
1616

1717
/**
18-
* Serialize an instance into a JSON object and return it as a byte array.
18+
* Serialize an instance into a byte array.
1919
*
2020
* @param obj the instance
2121
* @return the byte array
@@ -28,19 +28,31 @@ public static byte[] serialize(Object obj) {
2828
return Arrays.copyOfRange(stream.buffer().data(), 0, stream.buffer().tail());
2929
} catch (IOException e) {
3030
throw new JsonException(e);
31-
} finally {
32-
JsonStreamPool.returnJsonStream(stream);
3331
}
3432
}
3533

3634
/**
37-
* Serialize a map of strings into a JSON object and return it as a byte array.
35+
* Serialize an instance into a JSON stream.
36+
*
37+
* @param obj the instance
38+
* @param stream the JSON stream
39+
*/
40+
public static void serialize(Object obj, JsonStream stream) {
41+
try {
42+
stream.reset(null);
43+
stream.writeVal(obj.getClass(), obj);
44+
} catch (IOException e) {
45+
throw new JsonException(e);
46+
}
47+
}
48+
49+
/**
50+
* Serialize a map of strings into a JSON stream.
3851
*
3952
* @param map the map
40-
* @return the byte array
53+
* @param stream the JSON stream
4154
*/
42-
public static byte[] serialize(Map<String, String> map) {
43-
JsonStream stream = JsonStreamPool.borrowJsonStream();
55+
public static void serialize(Map<String, String> map, JsonStream stream) {
4456
try {
4557
stream.reset(null);
4658
stream.writeObjectStart();
@@ -53,22 +65,18 @@ public static byte[] serialize(Map<String, String> map) {
5365
}
5466
});
5567
stream.writeObjectEnd();
56-
return Arrays.copyOfRange(stream.buffer().data(), 0, stream.buffer().tail());
5768
} catch (IOException e) {
5869
throw new JsonException(e);
59-
} finally {
60-
JsonStreamPool.returnJsonStream(stream);
6170
}
6271
}
6372

6473
/**
65-
* Serialize a list of objects into a JSON array and return it as a byte array.
74+
* Serialize a list of objects into a JSON stream.
6675
*
6776
* @param objs the list of objects
68-
* @return the byte array
77+
* @param stream the JSON stream
6978
*/
70-
public static byte[] serialize(List<?> objs) {
71-
JsonStream stream = JsonStreamPool.borrowJsonStream();
79+
public static void serialize(List<?> objs, JsonStream stream) {
7280
try {
7381
stream.reset(null);
7482
stream.writeArrayStart();
@@ -82,11 +90,8 @@ public static byte[] serialize(List<?> objs) {
8290

8391
}
8492
stream.writeArrayEnd();
85-
return Arrays.copyOfRange(stream.buffer().data(), 0, stream.buffer().tail());
8693
} catch (IOException e) {
8794
throw new JsonException(e);
88-
} finally {
89-
JsonStreamPool.returnJsonStream(stream);
9095
}
9196
}
9297
}

frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/Main.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,16 +19,18 @@
1919
import java.nio.charset.StandardCharsets;
2020
import java.util.logging.Logger;
2121

22+
import com.jsoniter.output.JsonStream;
23+
import com.jsoniter.output.JsonStreamPool;
2224
import io.helidon.benchmark.nima.models.DbRepository;
2325
import io.helidon.benchmark.nima.models.HikariJdbcRepository;
2426
import io.helidon.benchmark.nima.models.PgClientRepository;
2527
import io.helidon.benchmark.nima.services.DbService;
2628
import io.helidon.benchmark.nima.services.FortuneHandler;
29+
import io.helidon.config.Config;
30+
import io.helidon.config.ConfigException;
2731
import io.helidon.http.Header;
2832
import io.helidon.http.HeaderNames;
2933
import io.helidon.http.HeaderValues;
30-
import io.helidon.config.Config;
31-
import io.helidon.config.ConfigException;
3234
import io.helidon.logging.common.LogConfig;
3335
import io.helidon.webserver.WebServer;
3436
import io.helidon.webserver.http.Handler;
@@ -93,7 +95,7 @@ static void routing(HttpRules rules) {
9395

9496
static class PlaintextHandler implements Handler {
9597
static final Header CONTENT_TYPE = HeaderValues.createCached(HeaderNames.CONTENT_TYPE,
96-
"text/plain; charset=UTF-8");
98+
"text/plain; charset=UTF-8");
9799
static final Header CONTENT_LENGTH = HeaderValues.createCached(HeaderNames.CONTENT_LENGTH, "13");
98100
private static final byte[] RESPONSE_BYTES = "Hello, World!".getBytes(StandardCharsets.UTF_8);
99101

@@ -110,14 +112,20 @@ static class JsonHandler implements Handler {
110112
private static final String MESSAGE = "Hello, World!";
111113
private static final int JSON_LENGTH = serialize(new Message(MESSAGE)).length;
112114
static final Header CONTENT_LENGTH = HeaderValues.createCached(HeaderNames.CONTENT_LENGTH,
113-
String.valueOf(JSON_LENGTH));
115+
String.valueOf(JSON_LENGTH));
114116

115117
@Override
116118
public void handle(ServerRequest req, ServerResponse res) {
117-
res.header(CONTENT_LENGTH);
118-
res.header(HeaderValues.CONTENT_TYPE_JSON);
119-
res.header(Main.SERVER);
120-
res.send(serialize(new Message(MESSAGE)));
119+
JsonStream stream = JsonStreamPool.borrowJsonStream();
120+
try {
121+
res.header(CONTENT_LENGTH);
122+
res.header(HeaderValues.CONTENT_TYPE_JSON);
123+
res.header(Main.SERVER);
124+
serialize(new Message(MESSAGE), stream);
125+
res.send(stream.buffer().data(), 0, stream.buffer().tail());
126+
} finally {
127+
JsonStreamPool.returnJsonStream(stream);
128+
}
121129
}
122130
}
123131

@@ -147,4 +155,4 @@ public String getMessage() {
147155
return message;
148156
}
149157
}
150-
}
158+
}

frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/models/Fortune.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
package io.helidon.benchmark.nima.models;
33

4-
public final class Fortune {
4+
public final class Fortune implements Comparable<Fortune> {
55
public int id;
66
public String message;
77

@@ -17,4 +17,8 @@ public int getId() {
1717
public String getMessage() {
1818
return message;
1919
}
20+
@Override
21+
public int compareTo(Fortune other) {
22+
return message.compareTo(other.message);
23+
}
2024
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
package io.helidon.benchmark.nima.models;
3+
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.concurrent.locks.ReentrantLock;
7+
8+
import io.vertx.core.Vertx;
9+
import io.vertx.pgclient.PgConnectOptions;
10+
import io.vertx.pgclient.PgConnection;
11+
import io.vertx.sqlclient.PreparedQuery;
12+
import io.vertx.sqlclient.Row;
13+
import io.vertx.sqlclient.RowSet;
14+
15+
class PgClientConnectionPool implements AutoCloseable {
16+
17+
private final Vertx vertx;
18+
private final PgConnectOptions options;
19+
private final ReentrantLock lock = new ReentrantLock();
20+
private final Map<String, PgClientConnection> connectionMap = new HashMap<>();
21+
22+
public PgClientConnectionPool(Vertx vertx, PgConnectOptions options) {
23+
this.vertx = vertx;
24+
this.options = options;
25+
}
26+
27+
public PgClientConnection clientConnection() {
28+
String carrierThread = carrierThread();
29+
PgClientConnection connection = connectionMap.get(carrierThread);
30+
if (connection == null) {
31+
try {
32+
lock.lock();
33+
connection = connectionMap.get(carrierThread);
34+
if (connection == null) {
35+
connection = newConnection();
36+
connectionMap.put(carrierThread, connection);
37+
}
38+
} finally {
39+
lock.unlock();
40+
}
41+
}
42+
return connection;
43+
}
44+
45+
@Override
46+
public void close() {
47+
try {
48+
for (PgClientConnection connection : connectionMap.values()) {
49+
connection.close();
50+
}
51+
} catch (Exception e) {
52+
throw new RuntimeException(e);
53+
}
54+
}
55+
56+
private PgClientConnection newConnection() {
57+
try {
58+
PgConnection conn = PgConnection.connect(vertx, options)
59+
.toCompletionStage().toCompletableFuture().get();
60+
PgClientConnection clientConn = new PgClientConnection(conn);
61+
clientConn.prepare();
62+
return clientConn;
63+
} catch (Exception e) {
64+
throw new RuntimeException(e);
65+
}
66+
}
67+
68+
static String carrierThread() {
69+
String threadName = Thread.currentThread().toString();
70+
return threadName.substring(threadName.indexOf('@') + 1);
71+
}
72+
73+
public static class PgClientConnection implements AutoCloseable {
74+
static final int UPDATE_QUERIES = 500;
75+
private static String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
76+
private static String SELECT_FORTUNE = "SELECT * from FORTUNE";
77+
78+
private PreparedQuery<RowSet<Row>> worldQuery;
79+
private PreparedQuery<RowSet<Row>> fortuneQuery;
80+
private PreparedQuery<RowSet<Row>>[] updateQuery;
81+
82+
private final PgConnection conn;
83+
84+
PgClientConnection(PgConnection conn) {
85+
this.conn = conn;
86+
}
87+
88+
public PgConnection pgConnection() {
89+
return conn;
90+
}
91+
92+
@Override
93+
public void close() {
94+
conn.close();
95+
}
96+
97+
public PreparedQuery<RowSet<Row>> worldQuery() {
98+
return worldQuery;
99+
}
100+
101+
public PreparedQuery<RowSet<Row>> fortuneQuery() {
102+
return fortuneQuery;
103+
}
104+
105+
public PreparedQuery<RowSet<Row>> updateQuery(int queryCount) {
106+
return updateQuery[queryCount - 1];
107+
}
108+
109+
@SuppressWarnings("unchecked")
110+
void prepare() {
111+
try {
112+
worldQuery = conn.prepare(SELECT_WORLD)
113+
.toCompletionStage().toCompletableFuture().get().query();
114+
fortuneQuery = conn.prepare(SELECT_FORTUNE)
115+
.toCompletionStage().toCompletableFuture().get().query();
116+
updateQuery = (PreparedQuery<RowSet<Row>>[]) new PreparedQuery<?>[UPDATE_QUERIES];
117+
for (int i = 0; i < UPDATE_QUERIES; i++) {
118+
updateQuery[i] = conn.prepare(singleUpdate(i + 1))
119+
.toCompletionStage().toCompletableFuture().get().query();
120+
}
121+
} catch (Exception e) {
122+
throw new RuntimeException(e);
123+
}
124+
}
125+
126+
private static String singleUpdate(int count) {
127+
StringBuilder sql = new StringBuilder();
128+
sql.append("UPDATE WORLD SET RANDOMNUMBER = CASE ID");
129+
for (int i = 0; i < count; i++) {
130+
int k = i * 2 + 1;
131+
sql.append(" WHEN $").append(k).append(" THEN $").append(k + 1);
132+
}
133+
sql.append(" ELSE RANDOMNUMBER");
134+
sql.append(" END WHERE ID IN ($1");
135+
for (int i = 1; i < count; i++) {
136+
int k = i * 2 + 1;
137+
sql.append(",$").append(k);
138+
}
139+
sql.append(")");
140+
return sql.toString();
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)