/** * Closes the channels. * * @param channels to close * @param blocking indicates if we should block on channel close */ static <C extends CloseableChannel> void closeChannels(List<C> channels, boolean blocking) { try { IOUtils.close(channels); } catch (IOException e) { // The CloseableChannel#close method does not throw IOException, so this should not occur. throw new AssertionError(e); } if (blocking) { ArrayList<ActionFuture<Void>> futures = new ArrayList<>(channels.size()); for (final C channel : channels) { PlainActionFuture<Void> closeFuture = PlainActionFuture.newFuture(); channel.addCloseListener(closeFuture); futures.add(closeFuture); } blockOnFutures(futures); } }