Browse Source

update smart-socket to 1.5.6 (#6417)

* update smart-servlet to 0.1.3-SNAPSHOT

* update aio-enhance to 1.0.3-SNAPSHOT

* smart-servlet bugfix

* bugfix

* update smart-socket to 1.5.6-SNAPSHOT

* remove file

* update aio-enhance to 1.0.4-SNAPSHOT

* 优化代码

* 优化代码

* update smart-socket to 1.5.6

* config threadNum
三刀 4 years ago
parent
commit
b4b61b53ff

+ 2 - 2
frameworks/Java/smart-socket/pom.xml

@@ -11,9 +11,9 @@
         <maven.compiler.source>11</maven.compiler.source>
         <maven.compiler.target>11</maven.compiler.target>
         <log4j.version>2.11.0</log4j.version>
-        <aio-enhance.version>1.0.3-SNAPSHOT</aio-enhance.version>
+        <aio-enhance.version>1.0.4-SNAPSHOT</aio-enhance.version>
         <smartservlet.version>0.1.3-SNAPSHOT</smartservlet.version>
-        <smartsocket.version>1.5.5-SNAPSHOT</smartsocket.version>
+        <smartsocket.version>1.5.6</smartsocket.version>
     </properties>
 
     <dependencies>

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

@@ -12,9 +12,12 @@ import com.zaxxer.hikari.HikariConfig;
 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 class Bootstrap {
 
         HttpRouteHandle routeHandle = new HttpRouteHandle();
         routeHandle
-                .route("/plaintext", new HttpHandle() {
+                .route("/plaintext", new HttpServerHandle() {
 
 
                     @Override
@@ -40,7 +43,7 @@ public class Bootstrap {
                         response.write(body);
                     }
                 })
-                .route("/json", new HttpHandle() {
+                .route("/json", new HttpServerHandle() {
 
                     @Override
                     public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
@@ -53,12 +56,13 @@ public class Bootstrap {
         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)
+                .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);
@@ -68,7 +72,8 @@ public class Bootstrap {
                     public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
                         processor.stateEvent(session, stateMachineEnum, throwable);
                     }
-                }).start();
+                });
+        bootstrap.pipeline(routeHandle).setPort(8080).start();
     }
 
     private static void initDB(HttpRouteHandle routeHandle) {

+ 1 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java

@@ -4,6 +4,7 @@ import com.jsoniter.output.JsonStream;
 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;

+ 5 - 3
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 @@ import java.util.concurrent.ThreadLocalRandom;
  * @author 三刀
  * @version V1.0 , 2020/6/16
  */
-public class MultipleQueriesHandler extends HttpHandle {
+public class MultipleQueriesHandler extends HttpServerHandle {
     private DataSource dataSource;
 
     public MultipleQueriesHandler(DataSource dataSource) {

+ 4 - 2
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 @@ import java.util.concurrent.ThreadLocalRandom;
  * @author 三刀
  * @version V1.0 , 2020/6/16
  */
-public class SingleQueryHandler extends HttpHandle {
+public class SingleQueryHandler extends HttpServerHandle {
     private DataSource dataSource;
 
     public SingleQueryHandler(DataSource dataSource) {

+ 5 - 3
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 @@ import java.util.concurrent.ThreadLocalRandom;
  * @author 三刀
  * @version V1.0 , 2020/6/16
  */
-public class UpdateHandler extends HttpHandle {
+public class UpdateHandler extends HttpServerHandle {
     private DataSource dataSource;
 
     public UpdateHandler(DataSource dataSource) {

+ 22 - 18
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;
@@ -42,18 +42,14 @@ public class Bootstrap {
         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 HttpHandle() {
-                    @Override
-                    public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
-                        containerRuntime.doHandle(request, response);
-                    }
-                })
-                .wrapProcessor(processor -> new AbstractMessageProcessor<>() {
+        bootstrap.configuration()
+                .threadNum(cpuNum)
+                .bannerEnabled(false)
+                .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);
@@ -63,6 +59,14 @@ public class Bootstrap {
                     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();
     }
 }

+ 21 - 0
frameworks/Java/smart-socket/src/main/resources/fortunes.vm

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Fortunes</title>
+</head>
+<body>
+<table>
+    <tr>
+        <th>id</th>
+        <th>message</th>
+    </tr>
+    #foreach($i in $fortunes)
+        <tr>
+            <td>${i.id}</td>
+            <td>${i.message}</td>
+        </tr>
+    #end
+</table>
+${text}
+</body>
+</html>