use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestException method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestExceptionServlet";
String param = "ttt";
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());
ProtobaseFuture future = session.request(serviceKey, param);
System.out.println(future.getReadText());
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestListenSimple method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestListenSimpleServlet";
String param = "ttt";
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());
ProtobaseFuture future = session.request(serviceKey, param);
System.out.println(future.getReadText());
session.listen(serviceKey, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
ProtobaseFuture f = (ProtobaseFuture) future;
System.out.println(f.getReadText());
}
});
session.write(serviceKey, param);
ThreadUtil.sleep(1000);
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestRedeploy method main.
public static void main(String[] args) throws Exception {
String serviceKey = "system-redeploy";
String param = "{username:\"admin\",password:\"admin100\"}";
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");
ProtobaseFuture future = session.request(serviceKey, param);
System.out.println(future.getReadText());
for (int i = 0; i < 0; i++) {
future = session.request(serviceKey, param);
}
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestSimpleBigParam method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestSimpleServlet";
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());
String temp = "网易科技腾讯科技阿里巴巴";
StringBuilder builder = new StringBuilder(temp);
for (int i = 0; i < 600000; i++) {
builder.append("\n");
builder.append(temp);
}
ProtobaseFuture future = session.request(serviceKey, builder.toString());
FileUtil.writeByCls(TestSimpleBigParam.class.getName(), future.getReadText());
System.out.println("处理完成");
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.component.SocketChannelContext in project baseio by generallycloud.
the class TestLineBasedBroadcastServer method main.
public static void main(String[] args) throws Exception {
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, Future future) throws Exception {
long old = System.currentTimeMillis();
String res = "hello world!";
future.write(res);
ChannelAcceptor acceptor = (ChannelAcceptor) session.getContext().getChannelService();
acceptor.broadcast(future);
long now = System.currentTimeMillis();
System.out.println("广播花费时间:" + (now - old) + ",连接数:" + session.getContext().getSessionManager().getManagedSessionSize());
}
};
ServerConfiguration configuration = new ServerConfiguration();
configuration.setSERVER_PORT(18300);
configuration.setSERVER_SESSION_IDLE_TIME(180000);
configuration.setSERVER_MEMORY_POOL_CAPACITY(1024 * 512);
configuration.setSERVER_MEMORY_POOL_UNIT(64);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.setProtocolFactory(new CharBasedProtocolFactory());
acceptor.bind();
}
Aggregations