Browse Source

upgrade feat (#9562)

* 适配最新版

* 适配最新版

* 适配最新版

* 适配最新版

* 适配最新版

* 适配最新版

* 适配最新版

* 适配最新版
三刀 5 months ago
parent
commit
434803dd81

+ 3 - 3
frameworks/Java/smart-socket/benchmark_config.json

@@ -1,5 +1,5 @@
 {
-  "framework": "smart-socket",
+  "framework": "feat",
   "tests": [
     {
       "default": {
@@ -17,9 +17,9 @@
         "webserver": "None",
         "os": "Linux",
         "database_os": "Linux",
-        "display_name": "smart-socket",
+        "display_name": "feat",
         "notes": "",
-        "versus": "smart-socket"
+        "versus": "feat"
       },
       "smart-servlet": {
         "json_url": "/json",

+ 2 - 2
frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile → frameworks/Java/smart-socket/feat-smart-servlet.dockerfile

@@ -2,11 +2,11 @@ FROM maven:3.9.7-amazoncorretto-21 as maven
 WORKDIR /smart-socket
 COPY pom.xml pom.xml
 COPY src src
-RUN mvn compile assembly:single -q
+RUN mvn install -q
 
 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
+COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0.jar app.jar
 
 EXPOSE 8080
 

+ 2 - 2
frameworks/Java/smart-socket/smart-socket.dockerfile → frameworks/Java/smart-socket/feat.dockerfile

@@ -2,11 +2,11 @@ FROM maven:3.9.7-amazoncorretto-21 as maven
 WORKDIR /smart-socket
 COPY pom.xml pom.xml
 COPY src src
-RUN mvn compile assembly:single -q
+RUN mvn install -q
 
 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
+COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0.jar app.jar
 
 EXPOSE 8080
 

+ 24 - 9
frameworks/Java/smart-socket/pom.xml

@@ -17,6 +17,11 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>tech.smartboot.feat</groupId>
+            <artifactId>feat-restful</artifactId>
+            <version>0.5</version>
+        </dependency>
         <dependency>
             <groupId>io.edap</groupId>
             <artifactId>edapx-json</artifactId>
@@ -26,6 +31,12 @@
             <groupId>tech.smartboot.servlet</groupId>
             <artifactId>servlet-core</artifactId>
             <version>${smartservlet.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>tech.smartboot.feat</groupId>
+                    <artifactId>feat-restful</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>com.zaxxer</groupId>
@@ -114,20 +125,24 @@
             </plugin>
 
             <plugin>
-                <artifactId>maven-assembly-plugin</artifactId>
-                <version>3.1.0</version>
-                <configuration>
-                    <descriptorRefs>
-                        <descriptorRef>jar-with-dependencies</descriptorRef>
-                    </descriptorRefs>
-                </configuration>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.3.0</version>
                 <executions>
                     <execution>
-                        <id>make-assembly</id>
                         <phase>package</phase>
                         <goals>
-                            <goal>single</goal>
+                            <goal>shade</goal>
                         </goals>
+                        <configuration>
+                            <createDependencyReducedPom>false</createDependencyReducedPom>
+                            <transformers>
+                                <!-- 采用追加的方式 -->
+                                <transformer
+                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
+                                    <resource>META-INF/services/tech.smartboot.feat.core.apt.AptLoader</resource>
+                                </transformer>
+                            </transformers>
+                        </configuration>
                     </execution>
                 </executions>
             </plugin>

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

@@ -8,12 +8,7 @@
 
 package org.smartboot.http;
 
-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.restful.RestFeat;
 
 public class Bootstrap {
     static byte[] body = "Hello, World!".getBytes();
@@ -21,21 +16,27 @@ public class Bootstrap {
     public static void main(String[] args) {
         int cpuNum = Runtime.getRuntime().availableProcessors();
         // 定义服务器接受的消息类型以及各类消息对应的处理器
-        Feat.createHttpServer(options -> {
+//        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!"));
+//            }
+//        }).listen(8080);
+        RestFeat.createServer(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!"));
-            }
         }).listen(8080);
     }
 

+ 24 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FeatController.java

@@ -0,0 +1,24 @@
+package org.smartboot.http;
+
+import org.smartboot.Message;
+import tech.smartboot.feat.core.apt.annotation.Controller;
+import tech.smartboot.feat.core.apt.annotation.RequestMapping;
+import tech.smartboot.feat.core.common.enums.HeaderValueEnum;
+import tech.smartboot.feat.core.server.HttpResponse;
+
+@Controller
+public class FeatController {
+    static byte[] body = "Hello, World!".getBytes();
+
+    @RequestMapping("/plaintext")
+    public byte[] plaintext(HttpResponse response) {
+        response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
+        return body;
+    }
+
+    @RequestMapping("/json")
+    public Message json(HttpResponse response) {
+        response.setContentType(HeaderValueEnum.ContentType.APPLICATION_JSON_UTF8);
+        return new Message("Hello, World!");
+    }
+}