Search in sources :

Example 6 with SocketChannelContext

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

the class TestTellerPower method main.

public static void main(String[] args) throws Exception {
    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");
    MessageProducer producer = new DefaultMessageProducer(session);
    TextMessage message = new TextMessage("msgId", "qName", "你好!");
    long old = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
        producer.offer(message);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    connector.close();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) 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) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) MessageProducer(com.generallycloud.baseio.container.jms.client.MessageProducer) TextMessage(com.generallycloud.baseio.container.jms.TextMessage)

Example 7 with SocketChannelContext

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

the class TestLoadClient method main.

public static void main(String[] args) throws Exception {
    final Logger logger = LoggerFactory.getLogger(TestLoadClient.class);
    final CountDownLatch latch = new CountDownLatch(time);
    final AtomicInteger res = new AtomicInteger();
    final AtomicInteger req = new AtomicInteger();
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
        // latch.countDown();
        // long count = latch.getCount();
        // if (count % 10 == 0) {
        // if (count < 50) {
        // logger.info("************************================" + count);
        // }
        // }
        // logger.info("res==========={}",res.getAndIncrement());
        }
    };
    ServerConfiguration configuration = new ServerConfiguration(8300);
    // SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelContext context = new AioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    connector.getContext().setProtocolFactory(new FixedLengthProtocolFactory());
    connector.getContext().getServerConfiguration().setSERVER_CORE_SIZE(1);
    SocketSession session = connector.connect();
    System.out.println("################## Test start ####################");
    long old = System.currentTimeMillis();
    for (int i = 0; i < time; i++) {
        FixedLengthFuture future = new FixedLengthFutureImpl(session.getContext());
        future.write("hello server!");
        session.flush(future);
    }
    latch.await();
    long spend = (System.currentTimeMillis() - old);
    System.out.println("## Execute Time:" + time);
    System.out.println("## OP/S:" + new BigDecimal(time * 1000).divide(new BigDecimal(spend), 2, BigDecimal.ROUND_HALF_UP));
    System.out.println("## Expend Time:" + spend);
    CloseUtil.close(connector);
}
Also used : FixedLengthFutureImpl(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) Logger(com.generallycloud.baseio.log.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) BigDecimal(java.math.BigDecimal) AioSocketChannelContext(com.generallycloud.baseio.component.AioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) 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) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) FixedLengthFuture(com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)

Example 8 with SocketChannelContext

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

the class TestHttpLoadClient method prepare.

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

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            addCount(1000);
        }
    };
    ServerConfiguration c = new ServerConfiguration("localhost", 80);
    c.setSERVER_MEMORY_POOL_CAPACITY(1280000);
    c.setSERVER_MEMORY_POOL_UNIT(128);
    c.setSERVER_CORE_SIZE(1);
    c.setSERVER_HOST("192.168.0.180");
    SocketChannelContext context = new NioSocketChannelContext(c);
    connector = new SocketChannelConnector(context);
    context.setProtocolFactory(new ClientHTTPProtocolFactory());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    session = connector.connect();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) Future(com.generallycloud.baseio.protocol.Future) ClientHttpFuture(com.generallycloud.baseio.codec.http11.future.ClientHttpFuture) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture) ClientHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ClientHTTPProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 9 with SocketChannelContext

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

the class SimpleTestFIxedLengthServer method main.

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

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            future.write("yes server already accept your message:");
            future.write(future.getReadText());
            session.flush(future);
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    // use java aio
    // SocketChannelContext context = new AioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.setBeatFutureFactory(new FLBeatFutureFactory());
    context.setProtocolFactory(new FixedLengthProtocolFactory());
    acceptor.bind();
}
Also used : FLBeatFutureFactory(com.generallycloud.baseio.codec.fixedlength.future.FLBeatFutureFactory) 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) 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 10 with SocketChannelContext

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

the class TestSimpleHttpClient2 method main.

public static void main(String[] args) throws IOException {
    String host = "www.baidu.com";
    host = "generallycloud.com";
    host = "127.0.0.1";
    int port = 443;
    port = 8080;
    HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
    ServerConfiguration c = new ServerConfiguration(host, port);
    SocketChannelContext context = new NioSocketChannelContext(c);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setProtocolFactory(new ClientHTTPProtocolFactory());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    if (port == 443) {
        context.setSslContext(SSLUtil.initClient(true));
    }
    SocketSession session = connector.connect();
    HttpClient client = new HttpClient(session);
    HttpFuture future = new ClientHttpFuture(context, "/");
    HttpFuture res = client.request(future, 99990000);
    System.out.println();
    System.out.println(new String(res.getBodyContent()));
    System.out.println();
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ClientHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ClientHTTPProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ClientHttpFuture(com.generallycloud.baseio.codec.http11.future.ClientHttpFuture) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture) HttpIOEventHandle(com.generallycloud.baseio.codec.http11.HttpIOEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ClientHttpFuture(com.generallycloud.baseio.codec.http11.future.ClientHttpFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) HttpClient(com.generallycloud.baseio.codec.http11.HttpClient)

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