From b708482f2b2022e1f673eb4e7bad43f5c1d083d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 7 Jan 2021 14:04:21 +0800 Subject: [PATCH 01/53] update smart-servlet to 0.1.3-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- .../java/org/smartboot/servlet/Bootstrap.java | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 684419d007a..d54ebeeb924 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -12,7 +12,7 @@ 11 2.11.0 1.0.2 - 0.1.2-SNAPSHOT + 0.1.3-SNAPSHOT 1.5.5-SNAPSHOT diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index d550c8301ca..cff3ca28d73 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,9 +1,12 @@ package org.smartboot.servlet; import org.smartboot.aio.EnhanceAsynchronousChannelProvider; +import org.smartboot.http.HttpRequest; +import org.smartboot.http.HttpResponse; import org.smartboot.http.server.HttpMessageProcessor; import org.smartboot.http.server.HttpRequestProtocol; import org.smartboot.http.server.Request; +import org.smartboot.http.server.handle.HttpHandle; import org.smartboot.servlet.conf.ServletInfo; import org.smartboot.socket.StateMachineEnum; import org.smartboot.socket.buffer.BufferFactory; @@ -24,26 +27,30 @@ public class Bootstrap { public static void main(String[] args) { System.setProperty("java.nio.channels.spi.AsynchronousChannelProvider", EnhanceAsynchronousChannelProvider.class.getName()); - ServletHttpHandle httpHandle = new ServletHttpHandle(); - ContainerRuntime containerRuntime = new ContainerRuntime("/"); + ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext + ApplicationRuntime applicationRuntime = new ApplicationRuntime("/"); ServletInfo plainTextServletInfo = new ServletInfo(); plainTextServletInfo.setServletName("plaintext"); plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName()); plainTextServletInfo.addMapping("/plaintext"); - containerRuntime.getDeploymentInfo().addServlet(plainTextServletInfo); + applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo); // json ServletInfo jsonServletInfo = new ServletInfo(); jsonServletInfo.setServletName("json"); jsonServletInfo.setServletClass(HelloWorldServlet.class.getName()); jsonServletInfo.addMapping("/json"); - containerRuntime.getDeploymentInfo().addServlet(jsonServletInfo); - httpHandle.addRuntime(containerRuntime); - - httpHandle.start(); + applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); + containerRuntime.addRuntime(applicationRuntime); + containerRuntime.start(); HttpMessageProcessor processor = new HttpMessageProcessor(); - processor.pipeline(httpHandle); + processor.pipeline(new HttpHandle() { + @Override + public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + containerRuntime.doHandle(request, response); + } + }); http(processor); } From 538056d4cd86d7d587275bef50bea6756ef97057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 7 Jan 2021 21:05:15 +0800 Subject: [PATCH 02/53] update aio-enhance to 1.0.3-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index d54ebeeb924..20fc84bbe4c 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 11 11 2.11.0 - 1.0.2 + 1.0.3-SNAPSHOT 0.1.3-SNAPSHOT 1.5.5-SNAPSHOT From dc42109cd82e5a35aef3edf786b4f7a399396d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sun, 24 Jan 2021 11:17:15 +0800 Subject: [PATCH 03/53] smart-servlet bugfix --- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index cff3ca28d73..99098b0472d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -39,7 +39,7 @@ public static void main(String[] args) { // json ServletInfo jsonServletInfo = new ServletInfo(); jsonServletInfo.setServletName("json"); - jsonServletInfo.setServletClass(HelloWorldServlet.class.getName()); + jsonServletInfo.setServletClass(JsonServlet.class.getName()); jsonServletInfo.addMapping("/json"); applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); containerRuntime.addRuntime(applicationRuntime); From b946e2583a3cbacb466173c9fc69c5e1000db720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Mon, 1 Feb 2021 18:29:16 +0800 Subject: [PATCH 04/53] bugfix --- frameworks/Java/smart-socket/pom.xml | 11 ++++ .../java/org/smartboot/http/Bootstrap.java | 55 +++++----------- .../java/org/smartboot/servlet/Bootstrap.java | 63 ++++++------------- 3 files changed, 47 insertions(+), 82 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 20fc84bbe4c..01427d6c7be 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -63,6 +63,17 @@ postgresql 42.2.5 + + + org.apache.velocity + velocity + 1.7 + + + oro + oro + 2.0.8 + diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 0228cc4c811..2a75ca95108 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -12,16 +12,11 @@ import com.zaxxer.hikari.HikariDataSource; import org.smartboot.Message; import org.smartboot.aio.EnhanceAsynchronousChannelProvider; -import org.smartboot.http.server.HttpMessageProcessor; -import org.smartboot.http.server.HttpRequestProtocol; import org.smartboot.http.server.Request; import org.smartboot.http.server.handle.HttpHandle; import org.smartboot.http.server.handle.HttpRouteHandle; import org.smartboot.socket.StateMachineEnum; -import org.smartboot.socket.buffer.BufferFactory; -import org.smartboot.socket.buffer.BufferPagePool; import org.smartboot.socket.extension.processor.AbstractMessageProcessor; -import org.smartboot.socket.transport.AioQuickServer; import org.smartboot.socket.transport.AioSession; import javax.sql.DataSource; @@ -55,45 +50,25 @@ public void doHandle(HttpRequest request, HttpResponse response) throws IOExcept } }); initDB(routeHandle); - HttpMessageProcessor processor = new HttpMessageProcessor(); - processor.pipeline(routeHandle); - http(processor); - } - - public static void http(final HttpMessageProcessor processor) { - AbstractMessageProcessor messageProcessor = new AbstractMessageProcessor() { - @Override - public void process0(AioSession session, Request msg) { - processor.process(session, msg); - } - - @Override - public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { - processor.stateEvent(session, stateMachineEnum, throwable); - } - }; -// messageProcessor.addPlugin(new MonitorPlugin(5)); -// messageProcessor.addPlugin(new SocketOptionPlugin()); - int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 - AioQuickServer server = new AioQuickServer<>(8080, new HttpRequestProtocol(), messageProcessor); - server.setThreadNum(cpuNum + 2) + HttpBootstrap bootstrap = new HttpBootstrap(); + bootstrap.setPort(8080).setThreadNum(cpuNum + 2) .setReadBufferSize(1024 * 4) - .setBufferFactory(new BufferFactory() { + .setReadPageSize(16384 * 1024 * 4) + .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4) + .pipeline(routeHandle) + .wrapProcessor(processor -> new AbstractMessageProcessor<>() { @Override - public BufferPagePool create() { - return new BufferPagePool(10 * 1024 * 1024, cpuNum + 2, 64 * 1024 * 1024, true); + public void process0(AioSession session, Request msg) { + processor.process(session, msg); } - }) - .setWriteBuffer(1024 * 4, 8); -// messageProcessor.addPlugin(new BufferPageMonitorPlugin(server, 6)); - try { - server.start(); - } catch (IOException e) { - e.printStackTrace(); - } + @Override + public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { + processor.stateEvent(session, stateMachineEnum, throwable); + } + }).start(); } private static void initDB(HttpRouteHandle routeHandle) { @@ -107,9 +82,13 @@ private static void initDB(HttpRouteHandle routeHandle) { config.setUsername("benchmarkdbuser"); config.setPassword("benchmarkdbpass"); config.setMaximumPoolSize(64); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); DataSource dataSource = new HikariDataSource(config); routeHandle.route("/db", new SingleQueryHandler(dataSource)) .route("/queries", new MultipleQueriesHandler(dataSource)) .route("/updates", new UpdateHandler(dataSource)); +// .route("/fortunes", new FortunesHandler(dataSource)); } } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 99098b0472d..2323c5c0396 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,19 +1,14 @@ package org.smartboot.servlet; import org.smartboot.aio.EnhanceAsynchronousChannelProvider; +import org.smartboot.http.HttpBootstrap; import org.smartboot.http.HttpRequest; import org.smartboot.http.HttpResponse; -import org.smartboot.http.server.HttpMessageProcessor; -import org.smartboot.http.server.HttpRequestProtocol; import org.smartboot.http.server.Request; import org.smartboot.http.server.handle.HttpHandle; import org.smartboot.servlet.conf.ServletInfo; import org.smartboot.socket.StateMachineEnum; -import org.smartboot.socket.buffer.BufferFactory; -import org.smartboot.socket.buffer.BufferPagePool; -import org.smartboot.socket.extension.plugins.MonitorPlugin; import org.smartboot.socket.extension.processor.AbstractMessageProcessor; -import org.smartboot.socket.transport.AioQuickServer; import org.smartboot.socket.transport.AioSession; import java.io.IOException; @@ -44,50 +39,30 @@ public static void main(String[] args) { applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); containerRuntime.addRuntime(applicationRuntime); containerRuntime.start(); - HttpMessageProcessor processor = new HttpMessageProcessor(); - processor.pipeline(new HttpHandle() { - @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { - containerRuntime.doHandle(request, response); - } - }); - http(processor); - } - - public static void http(final HttpMessageProcessor processor) { - AbstractMessageProcessor messageProcessor = new AbstractMessageProcessor() { - @Override - public void process0(AioSession session, Request msg) { - processor.process(session, msg); - } - - @Override - public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { - processor.stateEvent(session, stateMachineEnum, throwable); - } - }; - messageProcessor.addPlugin(new MonitorPlugin(5)); -// messageProcessor.addPlugin(new SocketOptionPlugin()); - int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 - AioQuickServer server = new AioQuickServer<>(8080, new HttpRequestProtocol(), messageProcessor); - server.setThreadNum(cpuNum + 2) + HttpBootstrap bootstrap = new HttpBootstrap(); + bootstrap.setPort(8080).setThreadNum(cpuNum + 2) .setReadBufferSize(1024 * 4) - .setBufferFactory(new BufferFactory() { + .setReadPageSize(16384 * 1024 * 4) + .setBannerEnabled(false) + .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4) + .pipeline(new HttpHandle() { @Override - public BufferPagePool create() { - return new BufferPagePool(10 * 1024 * 1024, cpuNum + 2, 64 * 1024 * 1024, true); + public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + containerRuntime.doHandle(request, response); } }) - .setBannerEnabled(false) - .setWriteBuffer(1024 * 4, 8); + .wrapProcessor(processor -> new AbstractMessageProcessor<>() { + @Override + public void process0(AioSession session, Request msg) { + processor.process(session, msg); + } -// messageProcessor.addPlugin(new BufferPageMonitorPlugin(server, 6)); - try { - server.start(); - } catch (IOException e) { - e.printStackTrace(); - } + @Override + public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { + processor.stateEvent(session, stateMachineEnum, throwable); + } + }).start(); } } From bdec05d6548f6c41a588612e7361d93cc9c753c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sun, 14 Feb 2021 11:10:18 +0800 Subject: [PATCH 05/53] update smart-socket to 1.5.6-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 4 +- .../java/org/smartboot/http/Bootstrap.java | 11 +- .../org/smartboot/http/FortunesHandler.java | 111 ++++++++++++++++++ .../java/org/smartboot/http/JsonUtil.java | 1 + .../http/MultipleQueriesHandler.java | 8 +- .../smartboot/http/SingleQueryHandler.java | 6 +- .../org/smartboot/http/UpdateHandler.java | 8 +- .../java/org/smartboot/servlet/Bootstrap.java | 12 +- .../src/main/resources/fortunes.vm | 21 ++++ 9 files changed, 162 insertions(+), 20 deletions(-) create mode 100644 frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java create mode 100644 frameworks/Java/smart-socket/src/main/resources/fortunes.vm diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 01427d6c7be..9769b2d0306 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,9 +11,9 @@ 11 11 2.11.0 - 1.0.3-SNAPSHOT + 1.0.3 0.1.3-SNAPSHOT - 1.5.5-SNAPSHOT + 1.5.6-SNAPSHOT diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 2a75ca95108..84d7c2ec497 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -12,9 +12,12 @@ import com.zaxxer.hikari.HikariDataSource; import org.smartboot.Message; import org.smartboot.aio.EnhanceAsynchronousChannelProvider; -import org.smartboot.http.server.Request; -import org.smartboot.http.server.handle.HttpHandle; +import org.smartboot.http.server.HttpBootstrap; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; import org.smartboot.http.server.handle.HttpRouteHandle; +import org.smartboot.http.server.impl.Request; import org.smartboot.socket.StateMachineEnum; import org.smartboot.socket.extension.processor.AbstractMessageProcessor; import org.smartboot.socket.transport.AioSession; @@ -30,7 +33,7 @@ public static void main(String[] args) { HttpRouteHandle routeHandle = new HttpRouteHandle(); routeHandle - .route("/plaintext", new HttpHandle() { + .route("/plaintext", new HttpServerHandle() { @Override @@ -40,7 +43,7 @@ public void doHandle(HttpRequest request, HttpResponse response) throws IOExcept response.write(body); } }) - .route("/json", new HttpHandle() { + .route("/json", new HttpServerHandle() { @Override public void doHandle(HttpRequest request, HttpResponse response) throws IOException { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java new file mode 100644 index 00000000000..8f5f7111949 --- /dev/null +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java @@ -0,0 +1,111 @@ +package org.smartboot.http; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; + +import javax.sql.DataSource; +import java.io.IOException; +import java.io.StringWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; + +/** + * @author 三刀(zhengjunweimail@163.com) + * @version V1.0 , 2021/1/24 + */ +public class FortunesHandler extends HttpServerHandle { + private final DataSource dataSource; + private final Template template; + + public FortunesHandler(DataSource dataSource) { + this.dataSource = dataSource; + // 初始化模板引擎 + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + ve.setProperty("output.encoding", "utf8"); + ve.setProperty("input.encoding", "utf8"); + ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + ve.setProperty("eventhandler.referenceinsertion.class", "org.apache.velocity.app.event.implement.EscapeHtmlReference"); + ve.setProperty("eventhandler.escape.html.match", "/^(?!\\$\\!?unesc_).*/"); + ve.init(); + // 获取模板文件 + template = ve.getTemplate("fortunes.vm", "utf8"); + } + + public static void main(String[] args) { + // 初始化模板引擎 + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + ve.setProperty("output.encoding", "MS932"); + ve.setProperty("input.encoding", "MS932"); + ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + ve.setProperty("eventhandler.referenceinsertion.class", "org.apache.velocity.app.event.implement.EscapeHtmlReference"); + ve.setProperty("eventhandler.escape.html.match", "/^(?!\\$\\!?unesc_).*/"); + ve.init(); + // 获取模板文件 + Template template = ve.getTemplate("fortunes.vm", "MS932"); + VelocityContext ctx = new VelocityContext(); + List fortunes = new ArrayList<>(); + fortunes.add(new Fortune(1, "")); + ctx.put("fortunes", fortunes); + ctx.put("text", "フレームワークのベンチマーク"); + StringWriter sw = new StringWriter(); + template.merge(ctx, sw); + System.out.println(sw); + System.out.println("フレームワークのベンチマーク"); + } + + @Override + public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + List fortunes = new ArrayList<>(); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM fortune"); + ResultSet resultSet = preparedStatement.executeQuery();) { + while (resultSet.next()) { + fortunes.add(new Fortune(resultSet.getInt(1), resultSet.getString(2))); + } + fortunes.add(new Fortune(0, "Additional fortune added at request time.")); + fortunes.sort(Comparator.comparing(fortune -> fortune.message)); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + VelocityContext ctx = new VelocityContext(); + ctx.put("fortunes", fortunes); + StringWriter sw = new StringWriter(); + template.merge(ctx, sw); + byte[] bytes = sw.toString().getBytes("utf8"); + response.setContentLength(bytes.length); + response.setContentType("text/plain; charset=UTF-8"); + response.write(bytes); + } + + public static final class Fortune { + public final int id; + public final String message; + + public Fortune(int id, String message) { + this.id = id; + this.message = Objects.requireNonNull(message); + } + + public int getId() { + return id; + } + + public String getMessage() { + return message; + } + } +} diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 930c98164d8..0b507e9142d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -4,6 +4,7 @@ import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; import com.jsoniter.spi.Slice; +import org.smartboot.http.server.HttpResponse; import javax.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index 0a368256a63..0896790de9f 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -1,7 +1,9 @@ package org.smartboot.http; -import org.smartboot.http.server.handle.HttpHandle; -import org.smartboot.http.utils.NumberUtils; +import org.smartboot.http.common.utils.NumberUtils; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; import javax.sql.DataSource; import java.io.IOException; @@ -15,7 +17,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class MultipleQueriesHandler extends HttpHandle { +public class MultipleQueriesHandler extends HttpServerHandle { private DataSource dataSource; public MultipleQueriesHandler(DataSource dataSource) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index 3473d75f88c..4b15f15d516 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -1,6 +1,8 @@ package org.smartboot.http; -import org.smartboot.http.server.handle.HttpHandle; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; import javax.sql.DataSource; import java.io.IOException; @@ -14,7 +16,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class SingleQueryHandler extends HttpHandle { +public class SingleQueryHandler extends HttpServerHandle { private DataSource dataSource; public SingleQueryHandler(DataSource dataSource) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 82307b684a2..51477460746 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -1,7 +1,9 @@ package org.smartboot.http; -import org.smartboot.http.server.handle.HttpHandle; -import org.smartboot.http.utils.NumberUtils; +import org.smartboot.http.common.utils.NumberUtils; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; import javax.sql.DataSource; import java.io.IOException; @@ -16,7 +18,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class UpdateHandler extends HttpHandle { +public class UpdateHandler extends HttpServerHandle { private DataSource dataSource; public UpdateHandler(DataSource dataSource) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 2323c5c0396..8571ce93bbd 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,11 +1,11 @@ package org.smartboot.servlet; import org.smartboot.aio.EnhanceAsynchronousChannelProvider; -import org.smartboot.http.HttpBootstrap; -import org.smartboot.http.HttpRequest; -import org.smartboot.http.HttpResponse; -import org.smartboot.http.server.Request; -import org.smartboot.http.server.handle.HttpHandle; +import org.smartboot.http.server.HttpBootstrap; +import org.smartboot.http.server.HttpRequest; +import org.smartboot.http.server.HttpResponse; +import org.smartboot.http.server.HttpServerHandle; +import org.smartboot.http.server.impl.Request; import org.smartboot.servlet.conf.ServletInfo; import org.smartboot.socket.StateMachineEnum; import org.smartboot.socket.extension.processor.AbstractMessageProcessor; @@ -47,7 +47,7 @@ public static void main(String[] args) { .setReadPageSize(16384 * 1024 * 4) .setBannerEnabled(false) .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4) - .pipeline(new HttpHandle() { + .pipeline(new HttpServerHandle() { @Override public void doHandle(HttpRequest request, HttpResponse response) throws IOException { containerRuntime.doHandle(request, response); diff --git a/frameworks/Java/smart-socket/src/main/resources/fortunes.vm b/frameworks/Java/smart-socket/src/main/resources/fortunes.vm new file mode 100644 index 00000000000..baa01946e42 --- /dev/null +++ b/frameworks/Java/smart-socket/src/main/resources/fortunes.vm @@ -0,0 +1,21 @@ + + + + Fortunes + + + + + + + + #foreach($i in $fortunes) + + + + + #end +
idmessage
${i.id}${i.message}
+${text} + + \ No newline at end of file From 2e8869b03458fea1ca674b8a63e8d67b4bab27c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sat, 20 Feb 2021 14:30:04 +0800 Subject: [PATCH 06/53] remove file --- .../org/smartboot/http/FortunesHandler.java | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java deleted file mode 100644 index 8f5f7111949..00000000000 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FortunesHandler.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.smartboot.http; - -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.runtime.RuntimeConstants; -import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; - -import javax.sql.DataSource; -import java.io.IOException; -import java.io.StringWriter; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; - -/** - * @author 三刀(zhengjunweimail@163.com) - * @version V1.0 , 2021/1/24 - */ -public class FortunesHandler extends HttpServerHandle { - private final DataSource dataSource; - private final Template template; - - public FortunesHandler(DataSource dataSource) { - this.dataSource = dataSource; - // 初始化模板引擎 - VelocityEngine ve = new VelocityEngine(); - ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); - ve.setProperty("output.encoding", "utf8"); - ve.setProperty("input.encoding", "utf8"); - ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); - ve.setProperty("eventhandler.referenceinsertion.class", "org.apache.velocity.app.event.implement.EscapeHtmlReference"); - ve.setProperty("eventhandler.escape.html.match", "/^(?!\\$\\!?unesc_).*/"); - ve.init(); - // 获取模板文件 - template = ve.getTemplate("fortunes.vm", "utf8"); - } - - public static void main(String[] args) { - // 初始化模板引擎 - VelocityEngine ve = new VelocityEngine(); - ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); - ve.setProperty("output.encoding", "MS932"); - ve.setProperty("input.encoding", "MS932"); - ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); - ve.setProperty("eventhandler.referenceinsertion.class", "org.apache.velocity.app.event.implement.EscapeHtmlReference"); - ve.setProperty("eventhandler.escape.html.match", "/^(?!\\$\\!?unesc_).*/"); - ve.init(); - // 获取模板文件 - Template template = ve.getTemplate("fortunes.vm", "MS932"); - VelocityContext ctx = new VelocityContext(); - List fortunes = new ArrayList<>(); - fortunes.add(new Fortune(1, "")); - ctx.put("fortunes", fortunes); - ctx.put("text", "フレームワークのベンチマーク"); - StringWriter sw = new StringWriter(); - template.merge(ctx, sw); - System.out.println(sw); - System.out.println("フレームワークのベンチマーク"); - } - - @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { - List fortunes = new ArrayList<>(); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM fortune"); - ResultSet resultSet = preparedStatement.executeQuery();) { - while (resultSet.next()) { - fortunes.add(new Fortune(resultSet.getInt(1), resultSet.getString(2))); - } - fortunes.add(new Fortune(0, "Additional fortune added at request time.")); - fortunes.sort(Comparator.comparing(fortune -> fortune.message)); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - VelocityContext ctx = new VelocityContext(); - ctx.put("fortunes", fortunes); - StringWriter sw = new StringWriter(); - template.merge(ctx, sw); - byte[] bytes = sw.toString().getBytes("utf8"); - response.setContentLength(bytes.length); - response.setContentType("text/plain; charset=UTF-8"); - response.write(bytes); - } - - public static final class Fortune { - public final int id; - public final String message; - - public Fortune(int id, String message) { - this.id = id; - this.message = Objects.requireNonNull(message); - } - - public int getId() { - return id; - } - - public String getMessage() { - return message; - } - } -} From 4b4541cfc8fb7fe6fad0c7ef95d55ffb755c7857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Mon, 22 Feb 2021 10:38:21 +0800 Subject: [PATCH 07/53] update aio-enhance to 1.0.4-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 9769b2d0306..6fafddf107c 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 11 11 2.11.0 - 1.0.3 + 1.0.4-SNAPSHOT 0.1.3-SNAPSHOT 1.5.6-SNAPSHOT From 9bd5a505d9d3f97b2a186d714ba82dc0d4acd5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Mon, 22 Feb 2021 21:25:00 +0800 Subject: [PATCH 08/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/smartboot/http/Bootstrap.java | 16 +++++----- .../java/org/smartboot/servlet/Bootstrap.java | 30 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 84d7c2ec497..f18b4f9e14e 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -56,12 +56,13 @@ public void doHandle(HttpRequest request, HttpResponse response) throws IOExcept int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); - bootstrap.setPort(8080).setThreadNum(cpuNum + 2) - .setReadBufferSize(1024 * 4) - .setReadPageSize(16384 * 1024 * 4) - .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4) - .pipeline(routeHandle) - .wrapProcessor(processor -> new AbstractMessageProcessor<>() { + bootstrap.configuration() + .threadNum(cpuNum + 2) + .readBufferSize(1024 * 4) + .writeBufferSize(1024 * 4) + .readMemoryPool(16384 * 1024 * 4) + .writeMemoryPool(10 * 1024 * 1024 * (cpuNum + 2), cpuNum + 2) + .messageProcessor(processor -> new AbstractMessageProcessor<>() { @Override public void process0(AioSession session, Request msg) { processor.process(session, msg); @@ -71,7 +72,8 @@ public void process0(AioSession session, Request msg) { public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { processor.stateEvent(session, stateMachineEnum, throwable); } - }).start(); + }); + bootstrap.setPort(8080).start(); } private static void initDB(HttpRouteHandle routeHandle) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 8571ce93bbd..c1f58f5c1bc 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -42,18 +42,14 @@ public static void main(String[] args) { int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); - bootstrap.setPort(8080).setThreadNum(cpuNum + 2) - .setReadBufferSize(1024 * 4) - .setReadPageSize(16384 * 1024 * 4) - .setBannerEnabled(false) - .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4) - .pipeline(new HttpServerHandle() { - @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { - containerRuntime.doHandle(request, response); - } - }) - .wrapProcessor(processor -> new AbstractMessageProcessor<>() { + bootstrap.configuration() + .threadNum(cpuNum + 2) + .bannerEnabled(false) + .readBufferSize(1024 * 4) + .writeBufferSize(1024 * 4) + .readMemoryPool(16384 * 1024 * 4) + .writeMemoryPool(10 * 1024 * 1024 * (cpuNum + 2), cpuNum + 2) + .messageProcessor(processor -> new AbstractMessageProcessor<>() { @Override public void process0(AioSession session, Request msg) { processor.process(session, msg); @@ -63,6 +59,14 @@ public void process0(AioSession session, Request msg) { public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { processor.stateEvent(session, stateMachineEnum, throwable); } - }).start(); + }); + bootstrap.setPort(8080) + .pipeline(new HttpServerHandle() { + @Override + public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + containerRuntime.doHandle(request, response); + } + }) + .start(); } } From e9e77413ed6c97d6007f05086e5197bfd4d2ba4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Tue, 23 Feb 2021 11:20:32 +0800 Subject: [PATCH 09/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/smartboot/http/Bootstrap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index f18b4f9e14e..04f80544d4b 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -73,7 +73,7 @@ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, T processor.stateEvent(session, stateMachineEnum, throwable); } }); - bootstrap.setPort(8080).start(); + bootstrap.pipeline(routeHandle).setPort(8080).start(); } private static void initDB(HttpRouteHandle routeHandle) { From 34ce1b268d5c33b664f34d28ab79260f56496f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 3 Mar 2021 14:12:18 +0800 Subject: [PATCH 10/53] update smart-socket to 1.5.6 --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 6fafddf107c..3f4fcf669ca 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -13,7 +13,7 @@ 2.11.0 1.0.4-SNAPSHOT 0.1.3-SNAPSHOT - 1.5.6-SNAPSHOT + 1.5.6 From b708443dbec32c45f204f436fa58cb7e3d280c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 3 Mar 2021 14:36:34 +0800 Subject: [PATCH 11/53] config threadNum --- .../src/main/java/org/smartboot/http/Bootstrap.java | 4 ++-- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 04f80544d4b..85c6d89aaef 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -57,11 +57,11 @@ public void doHandle(HttpRequest request, HttpResponse response) throws IOExcept // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); bootstrap.configuration() - .threadNum(cpuNum + 2) + .threadNum(cpuNum) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * (cpuNum + 2), cpuNum + 2) + .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum) .messageProcessor(processor -> new AbstractMessageProcessor<>() { @Override public void process0(AioSession session, Request msg) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index c1f58f5c1bc..163fc8f5326 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -43,12 +43,12 @@ public static void main(String[] args) { // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); bootstrap.configuration() - .threadNum(cpuNum + 2) + .threadNum(cpuNum) .bannerEnabled(false) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * (cpuNum + 2), cpuNum + 2) + .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum) .messageProcessor(processor -> new AbstractMessageProcessor<>() { @Override public void process0(AioSession session, Request msg) { From 5f5beea5091826dd692a5f2f6da93e27ebb9e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 17 Mar 2021 16:21:42 +0800 Subject: [PATCH 12/53] update smart-socket to 1.5.7-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 3f4fcf669ca..42c144e4caf 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -13,7 +13,7 @@ 2.11.0 1.0.4-SNAPSHOT 0.1.3-SNAPSHOT - 1.5.6 + 1.5.7-SNAPSHOT From 30734b3504020977d60e31c72d78ec71417e2af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 26 May 2021 19:19:33 +0800 Subject: [PATCH 13/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smart-socket/src/main/java/org/smartboot/http/JsonUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 0b507e9142d..d8491ef6118 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -19,7 +19,6 @@ public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { try { stream.reset(null); stream.writeVal(obj.getClass(), obj); - stream.buffer(); Slice slice = stream.buffer(); httpResponse.setContentLength(slice.tail()); httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); From e4e2a72ae8c88b5605cdf400c3dff0c026c8429b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 4 Jun 2021 11:29:53 +0800 Subject: [PATCH 14/53] update smart-socket to 1.5.10-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 4 ++-- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 42c144e4caf..096b64b0123 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -12,8 +12,8 @@ 11 2.11.0 1.0.4-SNAPSHOT - 0.1.3-SNAPSHOT - 1.5.7-SNAPSHOT + 0.1.5-SNAPSHOT + 1.5.10-SNAPSHOT diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 163fc8f5326..b589d5e1720 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -24,7 +24,7 @@ public static void main(String[] args) { ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext - ApplicationRuntime applicationRuntime = new ApplicationRuntime("/"); + ServletContextRuntime applicationRuntime = new ServletContextRuntime("/"); ServletInfo plainTextServletInfo = new ServletInfo(); plainTextServletInfo.setServletName("plaintext"); plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName()); From 6ef1f6cea3acce1b40888bea0455416c6100eeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 4 Jun 2021 13:51:49 +0800 Subject: [PATCH 15/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smart-socket/src/main/java/org/smartboot/http/JsonUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index d8491ef6118..20e0ebcc5b8 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -34,7 +34,6 @@ public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) try { stream.reset(null); stream.writeVal(obj.getClass(), obj); - stream.buffer(); Slice slice = stream.buffer(); httpResponse.setContentLength(slice.tail()); httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); From b92bd1a508fb3b87791d5409f70b4875e06d2205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 10 Jun 2021 21:01:21 +0800 Subject: [PATCH 16/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/smartboot/http/Bootstrap.java | 16 ++++++++-------- .../smartboot/http/MultipleQueriesHandler.java | 6 +++--- .../org/smartboot/http/SingleQueryHandler.java | 6 +++--- .../java/org/smartboot/http/UpdateHandler.java | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 85c6d89aaef..267a03dde42 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -15,8 +15,8 @@ import org.smartboot.http.server.HttpBootstrap; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; -import org.smartboot.http.server.handle.HttpRouteHandle; +import org.smartboot.http.server.HttpServerHandler; +import org.smartboot.http.server.handler.HttpRouteHandler; import org.smartboot.http.server.impl.Request; import org.smartboot.socket.StateMachineEnum; import org.smartboot.socket.extension.processor.AbstractMessageProcessor; @@ -31,22 +31,22 @@ public class Bootstrap { public static void main(String[] args) { System.setProperty("java.nio.channels.spi.AsynchronousChannelProvider", EnhanceAsynchronousChannelProvider.class.getName()); - HttpRouteHandle routeHandle = new HttpRouteHandle(); + HttpRouteHandler routeHandle = new HttpRouteHandler(); routeHandle - .route("/plaintext", new HttpServerHandle() { + .route("/plaintext", new HttpServerHandler() { @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + public void handle(HttpRequest request, HttpResponse response) throws IOException { response.setContentLength(body.length); response.setContentType("text/plain; charset=UTF-8"); response.write(body); } }) - .route("/json", new HttpServerHandle() { + .route("/json", new HttpServerHandler() { @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + public void handle(HttpRequest request, HttpResponse response) throws IOException { response.setContentType("application/json"); JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); @@ -76,7 +76,7 @@ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, T bootstrap.pipeline(routeHandle).setPort(8080).start(); } - private static void initDB(HttpRouteHandle routeHandle) { + private static void initDB(HttpRouteHandler routeHandle) { try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index 0896790de9f..d623f3bf1de 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -3,7 +3,7 @@ import org.smartboot.http.common.utils.NumberUtils; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; +import org.smartboot.http.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; @@ -17,7 +17,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class MultipleQueriesHandler extends HttpServerHandle { +public class MultipleQueriesHandler extends HttpServerHandler { private DataSource dataSource; public MultipleQueriesHandler(DataSource dataSource) { @@ -25,7 +25,7 @@ public MultipleQueriesHandler(DataSource dataSource) { } @Override - public void doHandle(HttpRequest httpRequest, HttpResponse response) throws IOException { + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); World[] worlds = new World[queries]; try (Connection connection = dataSource.getConnection(); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index 4b15f15d516..e72f4b06433 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -2,7 +2,7 @@ import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; +import org.smartboot.http.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; @@ -16,7 +16,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class SingleQueryHandler extends HttpServerHandle { +public class SingleQueryHandler extends HttpServerHandler { private DataSource dataSource; public SingleQueryHandler(DataSource dataSource) { @@ -24,7 +24,7 @@ public SingleQueryHandler(DataSource dataSource) { } @Override - public void doHandle(HttpRequest httpRequest, HttpResponse response) throws IOException { + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { World world = new World(); try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 51477460746..065bed5a9a6 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -3,7 +3,7 @@ import org.smartboot.http.common.utils.NumberUtils; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; +import org.smartboot.http.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; @@ -18,7 +18,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class UpdateHandler extends HttpServerHandle { +public class UpdateHandler extends HttpServerHandler { private DataSource dataSource; public UpdateHandler(DataSource dataSource) { @@ -26,7 +26,7 @@ public UpdateHandler(DataSource dataSource) { } @Override - public void doHandle(HttpRequest httpRequest, HttpResponse response) throws IOException { + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); World[] worlds = new World[queries]; StringJoiner updateSql = new StringJoiner( From 48a3430cc1397e754639c16fc234fe58555cbca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 10 Jun 2021 21:07:23 +0800 Subject: [PATCH 17/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index b589d5e1720..3cc870dfbdf 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -4,7 +4,7 @@ import org.smartboot.http.server.HttpBootstrap; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandle; +import org.smartboot.http.server.HttpServerHandler; import org.smartboot.http.server.impl.Request; import org.smartboot.servlet.conf.ServletInfo; import org.smartboot.socket.StateMachineEnum; @@ -61,9 +61,9 @@ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, T } }); bootstrap.setPort(8080) - .pipeline(new HttpServerHandle() { + .pipeline(new HttpServerHandler() { @Override - public void doHandle(HttpRequest request, HttpResponse response) throws IOException { + public void handle(HttpRequest request, HttpResponse response) throws IOException { containerRuntime.doHandle(request, response); } }) From 6aae4926f737ee7586698a17172e94d098120e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Mon, 28 Jun 2021 20:33:23 +0800 Subject: [PATCH 18/53] =?UTF-8?q?=E5=BC=82=E5=B8=B8aio-enhance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 6 ------ .../src/main/java/org/smartboot/http/Bootstrap.java | 3 --- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 3 --- 3 files changed, 12 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 096b64b0123..a8b52e153ad 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,6 @@ 11 11 2.11.0 - 1.0.4-SNAPSHOT 0.1.5-SNAPSHOT 1.5.10-SNAPSHOT @@ -22,11 +21,6 @@ servlet-core ${smartservlet.version} - - org.smartboot.aio - aio-enhance - ${aio-enhance.version} - com.zaxxer HikariCP diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 267a03dde42..9d431a2787a 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -11,7 +11,6 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import org.smartboot.Message; -import org.smartboot.aio.EnhanceAsynchronousChannelProvider; import org.smartboot.http.server.HttpBootstrap; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; @@ -29,8 +28,6 @@ public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); public static void main(String[] args) { - System.setProperty("java.nio.channels.spi.AsynchronousChannelProvider", EnhanceAsynchronousChannelProvider.class.getName()); - HttpRouteHandler routeHandle = new HttpRouteHandler(); routeHandle .route("/plaintext", new HttpServerHandler() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 3cc870dfbdf..c482bbedafa 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,6 +1,5 @@ package org.smartboot.servlet; -import org.smartboot.aio.EnhanceAsynchronousChannelProvider; import org.smartboot.http.server.HttpBootstrap; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; @@ -20,8 +19,6 @@ public class Bootstrap { public static void main(String[] args) { - System.setProperty("java.nio.channels.spi.AsynchronousChannelProvider", EnhanceAsynchronousChannelProvider.class.getName()); - ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime("/"); From 83d238f0a33ccce4394c01f6be351753c23f7b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sun, 25 Jul 2021 10:42:54 +0800 Subject: [PATCH 19/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/smartboot/http/Bootstrap.java | 2 +- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 9d431a2787a..023528ae873 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -70,7 +70,7 @@ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, T processor.stateEvent(session, stateMachineEnum, throwable); } }); - bootstrap.pipeline(routeHandle).setPort(8080).start(); + bootstrap.httpHandler(routeHandle).setPort(8080).start(); } private static void initDB(HttpRouteHandler routeHandle) { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index c482bbedafa..763554df801 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -58,7 +58,7 @@ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, T } }); bootstrap.setPort(8080) - .pipeline(new HttpServerHandler() { + .httpHandler(new HttpServerHandler() { @Override public void handle(HttpRequest request, HttpResponse response) throws IOException { containerRuntime.doHandle(request, response); From 517dd69292aa4ae28c67d0dc51d82db7bbfde29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sun, 25 Jul 2021 14:39:10 +0800 Subject: [PATCH 20/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index a8b52e153ad..5dc7be1243c 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -79,6 +79,12 @@ sonatype-nexus-snapshots Sonatype Nexus Snapshots https://oss.sonatype.org/content/repositories/snapshots + + false + + + true +
From 65f27d1f1d24ae3e81c285122d93c2e73371c2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sat, 14 Aug 2021 22:05:15 +0800 Subject: [PATCH 21/53] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 5dc7be1243c..09ac77285dd 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,8 +11,8 @@ 11 11 2.11.0 - 0.1.5-SNAPSHOT - 1.5.10-SNAPSHOT + 0.1.6 + 1.5.11 From a89d3d4cfa4403519c4193cf1c93b0d110a450da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 25 Aug 2021 23:14:08 +0800 Subject: [PATCH 22/53] remove aio-pro --- frameworks/Java/smart-socket/pom.xml | 14 +------------- .../main/java/org/smartboot/http/Bootstrap.java | 1 + .../main/java/org/smartboot/servlet/Bootstrap.java | 1 + 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 09ac77285dd..5bfcb2446f5 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,8 +11,7 @@ 11 11 2.11.0 - 0.1.6 - 1.5.11 + 0.1.7-SNAPSHOT @@ -26,11 +25,6 @@ HikariCP 3.4.5 - - org.smartboot.socket - aio-pro - ${smartsocket.version} - com.jsoniter jsoniter @@ -79,12 +73,6 @@ sonatype-nexus-snapshots Sonatype Nexus Snapshots https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 023528ae873..8ffea7a118f 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -55,6 +55,7 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio HttpBootstrap bootstrap = new HttpBootstrap(); bootstrap.configuration() .threadNum(cpuNum) + .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 763554df801..0f1985cb01b 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -42,6 +42,7 @@ public static void main(String[] args) { bootstrap.configuration() .threadNum(cpuNum) .bannerEnabled(false) + .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) From cbddd2c2526f144404a2fa1532f128e1488c1c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 30 Sep 2021 17:49:02 +0800 Subject: [PATCH 23/53] remove headerLimiter --- .../java/org/smartboot/http/Bootstrap.java | 18 +----------------- .../java/org/smartboot/servlet/Bootstrap.java | 14 +------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 8ffea7a118f..3d26a672e59 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -16,10 +16,6 @@ import org.smartboot.http.server.HttpResponse; import org.smartboot.http.server.HttpServerHandler; import org.smartboot.http.server.handler.HttpRouteHandler; -import org.smartboot.http.server.impl.Request; -import org.smartboot.socket.StateMachineEnum; -import org.smartboot.socket.extension.processor.AbstractMessageProcessor; -import org.smartboot.socket.transport.AioSession; import javax.sql.DataSource; import java.io.IOException; @@ -55,22 +51,10 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio HttpBootstrap bootstrap = new HttpBootstrap(); bootstrap.configuration() .threadNum(cpuNum) - .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum) - .messageProcessor(processor -> new AbstractMessageProcessor<>() { - @Override - public void process0(AioSession session, Request msg) { - processor.process(session, msg); - } - - @Override - public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { - processor.stateEvent(session, stateMachineEnum, throwable); - } - }); + .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum); bootstrap.httpHandler(routeHandle).setPort(8080).start(); } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 0f1985cb01b..a8fd3d35396 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -42,22 +42,10 @@ public static void main(String[] args) { bootstrap.configuration() .threadNum(cpuNum) .bannerEnabled(false) - .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum) - .messageProcessor(processor -> new AbstractMessageProcessor<>() { - @Override - public void process0(AioSession session, Request msg) { - processor.process(session, msg); - } - - @Override - public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) { - processor.stateEvent(session, stateMachineEnum, throwable); - } - }); + .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum); bootstrap.setPort(8080) .httpHandler(new HttpServerHandler() { @Override From 73bd7b399c5011cf84bc0c67df2ee6fac0f46eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 9 Dec 2021 10:38:25 +0800 Subject: [PATCH 24/53] update hikaricp version --- frameworks/Java/smart-socket/pom.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 5bfcb2446f5..e71c9d8972c 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -12,6 +12,8 @@ 11 2.11.0 0.1.7-SNAPSHOT + 5.0.0 + 0.9.23 @@ -23,12 +25,12 @@ com.zaxxer HikariCP - 3.4.5 + ${hikaricp.version} com.jsoniter jsoniter - 0.9.23 + ${jsoniter.version} org.apache.logging.log4j From 5a963940e6b26c4f701c2305af5e1b6ce49d5c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Sat, 22 Jan 2022 13:43:19 +0800 Subject: [PATCH 25/53] replace json util --- frameworks/Java/smart-socket/pom.xml | 5 ++ .../java/org/smartboot/http/JsonUtil.java | 61 +++++++++++++------ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index e71c9d8972c..3c8f5afa3f3 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -17,6 +17,11 @@ + + io.edap + edapx-json + 0.1-SNAPSHOT + org.smartboot.servlet servlet-core diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 20e0ebcc5b8..0aa0f44a2d1 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -1,9 +1,8 @@ package org.smartboot.http; -import com.jsoniter.output.JsonStream; -import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; -import com.jsoniter.spi.Slice; +import io.edap.x.json.Eson; +import io.edap.x.json.JsonWriter; import org.smartboot.http.server.HttpResponse; import javax.servlet.http.HttpServletResponse; @@ -15,32 +14,56 @@ */ public class JsonUtil { public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { - JsonStream stream = JsonStreamPool.borrowJsonStream(); + JsonWriter writer = Eson.THREAD_WRITER.get(); try { - stream.reset(null); - stream.writeVal(obj.getClass(), obj); - Slice slice = stream.buffer(); - httpResponse.setContentLength(slice.tail()); - httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); + writer.reset(); + Eson.serialize(obj, writer); + httpResponse.setContentLength(writer.size()); + writer.toStream(httpResponse.getOutputStream()); } catch (IOException e) { throw new JsonException(e); - } finally { - JsonStreamPool.returnJsonStream(stream); } } +// public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { +// JsonStream stream = JsonStreamPool.borrowJsonStream(); +// try { +// stream.reset(null); +// stream.writeVal(obj.getClass(), obj); +// Slice slice = stream.buffer(); +// httpResponse.setContentLength(slice.tail()); +// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); +// } catch (IOException e) { +// throw new JsonException(e); +// } finally { +// JsonStreamPool.returnJsonStream(stream); +// } +// } + +// public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { +// JsonStream stream = JsonStreamPool.borrowJsonStream(); +// try { +// stream.reset(null); +// stream.writeVal(obj.getClass(), obj); +// Slice slice = stream.buffer(); +// httpResponse.setContentLength(slice.tail()); +// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); +// } catch (IOException e) { +// throw new JsonException(e); +// } finally { +// JsonStreamPool.returnJsonStream(stream); +// } +// } + public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { - JsonStream stream = JsonStreamPool.borrowJsonStream(); + JsonWriter writer = Eson.THREAD_WRITER.get(); try { - stream.reset(null); - stream.writeVal(obj.getClass(), obj); - Slice slice = stream.buffer(); - httpResponse.setContentLength(slice.tail()); - httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); + writer.reset(); + Eson.serialize(obj, writer); + httpResponse.setContentLength(writer.size()); + writer.toStream(httpResponse.getOutputStream()); } catch (IOException e) { throw new JsonException(e); - } finally { - JsonStreamPool.returnJsonStream(stream); } } } From c882c082563fd6d895491259a7c8b9f4cfaee2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Mon, 21 Nov 2022 10:57:04 +0800 Subject: [PATCH 26/53] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/smartboot/http/Bootstrap.java | 22 ++++++++++++++----- .../java/org/smartboot/servlet/Bootstrap.java | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 3d26a672e59..a4acd4df6b7 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -19,11 +19,19 @@ import javax.sql.DataSource; import java.io.IOException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); public static void main(String[] args) { + ExecutorService executorService = new ThreadPoolExecutor(1, 1, + 0L, TimeUnit.MILLISECONDS, + new ArrayBlockingQueue<>(128), new ThreadPoolExecutor.CallerRunsPolicy()); HttpRouteHandler routeHandle = new HttpRouteHandler(); routeHandle .route("/plaintext", new HttpServerHandler() { @@ -37,12 +45,16 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio } }) .route("/json", new HttpServerHandler() { - @Override - public void handle(HttpRequest request, HttpResponse response) throws IOException { - - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); + public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { + executorService.execute(() -> { + try { + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); + } finally { + completableFuture.complete(null); + } + }); } }); initDB(routeHandle); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index a8fd3d35396..23efbecbd3f 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -35,7 +35,7 @@ public static void main(String[] args) { jsonServletInfo.addMapping("/json"); applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); containerRuntime.addRuntime(applicationRuntime); - containerRuntime.start(); + int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); @@ -46,6 +46,7 @@ public static void main(String[] args) { .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum); + containerRuntime.start(bootstrap.configuration()); bootstrap.setPort(8080) .httpHandler(new HttpServerHandler() { @Override From 2f49faa21d7702789807b599e079940fcc4389d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Tue, 22 Nov 2022 13:21:58 +0800 Subject: [PATCH 27/53] upgrade smart-servlet to 0.1.9-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 1c48ccf3ea4..4f192131ac4 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 11 11 2.17.1 - 0.1.7-SNAPSHOT + 0.1.9-SNAPSHOT 5.0.0 0.9.23 From 000034778069927c9ca91b1c1712c0f366292509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 27 Jan 2023 15:35:43 +0800 Subject: [PATCH 28/53] config thread num --- .../src/main/java/org/smartboot/http/Bootstrap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index a4acd4df6b7..5447ca24445 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -29,7 +29,7 @@ public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); public static void main(String[] args) { - ExecutorService executorService = new ThreadPoolExecutor(1, 1, + ExecutorService executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(), 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(128), new ThreadPoolExecutor.CallerRunsPolicy()); HttpRouteHandler routeHandle = new HttpRouteHandler(); From b26a9446995b718e135c495573856ad83277c8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 27 Jan 2023 15:46:27 +0800 Subject: [PATCH 29/53] config thread num --- .../java/org/smartboot/http/Bootstrap.java | 10 +-- .../http/MultipleQueriesHandler.java | 54 +++++++------ .../smartboot/http/SingleQueryHandler.java | 41 ++++++---- .../org/smartboot/http/UpdateHandler.java | 78 +++++++++++-------- 4 files changed, 107 insertions(+), 76 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 5447ca24445..c44f67335b0 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -57,7 +57,7 @@ public void handle(HttpRequest request, HttpResponse response, CompletableFuture }); } }); - initDB(routeHandle); + initDB(routeHandle,executorService); int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); @@ -70,7 +70,7 @@ public void handle(HttpRequest request, HttpResponse response, CompletableFuture bootstrap.httpHandler(routeHandle).setPort(8080).start(); } - private static void initDB(HttpRouteHandler routeHandle) { + private static void initDB(HttpRouteHandler routeHandle,ExecutorService executorService) { try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { @@ -85,9 +85,9 @@ private static void initDB(HttpRouteHandler routeHandle) { config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); DataSource dataSource = new HikariDataSource(config); - routeHandle.route("/db", new SingleQueryHandler(dataSource)) - .route("/queries", new MultipleQueriesHandler(dataSource)) - .route("/updates", new UpdateHandler(dataSource)); + routeHandle.route("/db", new SingleQueryHandler(dataSource,executorService)) + .route("/queries", new MultipleQueriesHandler(dataSource,executorService)) + .route("/updates", new UpdateHandler(dataSource,executorService)); // .route("/fortunes", new FortunesHandler(dataSource)); } } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index d623f3bf1de..d411f813ac1 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -11,6 +11,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -19,34 +21,42 @@ */ public class MultipleQueriesHandler extends HttpServerHandler { private DataSource dataSource; + private ExecutorService executorService; - public MultipleQueriesHandler(DataSource dataSource) { + public MultipleQueriesHandler(DataSource dataSource, ExecutorService executorService) { this.dataSource = dataSource; + this.executorService = executorService; } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); - World[] worlds = new World[queries]; - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - - for (int i = 0; i < queries; i++) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - World world = new World(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - worlds[i] = world; - preparedStatement.clearParameters(); - } + public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { + executorService.execute(() -> { + try { + int queries = Math.min(Math.max(NumberUtils.toInt(request.getParameter("queries"), 1), 1), 500); + World[] worlds = new World[queries]; + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + + for (int i = 0; i < queries; i++) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + World world = new World(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + worlds[i] = world; + preparedStatement.clearParameters(); + } - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, worlds); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, worlds); + } finally { + completableFuture.complete(null); + } + }); } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index e72f4b06433..c531a161ca4 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -10,6 +10,8 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -19,25 +21,34 @@ public class SingleQueryHandler extends HttpServerHandler { private DataSource dataSource; - public SingleQueryHandler(DataSource dataSource) { + private ExecutorService executorService; + + public SingleQueryHandler(DataSource dataSource, ExecutorService executorService) { this.dataSource = dataSource; + this.executorService = executorService; } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - World world = new World(); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, world); + public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { + executorService.execute(() -> { + try { + World world = new World(); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, world); + } finally { + completableFuture.complete(null); + } + }); } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 065bed5a9a6..7b81f2e8772 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -12,6 +12,8 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.StringJoiner; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -20,49 +22,57 @@ */ public class UpdateHandler extends HttpServerHandler { private DataSource dataSource; + private ExecutorService executorService; - public UpdateHandler(DataSource dataSource) { + public UpdateHandler(DataSource dataSource, ExecutorService executorService) { this.dataSource = dataSource; + this.executorService = executorService; } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); - World[] worlds = new World[queries]; - StringJoiner updateSql = new StringJoiner( - ", ", - "UPDATE world SET randomnumber = temp.randomnumber FROM (VALUES ", - " ORDER BY 1) AS temp(id, randomnumber) WHERE temp.id = world.id"); - try (Connection connection = dataSource.getConnection()) { + public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { + executorService.execute(() -> { + try { + int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); + World[] worlds = new World[queries]; + StringJoiner updateSql = new StringJoiner( + ", ", + "UPDATE world SET randomnumber = temp.randomnumber FROM (VALUES ", + " ORDER BY 1) AS temp(id, randomnumber) WHERE temp.id = world.id"); + try (Connection connection = dataSource.getConnection()) { - try (PreparedStatement queryPreparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - for (int i = 0; i < queries; i++) { - queryPreparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = queryPreparedStatement.executeQuery(); - resultSet.next(); - World world = new World(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(getRandomNumber()); - worlds[i] = world; - queryPreparedStatement.clearParameters(); - updateSql.add("(?, ?)"); - } - } + try (PreparedStatement queryPreparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + for (int i = 0; i < queries; i++) { + queryPreparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = queryPreparedStatement.executeQuery(); + resultSet.next(); + World world = new World(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(getRandomNumber()); + worlds[i] = world; + queryPreparedStatement.clearParameters(); + updateSql.add("(?, ?)"); + } + } - try (PreparedStatement preparedStatement = connection.prepareStatement(updateSql.toString());) { - int i = 0; - for (World world : worlds) { - preparedStatement.setInt(++i, world.getId()); - preparedStatement.setInt(++i, world.getRandomNumber()); + try (PreparedStatement preparedStatement = connection.prepareStatement(updateSql.toString());) { + int i = 0; + for (World world : worlds) { + preparedStatement.setInt(++i, world.getId()); + preparedStatement.setInt(++i, world.getRandomNumber()); + } + preparedStatement.executeUpdate(); + } + + } catch (SQLException throwables) { + throwables.printStackTrace(); } - preparedStatement.executeUpdate(); + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, worlds); + } finally { + completableFuture.complete(null); } - - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, worlds); + }); } protected int getRandomNumber() { From 5418509d3ca2c671ef7a6f27f27e91419a1a0e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 9 Feb 2023 20:52:36 +0800 Subject: [PATCH 30/53] revert code --- .../java/org/smartboot/http/Bootstrap.java | 32 +++----- .../http/MultipleQueriesHandler.java | 54 ++++++------- .../smartboot/http/SingleQueryHandler.java | 41 ++++------ .../org/smartboot/http/UpdateHandler.java | 78 ++++++++----------- 4 files changed, 81 insertions(+), 124 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index c44f67335b0..bfa60e03af5 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -19,19 +19,11 @@ import javax.sql.DataSource; import java.io.IOException; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); public static void main(String[] args) { - ExecutorService executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(), - 0L, TimeUnit.MILLISECONDS, - new ArrayBlockingQueue<>(128), new ThreadPoolExecutor.CallerRunsPolicy()); HttpRouteHandler routeHandle = new HttpRouteHandler(); routeHandle .route("/plaintext", new HttpServerHandler() { @@ -45,19 +37,15 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio } }) .route("/json", new HttpServerHandler() { + @Override - public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { - executorService.execute(() -> { - try { - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); - } finally { - completableFuture.complete(null); - } - }); + public void handle(HttpRequest request, HttpResponse response) throws IOException { + + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); } }); - initDB(routeHandle,executorService); +// initDB(routeHandle); int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); @@ -70,7 +58,7 @@ public void handle(HttpRequest request, HttpResponse response, CompletableFuture bootstrap.httpHandler(routeHandle).setPort(8080).start(); } - private static void initDB(HttpRouteHandler routeHandle,ExecutorService executorService) { + private static void initDB(HttpRouteHandler routeHandle) { try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { @@ -85,9 +73,9 @@ private static void initDB(HttpRouteHandler routeHandle,ExecutorService executor config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); DataSource dataSource = new HikariDataSource(config); - routeHandle.route("/db", new SingleQueryHandler(dataSource,executorService)) - .route("/queries", new MultipleQueriesHandler(dataSource,executorService)) - .route("/updates", new UpdateHandler(dataSource,executorService)); + routeHandle.route("/db", new SingleQueryHandler(dataSource)) + .route("/queries", new MultipleQueriesHandler(dataSource)) + .route("/updates", new UpdateHandler(dataSource)); // .route("/fortunes", new FortunesHandler(dataSource)); } } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index d411f813ac1..d623f3bf1de 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -11,8 +11,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -21,42 +19,34 @@ */ public class MultipleQueriesHandler extends HttpServerHandler { private DataSource dataSource; - private ExecutorService executorService; - public MultipleQueriesHandler(DataSource dataSource, ExecutorService executorService) { + public MultipleQueriesHandler(DataSource dataSource) { this.dataSource = dataSource; - this.executorService = executorService; } @Override - public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { - executorService.execute(() -> { - try { - int queries = Math.min(Math.max(NumberUtils.toInt(request.getParameter("queries"), 1), 1), 500); - World[] worlds = new World[queries]; - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - - for (int i = 0; i < queries; i++) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - World world = new World(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - worlds[i] = world; - preparedStatement.clearParameters(); - } - - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, worlds); - } finally { - completableFuture.complete(null); + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { + int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); + World[] worlds = new World[queries]; + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + + for (int i = 0; i < queries; i++) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + World world = new World(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + worlds[i] = world; + preparedStatement.clearParameters(); } - }); + + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, worlds); } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index c531a161ca4..e72f4b06433 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -10,8 +10,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -21,34 +19,25 @@ public class SingleQueryHandler extends HttpServerHandler { private DataSource dataSource; - private ExecutorService executorService; - - public SingleQueryHandler(DataSource dataSource, ExecutorService executorService) { + public SingleQueryHandler(DataSource dataSource) { this.dataSource = dataSource; - this.executorService = executorService; } @Override - public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws IOException { - executorService.execute(() -> { - try { - World world = new World(); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, world); - } finally { - completableFuture.complete(null); - } - }); + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { + World world = new World(); + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, world); } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 7b81f2e8772..065bed5a9a6 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -12,8 +12,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.StringJoiner; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadLocalRandom; /** @@ -22,57 +20,49 @@ */ public class UpdateHandler extends HttpServerHandler { private DataSource dataSource; - private ExecutorService executorService; - public UpdateHandler(DataSource dataSource, ExecutorService executorService) { + public UpdateHandler(DataSource dataSource) { this.dataSource = dataSource; - this.executorService = executorService; } @Override - public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { - executorService.execute(() -> { - try { - int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); - World[] worlds = new World[queries]; - StringJoiner updateSql = new StringJoiner( - ", ", - "UPDATE world SET randomnumber = temp.randomnumber FROM (VALUES ", - " ORDER BY 1) AS temp(id, randomnumber) WHERE temp.id = world.id"); - try (Connection connection = dataSource.getConnection()) { + public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { + int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); + World[] worlds = new World[queries]; + StringJoiner updateSql = new StringJoiner( + ", ", + "UPDATE world SET randomnumber = temp.randomnumber FROM (VALUES ", + " ORDER BY 1) AS temp(id, randomnumber) WHERE temp.id = world.id"); + try (Connection connection = dataSource.getConnection()) { - try (PreparedStatement queryPreparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - for (int i = 0; i < queries; i++) { - queryPreparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = queryPreparedStatement.executeQuery(); - resultSet.next(); - World world = new World(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(getRandomNumber()); - worlds[i] = world; - queryPreparedStatement.clearParameters(); - updateSql.add("(?, ?)"); - } - } - - try (PreparedStatement preparedStatement = connection.prepareStatement(updateSql.toString());) { - int i = 0; - for (World world : worlds) { - preparedStatement.setInt(++i, world.getId()); - preparedStatement.setInt(++i, world.getRandomNumber()); - } - preparedStatement.executeUpdate(); - } + try (PreparedStatement queryPreparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + for (int i = 0; i < queries; i++) { + queryPreparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = queryPreparedStatement.executeQuery(); + resultSet.next(); + World world = new World(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(getRandomNumber()); + worlds[i] = world; + queryPreparedStatement.clearParameters(); + updateSql.add("(?, ?)"); + } + } - } catch (SQLException throwables) { - throwables.printStackTrace(); + try (PreparedStatement preparedStatement = connection.prepareStatement(updateSql.toString());) { + int i = 0; + for (World world : worlds) { + preparedStatement.setInt(++i, world.getId()); + preparedStatement.setInt(++i, world.getRandomNumber()); } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, worlds); - } finally { - completableFuture.complete(null); + preparedStatement.executeUpdate(); } - }); + + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, worlds); } protected int getRandomNumber() { From 500ae8d1629c48828ac9e5398fc8816260bfbdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Thu, 9 Feb 2023 20:52:51 +0800 Subject: [PATCH 31/53] revert code --- .../src/main/java/org/smartboot/http/Bootstrap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index bfa60e03af5..3d26a672e59 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -45,7 +45,7 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); } }); -// initDB(routeHandle); + initDB(routeHandle); int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); From 3ff91b6431ac612a86a25b1c79ab41ab6b76db57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Wed, 3 May 2023 11:56:44 +0800 Subject: [PATCH 32/53] upgrade smart-servlet to 0.2.1-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 275e01c1900..e4bbc87e873 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 11 11 2.17.1 - 0.1.9-SNAPSHOT + 0.2.1-SNAPSHOT 5.0.0 0.9.23 From 916684b5cdfba4840de8fd4f268904dc4e0dfd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 18:57:10 +0800 Subject: [PATCH 33/53] upgrade smart-servlet to 0.6-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 6 +++--- frameworks/Java/smart-socket/smart-socket.dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index e4bbc87e873..81fbc295b98 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -8,10 +8,10 @@ jar UTF-8 - 11 - 11 + 17 + 17 2.17.1 - 0.2.1-SNAPSHOT + 0.6-SNAPSHOT 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/smart-socket.dockerfile b/frameworks/Java/smart-socket/smart-socket.dockerfile index f51ddcbd178..15c6cd7ca08 100644 --- a/frameworks/Java/smart-socket/smart-socket.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket.dockerfile @@ -1,10 +1,10 @@ -FROM maven:3.6.1-jdk-11-slim as maven +FROM maven:3.8.6-openjdk-18-slim as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src RUN mvn compile assembly:single -q -FROM openjdk:11.0.3-jdk-slim +FROM openjdk:21-jdk-slim WORKDIR /smart-socket COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-dependencies.jar app.jar From f6daf6fde64929be0169c2907867336def764196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 19:06:48 +0800 Subject: [PATCH 34/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../Java/smart-socket/smart-socket-smart-servlet.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile index b6fa2e31680..c6613b444d4 100644 --- a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile @@ -1,10 +1,10 @@ -FROM maven:3.6.1-jdk-11-slim as maven +FROM maven:3.8.6-openjdk-18-slim as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src RUN mvn compile assembly:single -q -FROM openjdk:11.0.3-jdk-slim +FROM openjdk:21-jdk-slim WORKDIR /smart-socket COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-dependencies.jar app.jar From f82b12e1755de22185d131ebf88459f270d7f553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 19:16:27 +0800 Subject: [PATCH 35/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../src/main/java/org/smartboot/http/JsonUtil.java | 2 +- .../main/java/org/smartboot/servlet/Bootstrap.java | 12 ++++-------- .../org/smartboot/servlet/HelloWorldServlet.java | 9 +++++---- .../main/java/org/smartboot/servlet/JsonServlet.java | 8 ++++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 0aa0f44a2d1..e2cd6e33cc7 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -3,9 +3,9 @@ import com.jsoniter.spi.JsonException; import io.edap.x.json.Eson; import io.edap.x.json.JsonWriter; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.http.server.HttpResponse; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 23efbecbd3f..681ad1a7593 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -4,13 +4,9 @@ import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; import org.smartboot.http.server.HttpServerHandler; -import org.smartboot.http.server.impl.Request; import org.smartboot.servlet.conf.ServletInfo; -import org.smartboot.socket.StateMachineEnum; -import org.smartboot.socket.extension.processor.AbstractMessageProcessor; -import org.smartboot.socket.transport.AioSession; -import java.io.IOException; +import java.util.concurrent.CompletableFuture; /** * @author 三刀(zhengjunweimail@163.com) @@ -18,7 +14,7 @@ */ public class Bootstrap { - public static void main(String[] args) { + public static void main(String[] args) throws Throwable { ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime("/"); @@ -50,8 +46,8 @@ public static void main(String[] args) { bootstrap.setPort(8080) .httpHandler(new HttpServerHandler() { @Override - public void handle(HttpRequest request, HttpResponse response) throws IOException { - containerRuntime.doHandle(request, response); + public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws Throwable { + containerRuntime.doHandle(request, response, completableFuture); } }) .start(); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java index f5c2ca710c6..10ec6563a98 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java @@ -1,9 +1,10 @@ package org.smartboot.servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java index 1c0081d7f23..9afb0e7ad61 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java @@ -1,12 +1,12 @@ package org.smartboot.servlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.Message; import org.smartboot.http.JsonUtil; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** From abcb2bd6881403ab371a6d2dff052ab72a6c7110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 19:37:20 +0800 Subject: [PATCH 36/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../Java/smart-socket/smart-socket-smart-servlet.dockerfile | 2 +- frameworks/Java/smart-socket/smart-socket.dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile index c6613b444d4..8b1cbe79930 100644 --- a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile @@ -10,4 +10,4 @@ COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-depen EXPOSE 8080 -CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-cp", "app.jar", "org.smartboot.servlet.Bootstrap"] +CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-cp", "app.jar", "org.smartboot.servlet.Bootstrap"] diff --git a/frameworks/Java/smart-socket/smart-socket.dockerfile b/frameworks/Java/smart-socket/smart-socket.dockerfile index 15c6cd7ca08..b40ad2c8d43 100644 --- a/frameworks/Java/smart-socket/smart-socket.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket.dockerfile @@ -10,4 +10,4 @@ COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-depen EXPOSE 8080 -CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-cp", "app.jar", "org.smartboot.http.Bootstrap"] +CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-cp", "app.jar", "org.smartboot.http.Bootstrap"] From 817bc2e9e523bbbc802add6c2e5445ea971a9b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 20:31:15 +0800 Subject: [PATCH 37/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../java/org/smartboot/http/JsonUtil.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index e2cd6e33cc7..b20525ec571 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -1,8 +1,9 @@ package org.smartboot.http; +import com.jsoniter.output.JsonStream; +import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; -import io.edap.x.json.Eson; -import io.edap.x.json.JsonWriter; +import com.jsoniter.spi.Slice; import jakarta.servlet.http.HttpServletResponse; import org.smartboot.http.server.HttpResponse; @@ -13,57 +14,56 @@ * @version V1.0 , 2020/6/16 */ public class JsonUtil { + // public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { +// JsonWriter writer = Eson.THREAD_WRITER.get(); +// try { +// writer.reset(); +// Eson.serialize(obj, writer); +// httpResponse.setContentLength(writer.size()); +// writer.toStream(httpResponse.getOutputStream()); +// } catch (IOException e) { +// throw new JsonException(e); +// } +// } public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { - JsonWriter writer = Eson.THREAD_WRITER.get(); + JsonStream stream = JsonStreamPool.borrowJsonStream(); try { - writer.reset(); - Eson.serialize(obj, writer); - httpResponse.setContentLength(writer.size()); - writer.toStream(httpResponse.getOutputStream()); + stream.reset(null); + stream.writeVal(obj.getClass(), obj); + Slice slice = stream.buffer(); + httpResponse.setContentLength(slice.tail()); + httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); } catch (IOException e) { throw new JsonException(e); + } finally { + JsonStreamPool.returnJsonStream(stream); } } -// public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { -// JsonStream stream = JsonStreamPool.borrowJsonStream(); -// try { -// stream.reset(null); -// stream.writeVal(obj.getClass(), obj); -// Slice slice = stream.buffer(); -// httpResponse.setContentLength(slice.tail()); -// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); -// } catch (IOException e) { -// throw new JsonException(e); -// } finally { -// JsonStreamPool.returnJsonStream(stream); -// } -// } + public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { + JsonStream stream = JsonStreamPool.borrowJsonStream(); + try { + stream.reset(null); + stream.writeVal(obj.getClass(), obj); + Slice slice = stream.buffer(); + httpResponse.setContentLength(slice.tail()); + httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); + } catch (IOException e) { + throw new JsonException(e); + } finally { + JsonStreamPool.returnJsonStream(stream); + } + } // public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { -// JsonStream stream = JsonStreamPool.borrowJsonStream(); +// JsonWriter writer = Eson.THREAD_WRITER.get(); // try { -// stream.reset(null); -// stream.writeVal(obj.getClass(), obj); -// Slice slice = stream.buffer(); -// httpResponse.setContentLength(slice.tail()); -// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); +// writer.reset(); +// Eson.serialize(obj, writer); +// httpResponse.setContentLength(writer.size()); +// writer.toStream(httpResponse.getOutputStream()); // } catch (IOException e) { // throw new JsonException(e); -// } finally { -// JsonStreamPool.returnJsonStream(stream); // } // } - - public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { - JsonWriter writer = Eson.THREAD_WRITER.get(); - try { - writer.reset(); - Eson.serialize(obj, writer); - httpResponse.setContentLength(writer.size()); - writer.toStream(httpResponse.getOutputStream()); - } catch (IOException e) { - throw new JsonException(e); - } - } } From 69c80e4a93cc05016fd34d7ac0cc7ff18ffa2e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 20:41:15 +0800 Subject: [PATCH 38/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../src/main/java/org/smartboot/servlet/HelloWorldServlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java index 10ec6563a98..c3900de716c 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java @@ -17,7 +17,7 @@ public class HelloWorldServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentLength(BODY.length); - resp.setContentType("text/plain; charset=UTF-8"); + resp.setContentType("text/plain;charset=UTF-8"); resp.setBufferSize(0); resp.getOutputStream().write(BODY); } From ed03c884c58abb6f141403988c4535389898a398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=88=80?= Date: Fri, 17 Nov 2023 20:49:02 +0800 Subject: [PATCH 39/53] upgrade smart-servlet to 0.6-SNAPSHOT --- .../src/main/java/org/smartboot/servlet/JsonServlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java index 9afb0e7ad61..064bc80556d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java @@ -16,7 +16,7 @@ public class JsonServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - resp.setContentType("application/json"); + resp.setContentType("application/json;charset=UTF-8"); resp.setBufferSize(0); JsonUtil.writeJsonBytes(resp, new Message("Hello, World!")); } From adcfa63f39ab9893a785c67bacd2dcedd36d9c16 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Wed, 3 Apr 2024 13:23:45 +0800 Subject: [PATCH 40/53] upgrade smart-servlet to 1.0-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- .../src/main/java/org/smartboot/http/JsonUtil.java | 2 +- .../java/org/smartboot/servlet/HelloWorldServlet.java | 8 ++++---- .../src/main/java/org/smartboot/servlet/JsonServlet.java | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index b95e7d71c52..376f82878f7 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 17 17 2.17.1 - 0.6-SNAPSHOT + 1.0-SNAPSHOT 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index b20525ec571..5c46d0ca5ef 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -4,9 +4,9 @@ import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; import com.jsoniter.spi.Slice; -import jakarta.servlet.http.HttpServletResponse; import org.smartboot.http.server.HttpResponse; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java index c3900de716c..6ac97cc7606 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java @@ -1,10 +1,10 @@ package org.smartboot.servlet; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java index 064bc80556d..e484da19fc3 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java @@ -1,12 +1,12 @@ package org.smartboot.servlet; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import org.smartboot.Message; import org.smartboot.http.JsonUtil; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** From 176adc514bc44655697ce92c1676ab20b95b7287 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sat, 1 Jun 2024 22:37:40 +0800 Subject: [PATCH 41/53] upgrade smart-servlet to 1.4 --- frameworks/Java/smart-socket/pom.xml | 2 +- .../src/main/java/org/smartboot/http/Bootstrap.java | 1 + .../src/main/java/org/smartboot/servlet/Bootstrap.java | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 376f82878f7..8904208b91e 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 17 17 2.17.1 - 1.0-SNAPSHOT + 1.4 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 3d26a672e59..06753113440 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -51,6 +51,7 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio HttpBootstrap bootstrap = new HttpBootstrap(); bootstrap.configuration() .threadNum(cpuNum) + .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 681ad1a7593..e92979fed49 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -17,7 +17,7 @@ public class Bootstrap { public static void main(String[] args) throws Throwable { ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext - ServletContextRuntime applicationRuntime = new ServletContextRuntime("/"); + ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/"); ServletInfo plainTextServletInfo = new ServletInfo(); plainTextServletInfo.setServletName("plaintext"); plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName()); @@ -38,6 +38,7 @@ public static void main(String[] args) throws Throwable { bootstrap.configuration() .threadNum(cpuNum) .bannerEnabled(false) + .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4) .readMemoryPool(16384 * 1024 * 4) From 36ad58b0ae3736ec3cde46b87dbd216df97fe41e Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sun, 2 Jun 2024 07:50:05 +0800 Subject: [PATCH 42/53] upgrade smart-servlet to 1.5-SNAPSHOT --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 8904208b91e..508c0fa1481 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 17 17 2.17.1 - 1.4 + 1.5-SNAPSHOT 5.0.0 0.9.23 From 41012e209497950883e1abfbd410a52dd956c4c1 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sun, 2 Jun 2024 18:07:52 +0800 Subject: [PATCH 43/53] =?UTF-8?q?=E5=90=AF=E7=94=A8=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http/MultipleQueriesHandler.java | 48 +++++++++++-------- .../smartboot/http/SingleQueryHandler.java | 35 ++++++++------ .../java/org/smartboot/servlet/Bootstrap.java | 3 ++ 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index d623f3bf1de..61b9f66b344 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -11,6 +11,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; /** @@ -25,28 +26,35 @@ public MultipleQueriesHandler(DataSource dataSource) { } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); - World[] worlds = new World[queries]; - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - - for (int i = 0; i < queries; i++) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - World world = new World(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - worlds[i] = world; - preparedStatement.clearParameters(); + public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { + Thread.startVirtualThread(() -> { + try { + int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); + World[] worlds = new World[queries]; + try (Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + + for (int i = 0; i < queries; i++) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + World world = new World(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + worlds[i] = world; + preparedStatement.clearParameters(); + } + + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, worlds); + } finally { + completableFuture.complete(null); } + }); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, worlds); } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index e72f4b06433..b69495d1a5e 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -10,6 +10,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; /** @@ -24,20 +25,26 @@ public SingleQueryHandler(DataSource dataSource) { } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - World world = new World(); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { - preparedStatement.setInt(1, getRandomNumber()); - ResultSet resultSet = preparedStatement.executeQuery(); - resultSet.next(); - world.setId(resultSet.getInt(1)); - world.setRandomNumber(resultSet.getInt(2)); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, world); + public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { + Thread.startVirtualThread(() -> { + try { + World world = new World(); + try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM World WHERE id=?");) { + preparedStatement.setInt(1, getRandomNumber()); + ResultSet resultSet = preparedStatement.executeQuery(); + resultSet.next(); + world.setId(resultSet.getInt(1)); + world.setRandomNumber(resultSet.getInt(2)); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, world); + } finally { + completableFuture.complete(null); + } + }); + } protected int getRandomNumber() { diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index e92979fed49..b6691bfd359 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -18,6 +18,9 @@ public static void main(String[] args) throws Throwable { ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/"); + applicationRuntime.setVendorProvider(response -> { + + }); ServletInfo plainTextServletInfo = new ServletInfo(); plainTextServletInfo.setServletName("plaintext"); plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName()); From 289be6b618dfef02ff9b4453dc947fb0584c185f Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sun, 2 Jun 2024 18:19:15 +0800 Subject: [PATCH 44/53] =?UTF-8?q?=E5=90=AF=E7=94=A8=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 4 ++-- .../Java/smart-socket/smart-socket-smart-servlet.dockerfile | 2 +- frameworks/Java/smart-socket/smart-socket.dockerfile | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 508c0fa1481..239721f8cba 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -8,8 +8,8 @@ jar UTF-8 - 17 - 17 + 21 + 21 2.17.1 1.5-SNAPSHOT 5.0.0 diff --git a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile index 8b1cbe79930..bb0b9258ec4 100644 --- a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile @@ -1,4 +1,4 @@ -FROM maven:3.8.6-openjdk-18-slim as maven +FROM maven:3.9.7-amazoncorretto-21 as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src diff --git a/frameworks/Java/smart-socket/smart-socket.dockerfile b/frameworks/Java/smart-socket/smart-socket.dockerfile index b40ad2c8d43..4890bd04a06 100644 --- a/frameworks/Java/smart-socket/smart-socket.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket.dockerfile @@ -1,4 +1,4 @@ -FROM maven:3.8.6-openjdk-18-slim as maven +FROM maven:3.9.7-amazoncorretto-21 as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src From 75844297ee70379ecd306da382c3de5671eded84 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Mon, 11 Nov 2024 14:00:19 +0800 Subject: [PATCH 45/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 4 ++-- .../src/main/java/org/smartboot/http/JsonUtil.java | 2 +- .../main/java/org/smartboot/servlet/Bootstrap.java | 12 ++++++++---- .../org/smartboot/servlet/HelloWorldServlet.java | 9 +++++---- .../main/java/org/smartboot/servlet/JsonServlet.java | 8 ++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 239721f8cba..39a47cc3c1e 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 1.5-SNAPSHOT + 2.3 5.0.0 0.9.23 @@ -23,7 +23,7 @@ 0.1-SNAPSHOT - org.smartboot.servlet + tech.smartboot.servlet servlet-core ${smartservlet.version} diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 5c46d0ca5ef..b20525ec571 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -4,9 +4,9 @@ import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; import com.jsoniter.spi.Slice; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.http.server.HttpResponse; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index b6691bfd359..f4458e0a6e6 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,10 +1,14 @@ package org.smartboot.servlet; + import org.smartboot.http.server.HttpBootstrap; import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; import org.smartboot.http.server.HttpServerHandler; -import org.smartboot.servlet.conf.ServletInfo; +import tech.smartboot.servlet.Container; +import tech.smartboot.servlet.ServletContextRuntime; +import tech.smartboot.servlet.conf.ServletInfo; +import tech.smartboot.servlet.conf.ServletMappingInfo; import java.util.concurrent.CompletableFuture; @@ -15,7 +19,7 @@ public class Bootstrap { public static void main(String[] args) throws Throwable { - ContainerRuntime containerRuntime = new ContainerRuntime(); + Container containerRuntime = new Container(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/"); applicationRuntime.setVendorProvider(response -> { @@ -24,15 +28,15 @@ public static void main(String[] args) throws Throwable { ServletInfo plainTextServletInfo = new ServletInfo(); plainTextServletInfo.setServletName("plaintext"); plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName()); - plainTextServletInfo.addMapping("/plaintext"); + applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(plainTextServletInfo.getServletName(), "/plaintext")); applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo); // json ServletInfo jsonServletInfo = new ServletInfo(); jsonServletInfo.setServletName("json"); jsonServletInfo.setServletClass(JsonServlet.class.getName()); - jsonServletInfo.addMapping("/json"); applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); + applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(jsonServletInfo.getServletName(), "/json")); containerRuntime.addRuntime(applicationRuntime); int cpuNum = Runtime.getRuntime().availableProcessors(); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java index 6ac97cc7606..3d0d8bd1d2a 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java @@ -1,10 +1,11 @@ package org.smartboot.servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; /** diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java index e484da19fc3..064bc80556d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java @@ -1,12 +1,12 @@ package org.smartboot.servlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.Message; import org.smartboot.http.JsonUtil; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** From 13476012724f8f98ad2b8b8d2630fb6d8b29b156 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sat, 7 Dec 2024 13:41:34 +0800 Subject: [PATCH 46/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 2 +- .../java/org/smartboot/http/Bootstrap.java | 4 +-- .../java/org/smartboot/servlet/Bootstrap.java | 29 +++---------------- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 39a47cc3c1e..1ea12004111 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 2.3 + 2.4 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 06753113440..74ec542ae44 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -53,9 +53,7 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio .threadNum(cpuNum) .headerLimiter(0) .readBufferSize(1024 * 4) - .writeBufferSize(1024 * 4) - .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum); + .writeBufferSize(1024 * 4); bootstrap.httpHandler(routeHandle).setPort(8080).start(); } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index f4458e0a6e6..7130017de5b 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -1,17 +1,11 @@ package org.smartboot.servlet; -import org.smartboot.http.server.HttpBootstrap; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandler; import tech.smartboot.servlet.Container; import tech.smartboot.servlet.ServletContextRuntime; import tech.smartboot.servlet.conf.ServletInfo; import tech.smartboot.servlet.conf.ServletMappingInfo; -import java.util.concurrent.CompletableFuture; - /** * @author 三刀(zhengjunweimail@163.com) * @version V1.0 , 2020/12/22 @@ -38,26 +32,11 @@ public static void main(String[] args) throws Throwable { applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo); applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(jsonServletInfo.getServletName(), "/json")); containerRuntime.addRuntime(applicationRuntime); - int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 - HttpBootstrap bootstrap = new HttpBootstrap(); - bootstrap.configuration() - .threadNum(cpuNum) - .bannerEnabled(false) - .headerLimiter(0) - .readBufferSize(1024 * 4) - .writeBufferSize(1024 * 4) - .readMemoryPool(16384 * 1024 * 4) - .writeMemoryPool(10 * 1024 * 1024 * cpuNum, cpuNum); - containerRuntime.start(bootstrap.configuration()); - bootstrap.setPort(8080) - .httpHandler(new HttpServerHandler() { - @Override - public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws Throwable { - containerRuntime.doHandle(request, response, completableFuture); - } - }) - .start(); + containerRuntime.getConfiguration() + .setThreadNum(cpuNum) + .setReadBufferSize(1024 * 4); + containerRuntime.start(); } } From 6794849a7c224bc8bd97e12a58aa2de1180c6dec Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sat, 7 Dec 2024 13:49:55 +0800 Subject: [PATCH 47/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Java/smart-socket/benchmark_config.json | 3 -- .../java/org/smartboot/http/Bootstrap.java | 37 +++++++------------ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/frameworks/Java/smart-socket/benchmark_config.json b/frameworks/Java/smart-socket/benchmark_config.json index f69d7a43eb7..7a26d71ed56 100755 --- a/frameworks/Java/smart-socket/benchmark_config.json +++ b/frameworks/Java/smart-socket/benchmark_config.json @@ -5,9 +5,6 @@ "default": { "json_url": "/json", "plaintext_url": "/plaintext", - "db_url": "/db", - "query_url": "/queries?queries=", - "update_url": "/updates?queries=", "port": 8080, "approach": "Realistic", "classification": "Platform", diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 74ec542ae44..9dda965e0be 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -18,34 +18,11 @@ import org.smartboot.http.server.handler.HttpRouteHandler; import javax.sql.DataSource; -import java.io.IOException; public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); public static void main(String[] args) { - HttpRouteHandler routeHandle = new HttpRouteHandler(); - routeHandle - .route("/plaintext", new HttpServerHandler() { - - - @Override - public void handle(HttpRequest request, HttpResponse response) throws IOException { - response.setContentLength(body.length); - response.setContentType("text/plain; charset=UTF-8"); - response.write(body); - } - }) - .route("/json", new HttpServerHandler() { - - @Override - public void handle(HttpRequest request, HttpResponse response) throws IOException { - - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); - } - }); - initDB(routeHandle); int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpBootstrap bootstrap = new HttpBootstrap(); @@ -54,7 +31,19 @@ public void handle(HttpRequest request, HttpResponse response) throws IOExceptio .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4); - bootstrap.httpHandler(routeHandle).setPort(8080).start(); + bootstrap.httpHandler(new HttpServerHandler() { + @Override + public void handle(HttpRequest request, HttpResponse response) throws Throwable { + if ("/plaintext".equals(request.getRequestURI())) { + response.setContentLength(body.length); + response.setContentType("text/plain; charset=UTF-8"); + response.write(body); + } else if ("/json".equals(request.getRequestURI())) { + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); + } + } + }).setPort(8080).start(); } private static void initDB(HttpRouteHandler routeHandle) { From dde7fce23d1d0955a9d056dfb9ffa3b61f69cd53 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sat, 7 Dec 2024 14:02:40 +0800 Subject: [PATCH 48/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/smartboot/servlet/Bootstrap.java | 2 + .../resources/smart-servlet/License.shield | Bin 0 -> 967 bytes .../resources/smart-servlet/smart-servlet.pem | 55 ++++++++++++++++++ .../smart-servlet/smart-servlet.properties | 15 +++++ 4 files changed, 72 insertions(+) create mode 100644 frameworks/Java/smart-socket/src/main/resources/smart-servlet/License.shield create mode 100644 frameworks/Java/smart-socket/src/main/resources/smart-servlet/smart-servlet.pem create mode 100644 frameworks/Java/smart-socket/src/main/resources/smart-servlet/smart-servlet.properties diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 7130017de5b..96c3bf7ed10 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -13,6 +13,7 @@ public class Bootstrap { public static void main(String[] args) throws Throwable { + System.setProperty("smart-servlet-spring-boot-starter","true"); Container containerRuntime = new Container(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/"); @@ -37,6 +38,7 @@ public static void main(String[] args) throws Throwable { containerRuntime.getConfiguration() .setThreadNum(cpuNum) .setReadBufferSize(1024 * 4); + containerRuntime.initialize(); containerRuntime.start(); } } diff --git a/frameworks/Java/smart-socket/src/main/resources/smart-servlet/License.shield b/frameworks/Java/smart-socket/src/main/resources/smart-servlet/License.shield new file mode 100644 index 0000000000000000000000000000000000000000..f970f023915e0e46165f8a833528edbaedc9f2d4 GIT binary patch literal 967 zcmV;&133J1ZDDeBEo^CHWo~n20004vtF8&P0004%2!md50000WF=aM2W;kOxWimKo zWil`{W@Ip8W@Tk!G-5DhIA$<30001@FoB;i4F(A+hDe6@4FLfG1potqjQ}u#i2{Lv z0Im+;3edJ8Payh|6C%}?uc~+yP(n}f0096101tC*VRCe0Z*O$vo1*EMp8x;= z7kX%AZf9zBZg*vAZDDC_KruEmE@N+P0000UfTfKld*FI7uZ*^!beU~viOp#F^)n091{Eq+b7g1Tcj5w;p!QXn>kqFT(a%=l%iUH< z-UGd($|u}tG!4X_i`wxf`Z8wAz#=DD`HJR#mKMTNz=_x>Unm9);v<|-Jvd!kc_et zxhF9nDJZ)ER5p;cD;yb(D(_Jg(&&_h@QxY@ECj0`t{qNQ$l#fwylYq<{8<=;`_bSm zj})_cAKPnFAEf;AS5PPb00000000btoj|#S?KXUr-WMN%kFQt;cp%9wwr3mz=;bU3 zK~r;Ov#R+3Is9T}Iv;Iuo$I$~4Kdk5Wj!O8$k8L{sKghuaV~Hiv{~Y;mtIg3w`UxU ztnkvE*UES*O=TWr?+`MXcgt{fkCr)O8DVX^RU-`em!x*IX%11FZm!6@@z`2x00000 z0000GfM)Uhl>BQ>;V!(IYdBCHp;M-2zY63MGj+BrE+@#wwX8>441_E$K;mOrme0F{ z`@k;AVA+S`YaTLoyz0(zMTA&kX5grbR_gHjb)Tjq-0YW*=$L1(v>Lb*d!0 Date: Sat, 7 Dec 2024 14:22:46 +0800 Subject: [PATCH 49/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 1ea12004111..a4107b3d3e8 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 2.4 + 2.5 5.0.0 0.9.23 From 050644450545da7b7dd174a0a6c488421cf81d7a Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sat, 7 Dec 2024 14:30:22 +0800 Subject: [PATCH 50/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/smartboot/servlet/Bootstrap.java | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 96c3bf7ed10..f3caa038cbe 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -40,5 +40,6 @@ public static void main(String[] args) throws Throwable { .setReadBufferSize(1024 * 4); containerRuntime.initialize(); containerRuntime.start(); + } } From 2efa84ebc6579f804596cb67ed0ae2940eed6e9f Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Wed, 25 Dec 2024 14:30:49 +0800 Subject: [PATCH 51/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 2 +- .../src/main/java/org/smartboot/http/Bootstrap.java | 12 ++++++------ .../src/main/java/org/smartboot/http/JsonUtil.java | 2 +- .../org/smartboot/http/MultipleQueriesHandler.java | 9 +++++---- .../java/org/smartboot/http/SingleQueryHandler.java | 7 ++++--- .../main/java/org/smartboot/http/UpdateHandler.java | 9 +++++---- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index a4107b3d3e8..48ef8c57303 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 2.5 + 2.6.1-dev 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 9dda965e0be..920970055f4 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -11,11 +11,11 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import org.smartboot.Message; -import org.smartboot.http.server.HttpBootstrap; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandler; -import org.smartboot.http.server.handler.HttpRouteHandler; +import tech.smartboot.feat.core.server.HttpRequest; +import tech.smartboot.feat.core.server.HttpResponse; +import tech.smartboot.feat.core.server.HttpServer; +import tech.smartboot.feat.core.server.HttpServerHandler; +import tech.smartboot.feat.core.server.handler.HttpRouteHandler; import javax.sql.DataSource; @@ -25,7 +25,7 @@ public class Bootstrap { public static void main(String[] args) { int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 - HttpBootstrap bootstrap = new HttpBootstrap(); + HttpServer bootstrap = new HttpServer(); bootstrap.configuration() .threadNum(cpuNum) .headerLimiter(0) diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index b20525ec571..31a7d546119 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -5,7 +5,7 @@ import com.jsoniter.spi.JsonException; import com.jsoniter.spi.Slice; import jakarta.servlet.http.HttpServletResponse; -import org.smartboot.http.server.HttpResponse; +import tech.smartboot.feat.core.server.HttpResponse; import java.io.IOException; diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index 61b9f66b344..ac4807a9284 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -1,9 +1,10 @@ package org.smartboot.http; -import org.smartboot.http.common.utils.NumberUtils; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandler; + +import tech.smartboot.feat.core.common.utils.NumberUtils; +import tech.smartboot.feat.core.server.HttpRequest; +import tech.smartboot.feat.core.server.HttpResponse; +import tech.smartboot.feat.core.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index b69495d1a5e..52a96b9ca57 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -1,8 +1,9 @@ package org.smartboot.http; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandler; + +import tech.smartboot.feat.core.server.HttpRequest; +import tech.smartboot.feat.core.server.HttpResponse; +import tech.smartboot.feat.core.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 065bed5a9a6..3217adea343 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -1,9 +1,10 @@ package org.smartboot.http; -import org.smartboot.http.common.utils.NumberUtils; -import org.smartboot.http.server.HttpRequest; -import org.smartboot.http.server.HttpResponse; -import org.smartboot.http.server.HttpServerHandler; + +import tech.smartboot.feat.core.common.utils.NumberUtils; +import tech.smartboot.feat.core.server.HttpRequest; +import tech.smartboot.feat.core.server.HttpResponse; +import tech.smartboot.feat.core.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; From cc05c876111d0430ecc9ba208a9e3afd8beaee51 Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Sun, 29 Dec 2024 17:39:33 +0800 Subject: [PATCH 52/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/pom.xml | 2 +- .../src/main/java/org/smartboot/http/Bootstrap.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index 48ef8c57303..afdeea27141 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 2.6.1-dev + 2.7 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 920970055f4..4875d68c8d8 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -27,7 +27,7 @@ public static void main(String[] args) { // 定义服务器接受的消息类型以及各类消息对应的处理器 HttpServer bootstrap = new HttpServer(); bootstrap.configuration() - .threadNum(cpuNum) + .threadNum(cpuNum + 1) .headerLimiter(0) .readBufferSize(1024 * 4) .writeBufferSize(1024 * 4); From 74b3ad96fa70d6c30d7abddfe45b476dce220e4c Mon Sep 17 00:00:00 2001 From: zhengjw22 Date: Thu, 16 Jan 2025 17:32:14 +0800 Subject: [PATCH 53/53] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/Java/smart-socket/config.toml | 10 +-- frameworks/Java/smart-socket/pom.xml | 2 +- .../java/org/smartboot/http/Bootstrap.java | 83 +++++++++---------- .../http/MultipleQueriesHandler.java | 7 +- .../smartboot/http/SingleQueryHandler.java | 7 +- .../org/smartboot/http/UpdateHandler.java | 9 +- 6 files changed, 57 insertions(+), 61 deletions(-) diff --git a/frameworks/Java/smart-socket/config.toml b/frameworks/Java/smart-socket/config.toml index fbebc43a6a3..54e7e13d9d7 100644 --- a/frameworks/Java/smart-socket/config.toml +++ b/frameworks/Java/smart-socket/config.toml @@ -1,12 +1,12 @@ [framework] -name = "smart-socket" +name = "feat" [main] urls.plaintext = "/plaintext" urls.json = "/json" -urls.db = "/db" -urls.query = "/queries?queries=" -urls.update = "/updates?queries=" +#urls.db = "/db" +#urls.query = "/queries?queries=" +#urls.update = "/updates?queries=" approach = "Realistic" classification = "Platform" database = "Postgres" @@ -15,7 +15,7 @@ os = "Linux" orm = "Raw" platform = "smartboot" webserver = "None" -versus = "smart-socket" +versus = "feat" [smart-servlet] urls.plaintext = "/plaintext" diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index afdeea27141..4fe3e7a155f 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -11,7 +11,7 @@ 21 21 2.17.1 - 2.7 + 2.8 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java index 4875d68c8d8..396b6d02900 100755 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java @@ -8,16 +8,12 @@ package org.smartboot.http; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; import org.smartboot.Message; +import tech.smartboot.feat.core.Feat; +import tech.smartboot.feat.core.common.enums.HeaderValueEnum; +import tech.smartboot.feat.core.server.HttpHandler; import tech.smartboot.feat.core.server.HttpRequest; import tech.smartboot.feat.core.server.HttpResponse; -import tech.smartboot.feat.core.server.HttpServer; -import tech.smartboot.feat.core.server.HttpServerHandler; -import tech.smartboot.feat.core.server.handler.HttpRouteHandler; - -import javax.sql.DataSource; public class Bootstrap { static byte[] body = "Hello, World!".getBytes(); @@ -25,45 +21,42 @@ public class Bootstrap { public static void main(String[] args) { int cpuNum = Runtime.getRuntime().availableProcessors(); // 定义服务器接受的消息类型以及各类消息对应的处理器 - HttpServer bootstrap = new HttpServer(); - bootstrap.configuration() - .threadNum(cpuNum + 1) - .headerLimiter(0) - .readBufferSize(1024 * 4) - .writeBufferSize(1024 * 4); - bootstrap.httpHandler(new HttpServerHandler() { - @Override - public void handle(HttpRequest request, HttpResponse response) throws Throwable { - if ("/plaintext".equals(request.getRequestURI())) { - response.setContentLength(body.length); - response.setContentType("text/plain; charset=UTF-8"); - response.write(body); - } else if ("/json".equals(request.getRequestURI())) { - response.setContentType("application/json"); - JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); - } + Feat.createHttpServer(options -> { + options.threadNum(cpuNum + 1) + .headerLimiter(0) + .readBufferSize(1024 * 4) + .writeBufferSize(1024 * 4); + }).httpHandler(request -> { + HttpResponse response = request.getResponse(); + if ("/plaintext".equals(request.getRequestURI())) { + response.setContentLength(body.length); + response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8); + response.write(body); + } else if ("/json".equals(request.getRequestURI())) { + response.setContentType("application/json"); + JsonUtil.writeJsonBytes(response, new Message("Hello, World!")); } - }).setPort(8080).start(); + }).listen(8080); } - private static void initDB(HttpRouteHandler routeHandle) { - try { - Class.forName("org.postgresql.Driver"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - HikariConfig config = new HikariConfig(); - config.setJdbcUrl("jdbc:postgresql://tfb-database:5432/hello_world"); - config.setUsername("benchmarkdbuser"); - config.setPassword("benchmarkdbpass"); - config.setMaximumPoolSize(64); - config.addDataSourceProperty("cachePrepStmts", "true"); - config.addDataSourceProperty("prepStmtCacheSize", "250"); - config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - DataSource dataSource = new HikariDataSource(config); - routeHandle.route("/db", new SingleQueryHandler(dataSource)) - .route("/queries", new MultipleQueriesHandler(dataSource)) - .route("/updates", new UpdateHandler(dataSource)); -// .route("/fortunes", new FortunesHandler(dataSource)); - } +// private static void initDB(HttpRouteHandler routeHandle) { +// try { +// Class.forName("org.postgresql.Driver"); +// } catch (ClassNotFoundException e) { +// e.printStackTrace(); +// } +// HikariConfig config = new HikariConfig(); +// config.setJdbcUrl("jdbc:postgresql://tfb-database:5432/hello_world"); +// config.setUsername("benchmarkdbuser"); +// config.setPassword("benchmarkdbpass"); +// config.setMaximumPoolSize(64); +// config.addDataSourceProperty("cachePrepStmts", "true"); +// config.addDataSourceProperty("prepStmtCacheSize", "250"); +// config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); +// DataSource dataSource = new HikariDataSource(config); +// routeHandle.route("/db", new SingleQueryHandler(dataSource)) +// .route("/queries", new MultipleQueriesHandler(dataSource)) +// .route("/updates", new UpdateHandler(dataSource)); +//// .route("/fortunes", new FortunesHandler(dataSource)); +// } } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java index ac4807a9284..f9b6b4faa5b 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java @@ -4,7 +4,7 @@ import tech.smartboot.feat.core.common.utils.NumberUtils; import tech.smartboot.feat.core.server.HttpRequest; import tech.smartboot.feat.core.server.HttpResponse; -import tech.smartboot.feat.core.server.HttpServerHandler; +import tech.smartboot.feat.core.server.handler.BaseHttpHandler; import javax.sql.DataSource; import java.io.IOException; @@ -19,7 +19,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class MultipleQueriesHandler extends HttpServerHandler { +public class MultipleQueriesHandler extends BaseHttpHandler { private DataSource dataSource; public MultipleQueriesHandler(DataSource dataSource) { @@ -27,7 +27,8 @@ public MultipleQueriesHandler(DataSource dataSource) { } @Override - public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { + public void handle(HttpRequest httpRequest, CompletableFuture completableFuture) throws IOException { + HttpResponse response = httpRequest.getResponse(); Thread.startVirtualThread(() -> { try { int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java index 52a96b9ca57..12898f62b7d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java @@ -3,7 +3,7 @@ import tech.smartboot.feat.core.server.HttpRequest; import tech.smartboot.feat.core.server.HttpResponse; -import tech.smartboot.feat.core.server.HttpServerHandler; +import tech.smartboot.feat.core.server.handler.BaseHttpHandler; import javax.sql.DataSource; import java.io.IOException; @@ -18,7 +18,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class SingleQueryHandler extends HttpServerHandler { +public class SingleQueryHandler extends BaseHttpHandler { private DataSource dataSource; public SingleQueryHandler(DataSource dataSource) { @@ -26,7 +26,8 @@ public SingleQueryHandler(DataSource dataSource) { } @Override - public void handle(HttpRequest httpRequest, HttpResponse response, CompletableFuture completableFuture) throws IOException { + public void handle(HttpRequest httpRequest, CompletableFuture completableFuture) throws IOException { + HttpResponse response = httpRequest.getResponse(); Thread.startVirtualThread(() -> { try { World world = new World(); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java index 3217adea343..b2b37a5f424 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/UpdateHandler.java @@ -2,9 +2,9 @@ import tech.smartboot.feat.core.common.utils.NumberUtils; +import tech.smartboot.feat.core.server.HttpHandler; import tech.smartboot.feat.core.server.HttpRequest; import tech.smartboot.feat.core.server.HttpResponse; -import tech.smartboot.feat.core.server.HttpServerHandler; import javax.sql.DataSource; import java.io.IOException; @@ -19,7 +19,7 @@ * @author 三刀 * @version V1.0 , 2020/6/16 */ -public class UpdateHandler extends HttpServerHandler { +public class UpdateHandler implements HttpHandler { private DataSource dataSource; public UpdateHandler(DataSource dataSource) { @@ -27,8 +27,9 @@ public UpdateHandler(DataSource dataSource) { } @Override - public void handle(HttpRequest httpRequest, HttpResponse response) throws IOException { - int queries = Math.min(Math.max(NumberUtils.toInt(httpRequest.getParameter("queries"), 1), 1), 500); + public void handle(HttpRequest request) throws IOException { + HttpResponse response = request.getResponse(); + int queries = Math.min(Math.max(NumberUtils.toInt(request.getParameter("queries"), 1), 1), 500); World[] worlds = new World[queries]; StringJoiner updateSql = new StringJoiner( ", ",