Skip to content

Commit 6794849

Browse files
committed
适配最新版
1 parent 1347601 commit 6794849

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

frameworks/Java/smart-socket/benchmark_config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"default": {
66
"json_url": "/json",
77
"plaintext_url": "/plaintext",
8-
"db_url": "/db",
9-
"query_url": "/queries?queries=",
10-
"update_url": "/updates?queries=",
118
"port": 8080,
129
"approach": "Realistic",
1310
"classification": "Platform",

frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,11 @@
1818
import org.smartboot.http.server.handler.HttpRouteHandler;
1919

2020
import javax.sql.DataSource;
21-
import java.io.IOException;
2221

2322
public class Bootstrap {
2423
static byte[] body = "Hello, World!".getBytes();
2524

2625
public static void main(String[] args) {
27-
HttpRouteHandler routeHandle = new HttpRouteHandler();
28-
routeHandle
29-
.route("/plaintext", new HttpServerHandler() {
30-
31-
32-
@Override
33-
public void handle(HttpRequest request, HttpResponse response) throws IOException {
34-
response.setContentLength(body.length);
35-
response.setContentType("text/plain; charset=UTF-8");
36-
response.write(body);
37-
}
38-
})
39-
.route("/json", new HttpServerHandler() {
40-
41-
@Override
42-
public void handle(HttpRequest request, HttpResponse response) throws IOException {
43-
44-
response.setContentType("application/json");
45-
JsonUtil.writeJsonBytes(response, new Message("Hello, World!"));
46-
}
47-
});
48-
initDB(routeHandle);
4926
int cpuNum = Runtime.getRuntime().availableProcessors();
5027
// 定义服务器接受的消息类型以及各类消息对应的处理器
5128
HttpBootstrap bootstrap = new HttpBootstrap();
@@ -54,7 +31,19 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio
5431
.headerLimiter(0)
5532
.readBufferSize(1024 * 4)
5633
.writeBufferSize(1024 * 4);
57-
bootstrap.httpHandler(routeHandle).setPort(8080).start();
34+
bootstrap.httpHandler(new HttpServerHandler() {
35+
@Override
36+
public void handle(HttpRequest request, HttpResponse response) throws Throwable {
37+
if ("/plaintext".equals(request.getRequestURI())) {
38+
response.setContentLength(body.length);
39+
response.setContentType("text/plain; charset=UTF-8");
40+
response.write(body);
41+
} else if ("/json".equals(request.getRequestURI())) {
42+
response.setContentType("application/json");
43+
JsonUtil.writeJsonBytes(response, new Message("Hello, World!"));
44+
}
45+
}
46+
}).setPort(8080).start();
5847
}
5948

6049
private static void initDB(HttpRouteHandler routeHandle) {

0 commit comments

Comments
 (0)