Merge pull request #718 from grkvlt/transform-parallel-timeout

Timeouts on FutureIterables.transformParallel
This commit is contained in:
Adrian Cole 2012-07-16 16:40:45 -07:00
commit a979c31d8c
3 changed files with 14 additions and 7 deletions

View File

@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -51,6 +50,7 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
/** /**
* *
@ -58,10 +58,15 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Singleton @Singleton
public class EC2ListNodesStrategy implements ListNodesStrategy { public class EC2ListNodesStrategy implements ListNodesStrategy {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject(optional = true)
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected static Long maxTime;
protected final EC2AsyncClient client; protected final EC2AsyncClient client;
protected final Supplier<Set<String>> regions; protected final Supplier<Set<String>> regions;
protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata; protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
@ -100,7 +105,7 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from)); return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
} }
}, executor, null, logger, "reservations"); }, executor, maxTime, logger, "reservations");
return concat(concat(reservations)); return concat(concat(reservations));
} }

View File

@ -137,8 +137,9 @@ public class FutureIterables {
errors.incrementAndGet(); errors.incrementAndGet();
logException(logger, logPrefix, total, complete.get(), errors.get(), start, e); logException(logger, logPrefix, total, complete.get(), errors.get(), start, e);
errorMap.put(future.getKey(), e); errorMap.put(future.getKey(), e);
} finally {
doneSignal.countDown();
} }
doneSignal.countDown();
} }
@Override @Override
@ -148,10 +149,11 @@ public class FutureIterables {
}, exec); }, exec);
} }
try { try {
if (maxTime != null) if (maxTime != null) {
doneSignal.await(maxTime, TimeUnit.MILLISECONDS); doneSignal.await(maxTime, TimeUnit.MILLISECONDS);
else } else {
doneSignal.await(); doneSignal.await();
}
if (errors.get() > 0) { if (errors.get() > 0) {
String message = message(logPrefix, total, complete.get(), errors.get(), start); String message = message(logPrefix, total, complete.get(), errors.get(), start);
RuntimeException exception = new RuntimeException(message); RuntimeException exception = new RuntimeException(message);

View File

@ -29,7 +29,6 @@ import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -45,6 +44,7 @@ import org.jclouds.location.Region;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.inject.Inject;
/** /**
* *
@ -76,7 +76,7 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
.describeSpotInstanceRequestsInRegion(from); .describeSpotInstanceRequestsInRegion(from);
} }
}, executor, null, logger, "reservations")), spotConverter), notNull()); }, executor, maxTime, logger, "reservations")), spotConverter), notNull());
return concat(super.pollRunningInstances(), spots); return concat(super.pollRunningInstances(), spots);
} }