|
@@ -12,7 +12,6 @@ import org.smartboot.http.server.HttpMessageProcessor;
|
|
|
import org.smartboot.http.server.decode.Http11Request;
|
|
|
import org.smartboot.http.server.decode.HttpRequestProtocol;
|
|
|
import org.smartboot.http.server.handle.HttpHandle;
|
|
|
-import org.smartboot.http.utils.HttpHeaderConstant;
|
|
|
import org.smartboot.socket.MessageProcessor;
|
|
|
import org.smartboot.socket.transport.AioQuickServer;
|
|
|
|
|
@@ -22,16 +21,15 @@ public class Bootstrap {
|
|
|
static byte[] body = "Hello, World!".getBytes();
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- System.setProperty("sun.nio.ch.maxCompletionHandlersOnStack","0");
|
|
|
+ System.setProperty("smart-socket.server.pageSize", (4 * 1024 * 1024) + "");
|
|
|
HttpMessageProcessor processor = new HttpMessageProcessor(System.getProperty("webapps.dir", "./"));
|
|
|
processor.route("/plaintext", new HttpHandle() {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
|
|
|
-
|
|
|
- response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, body.length + "");
|
|
|
- response.setHeader(HttpHeaderConstant.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
|
|
+ response.setContentLength(body.length);
|
|
|
+ response.setContentType("text/plain; charset=UTF-8");
|
|
|
response.getOutputStream().write(body);
|
|
|
}
|
|
|
});
|
|
@@ -39,8 +37,8 @@ public class Bootstrap {
|
|
|
@Override
|
|
|
public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
|
|
|
byte[] b = JSON.toJson(new Message("Hello, World!"));
|
|
|
- response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, b.length + "");
|
|
|
- response.setHeader(HttpHeaderConstant.Names.CONTENT_TYPE, "application/json");
|
|
|
+ response.setContentLength(b.length);
|
|
|
+ response.setContentType("application/json");
|
|
|
response.getOutputStream().write(b);
|
|
|
}
|
|
|
});
|
|
@@ -51,8 +49,7 @@ public class Bootstrap {
|
|
|
public static void http(MessageProcessor<Http11Request> processor) {
|
|
|
// 定义服务器接受的消息类型以及各类消息对应的处理器
|
|
|
AioQuickServer<Http11Request> server = new AioQuickServer<>(8080, new HttpRequestProtocol(), processor);
|
|
|
- server.setWriteQueueSize(1024);
|
|
|
- server.setReadBufferSize(1024*4);
|
|
|
+ server.setReadBufferSize(1024);
|
|
|
// server.setThreadNum((int) (Runtime.getRuntime().availableProcessors() * 2));
|
|
|
try {
|
|
|
server.start();
|