use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.
the class TestBytebufAllocator method test.
static void test() throws Exception {
ServerConfiguration configuration = new ServerConfiguration();
configuration.setSERVER_MEMORY_POOL_CAPACITY(10);
configuration.setSERVER_MEMORY_POOL_UNIT(1);
SocketChannelContext context = new NioSocketChannelContext(configuration);
PooledByteBufAllocatorManager allocator = new PooledByteBufAllocatorManager(context);
allocator.start();
ByteBufAllocator allocator2 = allocator.getNextBufAllocator();
ByteBuf buf = allocator2.allocate(15);
System.out.println(buf);
}
use of com.generallycloud.baseio.component.NioSocketChannelContext 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.NioSocketChannelContext 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.NioSocketChannelContext 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.NioSocketChannelContext 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