public Server(InetSocketAddress bindAddress, Acceptor acceptor) throws IOException { this.bindAddress = bindAddress; if (acceptor.getState() != Thread.State.RUNNABLE) { acceptor.start(); } this.acceptor = acceptor; serverSocketChannel = (ServerSocketChannel) ServerSocketChannel.open().bind(this.bindAddress).configureBlocking(false); acceptor.register(serverSocketChannel); logger.info("start server bind in : {}", bindAddress); }
public void close() { try { serverSocketChannel.close(); acceptor.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } }