public static <T extends SshFuture> CloseFuture parallel(final SshFuture<T>... futures) {
return parallel(null, futures);
}
public static <T extends SshFuture> CloseFuture parallel(Object lock, final SshFuture<T>... futures) {
final CloseFuture future = new DefaultCloseFuture(lock);
if (futures.length > 0) {
final AtomicInteger count = new AtomicInteger(futures.length);
SshFutureListener<T> listener = new SshFutureListener<T>() {
public void operationComplete(T f) {
if (count.decrementAndGet() == 0) {
future.setClosed();
}
}
};
for (SshFuture<T> f : futures) {
if (f != null) {
f.addListener(listener);
} else {
listener.operationComplete(null);
}
}
} else {
future.setClosed();
}
return future;
}