|
@@ -16,7 +16,11 @@ import org.smartboot.http.server.decode.Http11Request;
|
|
|
import org.smartboot.http.server.decode.HttpRequestProtocol;
|
|
|
import org.smartboot.http.server.handle.HttpHandle;
|
|
|
import org.smartboot.socket.MessageProcessor;
|
|
|
+import org.smartboot.socket.StateMachineEnum;
|
|
|
+import org.smartboot.socket.extension.plugins.MonitorPlugin;
|
|
|
+import org.smartboot.socket.extension.processor.AbstractMessageProcessor;
|
|
|
import org.smartboot.socket.transport.AioQuickServer;
|
|
|
+import org.smartboot.socket.transport.AioSession;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
@@ -25,7 +29,7 @@ public class Bootstrap {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.setProperty("smart-socket.server.pageSize", (8 * 1024 * 1024) + "");
|
|
|
- System.setProperty("smart-socket.bufferPool.pageNum", 16 + "");
|
|
|
+// System.setProperty("smart-socket.bufferPool.pageNum", 16 + "");
|
|
|
System.setProperty("smart-socket.session.writeChunkSize", (1024 * 4) + "");
|
|
|
// System.setProperty("sun.nio.ch.maxCompletionHandlersOnStack","24");
|
|
|
HttpMessageProcessor processor = new HttpMessageProcessor(System.getProperty("webapps.dir", "./"));
|
|
@@ -51,6 +55,7 @@ public class Bootstrap {
|
|
|
stream.writeVal(Message.class, new Message("Hello, World!"));
|
|
|
response.setContentLength(stream.buffer().tail());
|
|
|
response.getOutputStream().write(stream.buffer().data(), 0, stream.buffer().tail());
|
|
|
+ response.getOutputStream().flush();
|
|
|
} catch (IOException e) {
|
|
|
throw new JsonException(e);
|
|
|
} finally {
|
|
@@ -62,9 +67,21 @@ public class Bootstrap {
|
|
|
// https(processor);
|
|
|
}
|
|
|
|
|
|
- public static void http(MessageProcessor<Http11Request> processor) {
|
|
|
+ public static void http(final MessageProcessor<Http11Request> processor) {
|
|
|
+ AbstractMessageProcessor messageProcessor = new AbstractMessageProcessor<Http11Request>() {
|
|
|
+ @Override
|
|
|
+ public void process0(AioSession<Http11Request> session, Http11Request msg) {
|
|
|
+ processor.process(session, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void stateEvent0(AioSession<Http11Request> session, StateMachineEnum stateMachineEnum, Throwable throwable) {
|
|
|
+ processor.stateEvent(session, stateMachineEnum, throwable);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ messageProcessor.addPlugin(new MonitorPlugin(5 ));
|
|
|
// 定义服务器接受的消息类型以及各类消息对应的处理器
|
|
|
- AioQuickServer<Http11Request> server = new AioQuickServer<>(8080, new HttpRequestProtocol(), processor);
|
|
|
+ AioQuickServer<Http11Request> server = new AioQuickServer<>(8080, new HttpRequestProtocol(), messageProcessor);
|
|
|
server.setReadBufferSize(1024 * 4);
|
|
|
int cpuNum = Runtime.getRuntime().availableProcessors();
|
|
|
server.setThreadNum(cpuNum + 2);
|