|
@@ -20,9 +20,10 @@ import java.util.Arrays;
|
|
|
|
|
|
import com.firenio.baseio.Options;
|
|
|
import com.firenio.baseio.codec.http11.HttpCodec;
|
|
|
-import com.firenio.baseio.codec.http11.HttpCodecLite;
|
|
|
-import com.firenio.baseio.codec.http11.HttpFrameLite;
|
|
|
-import com.firenio.baseio.codec.http11.HttpStatic;
|
|
|
+import com.firenio.baseio.codec.http11.HttpConnection;
|
|
|
+import com.firenio.baseio.codec.http11.HttpContentType;
|
|
|
+import com.firenio.baseio.codec.http11.HttpDateUtil;
|
|
|
+import com.firenio.baseio.codec.http11.HttpFrame;
|
|
|
import com.firenio.baseio.codec.http11.HttpStatus;
|
|
|
import com.firenio.baseio.common.Util;
|
|
|
import com.firenio.baseio.component.Channel;
|
|
@@ -31,7 +32,6 @@ import com.firenio.baseio.component.ChannelEventListenerAdapter;
|
|
|
import com.firenio.baseio.component.Frame;
|
|
|
import com.firenio.baseio.component.IoEventHandle;
|
|
|
import com.firenio.baseio.component.NioEventLoopGroup;
|
|
|
-import com.firenio.baseio.component.ProtocolCodec;
|
|
|
import com.firenio.baseio.component.SocketOptions;
|
|
|
import com.firenio.baseio.log.DebugUtil;
|
|
|
import com.firenio.baseio.log.LoggerFactory;
|
|
@@ -88,39 +88,41 @@ public class TestHttpLoadServer {
|
|
|
|
|
|
@Override
|
|
|
public void accept(Channel ch, Frame frame) throws Exception {
|
|
|
- HttpFrameLite f = (HttpFrameLite) frame;
|
|
|
+ HttpFrame f = (HttpFrame) frame;
|
|
|
String action = f.getRequestURL();
|
|
|
if ("/plaintext".equals(action)) {
|
|
|
f.setContent(STATIC_PLAINTEXT);
|
|
|
- f.setContentType(HttpStatic.text_plain_bytes);
|
|
|
+ f.setContentType(HttpContentType.text_plain);
|
|
|
+ f.setConnection(HttpConnection.NONE);
|
|
|
} else if ("/json".equals(action)) {
|
|
|
f.setContent(serializeMsg(new Message("Hello, World!")));
|
|
|
- f.setContentType(HttpStatic.application_json_bytes);
|
|
|
+ f.setContentType(HttpContentType.application_json);
|
|
|
+ f.setConnection(HttpConnection.NONE);
|
|
|
} else {
|
|
|
+ System.err.println("404");
|
|
|
f.setContent("404,page not found!".getBytes());
|
|
|
+ f.setContentType(HttpContentType.text_plain);
|
|
|
f.setStatus(HttpStatus.C404);
|
|
|
}
|
|
|
+ f.setDate(HttpDateUtil.getDate());
|
|
|
ch.writeAndFlush(f);
|
|
|
ch.release(f);
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
- ProtocolCodec codec;
|
|
|
- if (lite) {
|
|
|
- codec = new HttpCodecLite("baseio", 1024 * 16);
|
|
|
- } else {
|
|
|
- codec = new HttpCodec("baseio", 1024 * 16);
|
|
|
- }
|
|
|
+ HttpDateUtil.start();
|
|
|
NioEventLoopGroup group = new NioEventLoopGroup();
|
|
|
ChannelAcceptor context = new ChannelAcceptor(group, 8080);
|
|
|
group.setMemoryPoolCapacity(1024 * 128);
|
|
|
+ group.setEnableMemoryPoolDirect(direct);
|
|
|
+ group.setEnableMemoryPool(pool);
|
|
|
group.setMemoryPoolUnit(256);
|
|
|
group.setWriteBuffers(32);
|
|
|
group.setChannelReadBuffer(1024 * readBuf);
|
|
|
group.setEventLoopSize(Util.availableProcessors() * core);
|
|
|
group.setConcurrentFrameStack(false);
|
|
|
- context.addProtocolCodec(codec);
|
|
|
+ context.addProtocolCodec(new HttpCodec("baseio", 1024 * 16, lite));
|
|
|
context.addChannelEventListener(new ChannelEventListenerAdapter() {
|
|
|
|
|
|
@Override
|