Search in sources :

Example 26 with SocketChannelContext

use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.

the class TestRedisClient method main.

public static void main(String[] args) throws Exception {
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(6379));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(new RedisIOEventHandle());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new RedisProtocolFactory());
    SocketSession session = connector.connect();
    RedisClient client = new RedisClient(session);
    String value = client.set("name222", "hello redis!");
    System.out.println("__________________res______" + value);
    value = client.get("name222");
    System.out.println("__________________res______" + value);
    value = client.set("debug", "PONG");
    System.out.println("__________________res______" + value);
    value = client.get("debug");
    System.out.println("__________________res______" + value);
    value = client.ping();
    System.out.println("__________________res______" + value);
    ThreadUtil.sleep(100);
    CloseUtil.close(connector);
}
Also used : RedisClient(com.generallycloud.baseio.codec.redis.future.RedisClient) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) RedisIOEventHandle(com.generallycloud.baseio.codec.redis.future.RedisIOEventHandle) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSession(com.generallycloud.baseio.component.SocketSession) RedisProtocolFactory(com.generallycloud.baseio.codec.redis.RedisProtocolFactory) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 27 with SocketChannelContext

use of com.generallycloud.baseio.component.SocketChannelContext 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 28 with SocketChannelContext

use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.

the class SimpleTestProtobaseServer method main.

public static void main(String[] args) throws Exception {
    DebugUtil.setEnableDebug(true);
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            DebugUtil.debug("receive:" + future.getReadText());
            future.write("yes server already accept your message:");
            future.write(future.getReadText());
            session.flush(future);
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    context.getServerConfiguration().setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
    context.getServerConfiguration().setSERVER_SESSION_IDLE_TIME(60 * 60 * 1000);
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setBeatFutureFactory(new ProtobaseBeatFutureFactory());
    context.addSessionIdleEventListener(new SocketSessionAliveSEListener());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    acceptor.bind();
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseBeatFutureFactory(com.generallycloud.baseio.codec.protobase.future.ProtobaseBeatFutureFactory) SocketSessionAliveSEListener(com.generallycloud.baseio.component.SocketSessionAliveSEListener) 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) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 29 with SocketChannelContext

use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.

the class TestGetPhoneNO method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "TestGetPhoneNOServlet";
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
    FixedSession session = new FixedSession(connector.connect());
    ProtobaseFuture future = session.request(serviceKey, null);
    System.out.println(future.getReadText());
    CloseUtil.close(connector);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 30 with SocketChannelContext

use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.

the class TestSessionDisconnect method main.

public static void main(String[] args) throws Exception {
    String serviceName = "TestSessionDisconnectServlet";
    String param = "ttt";
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    ProtobaseFuture future = session.request(serviceName, param);
    System.out.println(future.getReadText());
    session.listen(serviceName, new OnFuture() {

        @Override
        public void onResponse(SocketSession session, Future future) {
            ProtobaseFuture f = (ProtobaseFuture) future;
            System.out.println(f.getReadText());
        }
    });
    session.write(serviceName, param);
    ThreadUtil.sleep(9999);
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnFuture(com.generallycloud.baseio.container.OnFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) OnFuture(com.generallycloud.baseio.container.OnFuture)

Aggregations

SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)65 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)55 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)55 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)54 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)40 SocketSession (com.generallycloud.baseio.component.SocketSession)36 Future (com.generallycloud.baseio.protocol.Future)33 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)29 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)27 FixedSession (com.generallycloud.baseio.container.FixedSession)20 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)20 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)17 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)12 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)12 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)8 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)8 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)7 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)6 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)6 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)6