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();
}
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);
}
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();
}
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();
}
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);
}
Aggregations