public FutureDone<Void> close() { // cc is not null if we opened the connection if (cc != null) { FutureDone<Void> future = cc.shutdown(); // Maybe done on arrival? Set close future in any case future.addListener( new BaseFutureAdapter<FutureDone<Void>>() { @Override public void operationComplete(FutureDone<Void> future) throws Exception { closeFuture.setDone(); } }); } else { // cc is null if its an incoming connection. We can close it here, or it will be closed when // the dispatcher // is shutdown channelFuture.channel().close(); } return closeFuture; }