Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions frameworks/Java/smart-socket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<log4j.version>2.17.1</log4j.version>
<smartservlet.version>2.8</smartservlet.version>
<smartservlet.version>2.9.1</smartservlet.version>
<hikaricp.version>5.0.0</hikaricp.version>
<jsoniter.version>0.9.23</jsoniter.version>
</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>
<version>0.1-SNAPSHOT</version>
<artifactId>feat-cloud-starter</artifactId>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>tech.smartboot.servlet</groupId>
Expand All @@ -34,7 +29,7 @@
<exclusions>
<exclusion>
<groupId>tech.smartboot.feat</groupId>
<artifactId>feat-restful</artifactId>
<artifactId>feat-core</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,14 @@

package org.smartboot.http;

import tech.smartboot.feat.restful.RestFeat;

import tech.smartboot.feat.cloud.FeatCloud;

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

public static void main(String[] args) {
int cpuNum = Runtime.getRuntime().availableProcessors();
// 定义服务器接受的消息类型以及各类消息对应的处理器
// 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 -> {
FeatCloud.cloudServer(options -> {
options.threadNum(cpuNum + 1)
.headerLimiter(0)
.readBufferSize(1024 * 4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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.cloud.annotation.Controller;
import tech.smartboot.feat.cloud.annotation.RequestMapping;
import tech.smartboot.feat.core.common.HeaderValue;
import tech.smartboot.feat.core.server.HttpResponse;

@Controller
Expand All @@ -12,13 +12,13 @@ public class FeatController {

@RequestMapping("/plaintext")
public byte[] plaintext(HttpResponse response) {
response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
response.setContentType(HeaderValue.ContentType.TEXT_PLAIN_UTF8);
return body;
}

@RequestMapping("/json")
public Message json(HttpResponse response) {
response.setContentType(HeaderValueEnum.ContentType.APPLICATION_JSON_UTF8);
response.setContentType(HeaderValue.ContentType.APPLICATION_JSON_UTF8);
return new Message("Hello, World!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.handler.BaseHttpHandler;

import javax.sql.DataSource;
import java.io.IOException;
Expand All @@ -19,7 +19,7 @@
* @author 三刀
* @version V1.0 , 2020/6/16
*/
public class MultipleQueriesHandler extends BaseHttpHandler {
public class MultipleQueriesHandler implements HttpHandler {
private DataSource dataSource;

public MultipleQueriesHandler(DataSource dataSource) {
Expand Down Expand Up @@ -59,6 +59,11 @@ public void handle(HttpRequest httpRequest, CompletableFuture<Object> completabl

}

@Override
public void handle(HttpRequest request) throws Throwable {

}

protected int getRandomNumber() {
return 1 + ThreadLocalRandom.current().nextInt(10000);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.smartboot.http;


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.handler.BaseHttpHandler;

import javax.sql.DataSource;
import java.io.IOException;
Expand All @@ -18,7 +18,7 @@
* @author 三刀
* @version V1.0 , 2020/6/16
*/
public class SingleQueryHandler extends BaseHttpHandler {
public class SingleQueryHandler implements HttpHandler {
private DataSource dataSource;

public SingleQueryHandler(DataSource dataSource) {
Expand Down Expand Up @@ -49,6 +49,11 @@ public void handle(HttpRequest httpRequest, CompletableFuture<Object> completabl

}

@Override
public void handle(HttpRequest request) throws Throwable {

}

protected int getRandomNumber() {
return 1 + ThreadLocalRandom.current().nextInt(10000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tech.smartboot.servlet.Container;
import tech.smartboot.servlet.ServletContextRuntime;
import tech.smartboot.servlet.conf.ServletInfo;
import tech.smartboot.servlet.conf.ServletMappingInfo;

/**
* @author 三刀(zhengjunweimail@163.com)
Expand All @@ -13,7 +12,7 @@
public class Bootstrap {

public static void main(String[] args) throws Throwable {
System.setProperty("smart-servlet-spring-boot-starter","true");
System.setProperty("smart-servlet-spring-boot-starter", "true");
Container containerRuntime = new Container();
// plaintext
ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
Expand All @@ -23,23 +22,24 @@ public static void main(String[] args) throws Throwable {
ServletInfo plainTextServletInfo = new ServletInfo();
plainTextServletInfo.setServletName("plaintext");
plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(plainTextServletInfo.getServletName(), "/plaintext"));
plainTextServletInfo.addServletMapping("/plaintext", applicationRuntime);
applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo);

// json
ServletInfo jsonServletInfo = new ServletInfo();
jsonServletInfo.setServletName("json");
jsonServletInfo.setServletClass(JsonServlet.class.getName());
jsonServletInfo.addServletMapping("/json", applicationRuntime);
applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo);
applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(jsonServletInfo.getServletName(), "/json"));
containerRuntime.addRuntime(applicationRuntime);
int cpuNum = Runtime.getRuntime().availableProcessors();
// 定义服务器接受的消息类型以及各类消息对应的处理器
containerRuntime.getConfiguration()
.setThreadNum(cpuNum)
.setHeaderLimiter(0)
.setReadBufferSize(1024 * 4);
containerRuntime.initialize();
containerRuntime.start();

}
}
Binary file not shown.
Loading