use of com.generallycloud.baseio.acceptor.ChannelAcceptor in project baseio by generallycloud.
the class SocketSelectorEventLoop method rebuildSelector0.
private SocketSelector rebuildSelector0() throws IOException {
SocketChannelContext context = getChannelContext();
NioChannelService nioChannelService = (NioChannelService) context.getChannelService();
SelectableChannel channel = nioChannelService.getSelectableChannel();
SocketSelector selector = openSelector(channel);
if (nioChannelService instanceof ChannelAcceptor) {
if (isMainEventLoop()) {
channel.register(selector.getSelector(), SelectionKey.OP_ACCEPT);
}
} else {
channel.register(selector.getSelector(), SelectionKey.OP_CONNECT);
}
return selector;
}
use of com.generallycloud.baseio.acceptor.ChannelAcceptor 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