use of com.generallycloud.baseio.component.SocketChannelContext 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.SocketChannelContext 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.SocketChannelContext 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();
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestBeat 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());
}
};
String serviceKey = "TestSimpleServlet";
ServerConfiguration configuration = new ServerConfiguration(18300);
configuration.setSERVER_SESSION_IDLE_TIME(10);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.addSessionIdleEventListener(new SocketSessionActiveSEListener());
context.setBeatFutureFactory(new ProtobaseBeatFutureFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
SocketSession session = connector.connect();
String param = "tttt";
long old = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
Future future = new ProtobaseFutureImpl(context, serviceKey);
future.write(param);
session.flush(future);
ThreadUtil.sleep(300);
}
System.out.println("Time:" + (System.currentTimeMillis() - old));
Thread.sleep(2000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestDownload method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestDownloadServlet";
String fileName = "upload-flashmail-2.4.exe";
JSONObject j = new JSONObject();
j.put(FileReceiveUtil.FILE_NAME, fileName);
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());
connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
FixedSession session = new FixedSession(connector.connect());
final FileReceiveUtil fileReceiveUtil = new FileReceiveUtil("download-");
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
try {
fileReceiveUtil.accept(session, (ParamedProtobaseFuture) future, false);
} catch (Exception e) {
DebugUtil.debug(e);
}
}
});
long old = System.currentTimeMillis();
session.write(serviceName, j.toJSONString());
System.out.println("Time:" + (System.currentTimeMillis() - old));
ThreadUtil.sleep(5000);
CloseUtil.close(connector);
}
Aggregations