@@ -0,0 +1,1977 @@
+package edu.teco.dnd.util;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0A/**%0A * Combines multiple FutureNotifiers. If all FutureNotifiers succeed this will succeed as well. If at least one fails this%0A * will also be set to be a failure and the cause will be set to the cause of the failed FutureNotifier. If multiple FutureNotifiers%0A * fail the cause is set to one of the causes of the failed FutureNotifiers without any guarantee as to which one.%0A * %0A * @author Philipp Adolf%0A *%0A * @param %3CT%3E the type of the result of the FutureNotifiers that should be joined%0A */%0Apublic class JoinedFutureNotifier%3CT%3E extends DefaultFutureNotifier%3CCollection%3CT%3E%3E implements FutureListener%3CFutureNotifier%3CT%3E%3E%7B%0A%09/**%0A%09 * The FutureNotifiers that are combined.%0A%09 */%0A%09private final Collection%3CFutureNotifier%3C? extends T%3E%3E futures;%0A%09%0A%09/**%0A%09 * The number of FutureNotifiers that have not yet finished. Only relevant in the success case.%0A%09 */%0A%09private final AtomicInteger unfinished;%0A%09%0A%09/**%0A%09 * Initializes a new JoinedFutureNotifier.%0A%09 * %0A%09 * @param futures the FutureNotifiers that should be joined%0A%09 */%0A%09public JoinedFutureNotifier(final Collection%3CFutureNotifier%3C? extends T%3E%3E futures) %7B%0A%09%09this.futures = Collections.unmodifiableSet(new HashSet%3CFutureNotifier%3C? extends T%3E%3E(futures));%0A%09%09unfinished = new AtomicInteger(this.futures.size());%0A%09%09for (FutureNotifier%3C? extends T%3E future : this.futures) %7B%0A%09%09%09future.addListener(this);%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public synchronized void operationComplete(final FutureNotifier%3CT%3E future) %7B%0A%09%09if (!isDone()) %7B%0A%09%09%09if (future.isSuccess()) %7B%0A%09%09%09%09if (unfinished.decrementAndGet() %3C= 0) %7B%0A%09%09%09%09%09final Collection%3CT%3E result = new ArrayList%3CT%3E();%0A%09%09%09%09%09for (final FutureNotifier%3C? extends T%3E notifier : this.futures) %7B%0A%09%09%09%09%09%09result.add(notifier.getNow());%0A%09%09%09%09%09%7D%0A%09%09%09%09%09setSuccess(result);%0A%09%09%09%09%7D%0A%09%09%09%7D else %7B%0A%09%09%09%09setFailure(future.cause());%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add JoinedFutureNotifier