Search in sources :

Example 21 with Future

use of com.generallycloud.baseio.protocol.Future in project baseio by generallycloud.

the class TestHeartBeat 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("______________" + future.getReadText());
        }
    };
    ServerConfiguration configuration = new ServerConfiguration(18300);
    configuration.setSERVER_SESSION_IDLE_TIME(20);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.addSessionIdleEventListener(new SocketSessionActiveSEListener());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setBeatFutureFactory(new FLBeatFutureFactory());
    context.setProtocolFactory(new FixedLengthProtocolFactory());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    SocketSession session = connector.connect();
    String param = "tttt";
    long old = System.currentTimeMillis();
    for (int i = 0; i < 5; i++) {
        Future future = new FixedLengthFutureImpl(context);
        future.write(param);
        session.flush(future);
        ThreadUtil.sleep(300);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    Thread.sleep(2000);
    CloseUtil.close(connector);
}
Also used : FixedLengthFutureImpl(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl) FLBeatFutureFactory(com.generallycloud.baseio.codec.fixedlength.future.FLBeatFutureFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketSession(com.generallycloud.baseio.component.SocketSession) FixedLengthProtocolFactory(com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) SocketSessionActiveSEListener(com.generallycloud.baseio.component.SocketSessionActiveSEListener)

Example 22 with Future

use of com.generallycloud.baseio.protocol.Future in project baseio by generallycloud.

the class SimpleTestProtobaseClient method main.

public static void main(String[] args) throws Exception {
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            System.out.println();
            System.out.println("____________________" + future.getReadText());
            System.out.println();
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 18300));
    context.getServerConfiguration().setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    connector.setTimeout(99999999);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    SocketSession session = connector.connect();
    ProtobaseFuture future = new ProtobaseFutureImpl(context, "test222");
    future.write("hello server!");
    session.flush(future);
    ThreadUtil.sleep(100);
    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) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 23 with Future

use of com.generallycloud.baseio.protocol.Future in project baseio by generallycloud.

the class Test404 method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "22";
    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 ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    ProtobaseFuture future = session.request(serviceKey, null);
    System.out.println(future.getReadText());
    Future future1 = new ProtobaseFutureImpl(connector.getContext()).setPING();
    session.getSession().flush(future1);
    CloseUtil.close(connector);
}
Also used : 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) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) FixedSession(com.generallycloud.baseio.container.FixedSession) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 24 with Future

use of com.generallycloud.baseio.protocol.Future in project baseio by generallycloud.

the class TestLoadClient1 method prepare.

@Override
public void prepare() throws Exception {
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            addCount(10000);
        }
    };
    ServerConfiguration configuration = new ServerConfiguration(8300);
    configuration.setSERVER_MEMORY_POOL_CAPACITY(1280000);
    configuration.setSERVER_MEMORY_POOL_UNIT(128);
    configuration.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
    configuration.setSERVER_ENABLE_MEMORY_POOL(true);
    // c.setSERVER_HOST("192.168.0.180");
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new FixedLengthProtocolFactory());
    connector.connect();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSession(com.generallycloud.baseio.component.SocketSession) FixedLengthProtocolFactory(com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 25 with Future

use of com.generallycloud.baseio.protocol.Future in project baseio by generallycloud.

the class TestLoadServer method main.

public static void main(String[] args) throws Exception {
    LoggerFactory.configure();
    final AtomicInteger res = new AtomicInteger();
    final AtomicInteger req = new AtomicInteger();
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            FixedLengthFuture f = (FixedLengthFuture) future;
            String res = "yes server already accept your message" + f.getReadText();
            f.write(res);
            session.flush(future);
        // System.out.println("req======================"+req.getAndIncrement());
        }
    };
    ServerConfiguration c = new ServerConfiguration(8300);
    c.setSERVER_MEMORY_POOL_CAPACITY(2560000);
    c.setSERVER_MEMORY_POOL_UNIT(128);
    c.setSERVER_MEMORY_POOL_CAPACITY_RATE(0.5);
    c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
    c.setSERVER_CORE_SIZE(6);
    SocketChannelContext context = new NioSocketChannelContext(c);
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
    context.setProtocolFactory(new FixedLengthProtocolFactory());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    // context.addSessionEventListener(new SetOptionListener());
    acceptor.bind();
}
Also used : LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SocketSession(com.generallycloud.baseio.component.SocketSession) FixedLengthProtocolFactory(com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Aggregations

Future (com.generallycloud.baseio.protocol.Future)36 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)33 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)33 SocketSession (com.generallycloud.baseio.component.SocketSession)33 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)33 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)31 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)29 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)21 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)15 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)12 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)12 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)11 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)8 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)7 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 FLBeatFutureFactory (com.generallycloud.baseio.codec.fixedlength.future.FLBeatFutureFactory)4 FixedSession (com.generallycloud.baseio.container.FixedSession)4 OnFuture (com.generallycloud.baseio.container.OnFuture)4 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)4