|
@@ -4,7 +4,6 @@ package org.smartboot.servlet;
|
|
import tech.smartboot.servlet.Container;
|
|
import tech.smartboot.servlet.Container;
|
|
import tech.smartboot.servlet.ServletContextRuntime;
|
|
import tech.smartboot.servlet.ServletContextRuntime;
|
|
import tech.smartboot.servlet.conf.ServletInfo;
|
|
import tech.smartboot.servlet.conf.ServletInfo;
|
|
-import tech.smartboot.servlet.conf.ServletMappingInfo;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author 三刀([email protected])
|
|
* @author 三刀([email protected])
|
|
@@ -13,7 +12,7 @@ import tech.smartboot.servlet.conf.ServletMappingInfo;
|
|
public class Bootstrap {
|
|
public class Bootstrap {
|
|
|
|
|
|
public static void main(String[] args) throws Throwable {
|
|
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();
|
|
Container containerRuntime = new Container();
|
|
// plaintext
|
|
// plaintext
|
|
ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
|
|
ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
|
|
@@ -23,23 +22,24 @@ public class Bootstrap {
|
|
ServletInfo plainTextServletInfo = new ServletInfo();
|
|
ServletInfo plainTextServletInfo = new ServletInfo();
|
|
plainTextServletInfo.setServletName("plaintext");
|
|
plainTextServletInfo.setServletName("plaintext");
|
|
plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
|
|
plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
|
|
- applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(plainTextServletInfo.getServletName(), "/plaintext"));
|
|
|
|
|
|
+ plainTextServletInfo.addServletMapping("/plaintext", applicationRuntime);
|
|
applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo);
|
|
applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo);
|
|
|
|
|
|
// json
|
|
// json
|
|
ServletInfo jsonServletInfo = new ServletInfo();
|
|
ServletInfo jsonServletInfo = new ServletInfo();
|
|
jsonServletInfo.setServletName("json");
|
|
jsonServletInfo.setServletName("json");
|
|
jsonServletInfo.setServletClass(JsonServlet.class.getName());
|
|
jsonServletInfo.setServletClass(JsonServlet.class.getName());
|
|
|
|
+ jsonServletInfo.addServletMapping("/json", applicationRuntime);
|
|
applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo);
|
|
applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo);
|
|
- applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(jsonServletInfo.getServletName(), "/json"));
|
|
|
|
containerRuntime.addRuntime(applicationRuntime);
|
|
containerRuntime.addRuntime(applicationRuntime);
|
|
int cpuNum = Runtime.getRuntime().availableProcessors();
|
|
int cpuNum = Runtime.getRuntime().availableProcessors();
|
|
// 定义服务器接受的消息类型以及各类消息对应的处理器
|
|
// 定义服务器接受的消息类型以及各类消息对应的处理器
|
|
containerRuntime.getConfiguration()
|
|
containerRuntime.getConfiguration()
|
|
.setThreadNum(cpuNum)
|
|
.setThreadNum(cpuNum)
|
|
|
|
+ .setHeaderLimiter(0)
|
|
.setReadBufferSize(1024 * 4);
|
|
.setReadBufferSize(1024 * 4);
|
|
containerRuntime.initialize();
|
|
containerRuntime.initialize();
|
|
containerRuntime.start();
|
|
containerRuntime.start();
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|