use of com.generallycloud.baseio.component.SocketSession in project baseio by generallycloud.
the class TestSimpleHttpClient method main.
public static void main(String[] args) throws Exception {
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
// ServerConfiguration c = new ServerConfiguration("localhost",80);
ServerConfiguration c = new ServerConfiguration("generallycloud.com", 443);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
SslContext sslContext = SSLUtil.initClient(true);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setSslContext(sslContext);
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/test-show-memory");
HttpFuture res = client.request(future, 10000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketSession 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);
}
use of com.generallycloud.baseio.component.SocketSession 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();
}
use of com.generallycloud.baseio.component.SocketSession 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();
}
use of com.generallycloud.baseio.component.SocketSession in project baseio by generallycloud.
the class TestHttpLoadServer 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 {
future.write("hello world!");
session.flush(future);
// System.out.println("req======================"+req.getAndIncrement());
}
};
ServerConfiguration c = new ServerConfiguration(8080);
// c.setSERVER_MEMORY_POOL_CAPACITY(2560000);
c.setSERVER_MEMORY_POOL_UNIT(256);
c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
// c.setSERVER_CORE_SIZE(2);
c.setSERVER_ENABLE_MEMORY_POOL(true);
c.setSERVER_MEMORY_POOL_CAPACITY_RATE(4);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.setProtocolFactory(new ServerHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
acceptor.bind();
}
Aggregations