public synchronized boolean addChannel(Channel channel) { if (closed) { channel.close(); return false; } this.connectedChannels.add(channel); return true; }
public synchronized CompletableFuture<Void> closeChannels() { List<CompletableFuture<Channel>> futures = new ArrayList<>(); for (Channel c : getAllChannels()) { futures.add(c.close()); } @SuppressWarnings("rawtypes") CompletableFuture[] array = futures.toArray(new CompletableFuture[0]); closed = true; return CompletableFuture.allOf(array); }