Search in sources :

Example 1 with ServerHTTPProtocolFactory

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);
}
Also used : LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture) ServerHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SocketSession(com.generallycloud.baseio.component.SocketSession) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor)

Example 2 with ServerHTTPProtocolFactory

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());
}
Also used : LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSessionAliveSEListener(com.generallycloud.baseio.component.SocketSessionAliveSEListener) BlackIPFilter(com.generallycloud.baseio.container.BlackIPFilter) FutureAcceptorHttpFilter(com.generallycloud.baseio.container.http11.service.FutureAcceptorHttpFilter) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ServerHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory) WebSocketBeatFutureFactory(com.generallycloud.baseio.codec.http11.future.WebSocketBeatFutureFactory)

Example 3 with 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();
}
Also used : LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor) ServerHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Aggregations

ServerHTTPProtocolFactory (com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory)3 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)3 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)3 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)2 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)2 SocketSession (com.generallycloud.baseio.component.SocketSession)2 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)2 Future (com.generallycloud.baseio.protocol.Future)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HttpFuture (com.generallycloud.baseio.codec.http11.future.HttpFuture)1 WebSocketBeatFutureFactory (com.generallycloud.baseio.codec.http11.future.WebSocketBeatFutureFactory)1 AioSocketChannelContext (com.generallycloud.baseio.component.AioSocketChannelContext)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 SocketSessionAliveSEListener (com.generallycloud.baseio.component.SocketSessionAliveSEListener)1 BlackIPFilter (com.generallycloud.baseio.container.BlackIPFilter)1 FutureAcceptorHttpFilter (com.generallycloud.baseio.container.http11.service.FutureAcceptorHttpFilter)1