SelectableChannel doConnect() throws IOException, InterruptedException { final ServerSocketChannel serverChannel = ServerSocketChannel.open(); serverChannel.socket().setReceiveBufferSize(BUFFER_SIZE); serverChannel.configureBlocking(false); final ServerSocket serverSocket = serverChannel.socket(); serverSocket.setReuseAddress(true); serverSocket.bind(details.address()); // these can be run on this thread addPendingRegistration( new Runnable() { @Override public void run() { final Attached attached = new Attached(); attached.connector = ServerConnector.this; try { serverChannel.register(TcpReplicator.this.selector, OP_ACCEPT, attached); } catch (ClosedChannelException e) { LOG.error("", e); } } }); selector.wakeup(); return serverChannel; }