This commit is contained in:
Adrian Cole 2012-05-17 01:31:20 -07:00
parent a2c8993592
commit 6e1c354423
3 changed files with 29 additions and 41 deletions

View File

@ -53,12 +53,6 @@
<artifactId>jclouds-compute</artifactId> <artifactId>jclouds-compute</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-s3</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jclouds.provider</groupId> <groupId>org.jclouds.provider</groupId>
<artifactId>hpcloud-objectstorage</artifactId> <artifactId>hpcloud-objectstorage</artifactId>
@ -369,8 +363,6 @@
<systemPropertyVariables> <systemPropertyVariables>
<!-- note you can add support for new clouds by adding more entries here <!-- note you can add support for new clouds by adding more entries here
after adding maven dependency --> after adding maven dependency -->
<test.aws-s3.identity>${test.aws-s3.identity}</test.aws-s3.identity>
<test.aws-s3.credential>${test.aws-s3.credential}</test.aws-s3.credential>
<test.hpcloud-objectstorage.identity>${test.hpcloud-objectstorage.identity}</test.hpcloud-objectstorage.identity> <test.hpcloud-objectstorage.identity>${test.hpcloud-objectstorage.identity}</test.hpcloud-objectstorage.identity>
<test.hpcloud-objectstorage.credential>${test.hpcloud-objectstorage.credential}</test.hpcloud-objectstorage.credential> <test.hpcloud-objectstorage.credential>${test.hpcloud-objectstorage.credential}</test.hpcloud-objectstorage.credential>
<appengine.sdk.root>${appengine.sdk.root}</appengine.sdk.root> <appengine.sdk.root>${appengine.sdk.root}</appengine.sdk.root>

View File

@ -25,5 +25,6 @@
<system-properties> <system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties" /> <property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
</system-properties> </system-properties>
<threadsafe>true</threadsafe> <!-- potential race condition in GuiceServletConfig -->
<threadsafe>false</threadsafe>
</appengine-web-app> </appengine-web-app>

View File

@ -23,7 +23,6 @@ import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -50,7 +49,6 @@ import com.google.common.base.Stopwatch;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -116,9 +114,8 @@ public class GetAllResourcesController extends HttpServlet {
request.setAttribute("resources", results); request.setAttribute("resources", results);
} }
private Set<Iterable<? extends ResourceMetadata<?>>> allResourcesWithinDeadline( private <T> Set<T> allResourcesWithinDeadline(Iterable<ListenableFuture<? extends T>> asyncResources) {
Iterable<ListenableFuture<? extends Iterable<? extends ResourceMetadata<?>>>> asyncResources) { Builder<T> resourcesWeCanList = addToBuilderOnComplete(asyncResources);
Builder<Iterable<? extends ResourceMetadata<?>>> resourcesWeCanList = addToBuilderOnComplete(asyncResources);
// only serve resources that made it by the timeout // only serve resources that made it by the timeout
blockUntilAllDoneOrCancelOnTimeout(asyncResources); blockUntilAllDoneOrCancelOnTimeout(asyncResources);
@ -126,22 +123,20 @@ public class GetAllResourcesController extends HttpServlet {
return resourcesWeCanList.build(); return resourcesWeCanList.build();
} }
private Builder<Iterable<? extends ResourceMetadata<?>>> addToBuilderOnComplete( private <T> Builder<T> addToBuilderOnComplete(Iterable<ListenableFuture<? extends T>> asyncResources) {
Iterable<ListenableFuture<? extends Iterable<? extends ResourceMetadata<?>>>> asyncResources) {
final Builder<Iterable<? extends ResourceMetadata<?>>> resourcesWeCanList = ImmutableSet final Builder<T> resourcesWeCanList = ImmutableSet.<T> builder();
.<Iterable<? extends ResourceMetadata<?>>> builder();
for (final ListenableFuture<? extends Iterable<? extends ResourceMetadata<?>>> asyncResource : asyncResources) { for (final ListenableFuture<? extends T> asyncResource : asyncResources) {
Futures.addCallback(asyncResource, new FutureCallback<Iterable<? extends ResourceMetadata<?>>>() { Futures.addCallback(asyncResource, new FutureCallback<T>() {
public void onSuccess(Iterable<? extends ResourceMetadata<?>> result) { public void onSuccess(T result) {
if (result != null) if (result != null)
resourcesWeCanList.add(result); resourcesWeCanList.add(result);
} }
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
if (!(t instanceof CancellationException)) if (!(t instanceof CancellationException))
logger.info("exception getting resource %s: %s", asyncResource, t.getMessage()); logger.error(t, "exception getting resource %s: %s", asyncResource, t.getMessage());
} }
}, currentRequestExecutorService); }, currentRequestExecutorService);
@ -149,27 +144,27 @@ public class GetAllResourcesController extends HttpServlet {
return resourcesWeCanList; return resourcesWeCanList;
} }
private void blockUntilAllDoneOrCancelOnTimeout( // ensure we don't violate our request timeouts.
Iterable<ListenableFuture<? extends Iterable<? extends ResourceMetadata<?>>>> asyncResources) { private void blockUntilAllDoneOrCancelOnTimeout(Iterable<? extends ListenableFuture<?>> asyncResources) {
List<ListenableFuture<? extends Iterable<? extends ResourceMetadata<?>>>> remaining = Lists try {
.newArrayList(asyncResources); for (ListenableFuture<?> asyncResource : asyncResources) {
if (remainingMillis.get() > 0) {
while (remaining.size() > 0) { try {
ListenableFuture<?> resource = remaining.remove(0); asyncResource.get(remainingMillis.get(), TimeUnit.MILLISECONDS);
if (remainingMillis.get() <= 0) { } catch (Exception e) {
if (!resource.isDone()) logger.info("exception getting resource %s: %s", asyncResource, e.getMessage());
resource.cancel(true); }
continue; }
} }
} finally {
try { if (remainingMillis.get() < 0) {
resource.get(remainingMillis.get(), TimeUnit.MILLISECONDS); for (ListenableFuture<?> asyncResource : asyncResources) {
} catch (Exception e) { if (!asyncResource.isDone())
logger.info("exception getting resource %s: %s", resource, e.getMessage()); asyncResource.cancel(true);
if (!resource.isDone()) }
resource.cancel(true);
} }
} }
} }
} }