use of com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory in project baseio by generallycloud.
the class TestHttpLoadServerAio method main.
public static void main(String[] args) throws Exception {
final AtomicInteger res = new AtomicInteger();
final AtomicInteger req = new AtomicInteger();
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
HttpFuture f = (HttpFuture) future;
String res;
if (f.hasBodyContent()) {
byte[] array = f.getBodyContent();
res = "yes server already accept your message :) </BR><PRE style='font-size: 18px;color: #FF9800;'>" + new String(array) + "</PRE>";
} else {
res = "yes server already accept your message :) " + f.getRequestParams();
}
f.write(res);
session.flush(f);
// System.out.println("req======================"+req.getAndIncrement());
}
};
ServerConfiguration c = new ServerConfiguration(80);
c.setSERVER_MEMORY_POOL_CAPACITY(2560000);
c.setSERVER_MEMORY_POOL_UNIT(256);
c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
c.setSERVER_CORE_SIZE(4);
c.setSERVER_ENABLE_MEMORY_POOL(true);
c.setSERVER_MEMORY_POOL_CAPACITY_RATE(0.5);
SocketChannelContext context = new AioSocketChannelContext(c);
context.setProtocolFactory(new ServerHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
new SocketChannelAcceptor(context).bind();
ThreadUtil.sleep(99999999);
}
use of com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory in project baseio by generallycloud.
the class HttpApplicationContextEnricher method enrich.
@Override
public void enrich(ApplicationContext context) {
SocketChannelContext channelContext = context.getChannelContext();
context.setServiceFilter(new FutureAcceptorHttpFilter());
context.setExceptionCaughtHandle(new HttpExceptionCaughtHandle());
// FIXME 重复的
Set<String> blackIPs = context.getBlackIPs();
if (blackIPs != null && !blackIPs.isEmpty()) {
channelContext.addSessionEventListener(new BlackIPFilter(blackIPs));
}
channelContext.setBeatFutureFactory(new WebSocketBeatFutureFactory());
channelContext.addSessionEventListener(new LoggerSocketSEListener());
channelContext.addSessionIdleEventListener(new SocketSessionAliveSEListener());
channelContext.setProtocolFactory(new ServerHTTPProtocolFactory());
}
use of com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory in project baseio by generallycloud.
the class TestHttpLoadServer method main.
public static void main(String[] args) throws Exception {
final AtomicInteger res = new AtomicInteger();
final AtomicInteger req = new AtomicInteger();
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
future.write("hello world!");
session.flush(future);
// System.out.println("req======================"+req.getAndIncrement());
}
};
ServerConfiguration c = new ServerConfiguration(8080);
// c.setSERVER_MEMORY_POOL_CAPACITY(2560000);
c.setSERVER_MEMORY_POOL_UNIT(256);
c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
// c.setSERVER_CORE_SIZE(2);
c.setSERVER_ENABLE_MEMORY_POOL(true);
c.setSERVER_MEMORY_POOL_CAPACITY_RATE(4);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.setProtocolFactory(new ServerHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
acceptor.bind();
}
Aggregations