diff --git a/core/pom.xml b/core/pom.xml index 0bc88c80ae..20a318be39 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -111,7 +111,7 @@ com.google.guava guava - r08 + r09 com.google.code.findbugs diff --git a/core/src/main/java/org/jclouds/concurrent/Futures.java b/core/src/main/java/org/jclouds/concurrent/Futures.java index f74ffbb9c1..d388635c03 100644 --- a/core/src/main/java/org/jclouds/concurrent/Futures.java +++ b/core/src/main/java/org/jclouds/concurrent/Futures.java @@ -226,11 +226,12 @@ public class Futures { return Futures.LazyListenableFutureFunctionAdapter.create( ((org.jclouds.concurrent.Futures.ListenableFutureAdapter) future).futureListener, function); else - return com.google.common.util.concurrent.Futures.compose(lf, function, executorService); + return com.google.common.util.concurrent.Futures.transform(lf, function, executorService); } else if (executorService.getClass().isAnnotationPresent(SingleThreaded.class)) { return Futures.LazyListenableFutureFunctionAdapter.create(future, function, executorService); } else { - return com.google.common.util.concurrent.Futures.compose(Futures.makeListenable(future, executorService), function, executorService); + return com.google.common.util.concurrent.Futures.transform(Futures.makeListenable(future, executorService), + function, executorService); } } diff --git a/core/src/main/java/org/jclouds/concurrent/config/ExecutorServiceModule.java b/core/src/main/java/org/jclouds/concurrent/config/ExecutorServiceModule.java index 9d31244ab2..abd4c7d6a1 100644 --- a/core/src/main/java/org/jclouds/concurrent/config/ExecutorServiceModule.java +++ b/core/src/main/java/org/jclouds/concurrent/config/ExecutorServiceModule.java @@ -18,14 +18,20 @@ */ package org.jclouds.concurrent.config; - +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.concurrent.DynamicExecutors.newScalingThreadPool; import java.io.Closeable; import java.io.IOException; +import java.util.Collection; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.annotation.Resource; import javax.inject.Inject; @@ -104,6 +110,150 @@ public class ExecutorServiceModule extends AbstractModule { protected void configure() { } + static class AddToStringOnSubmitExecutorService implements ExecutorService { + + private final ExecutorService delegate; + + public AddToStringOnSubmitExecutorService(ExecutorService delegate) { + this.delegate = checkNotNull(delegate, "delegate"); + } + + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { + return delegate.awaitTermination(timeout, unit); + } + + @Override + public List> invokeAll(Collection> tasks) throws InterruptedException { + return delegate.invokeAll(tasks); + } + + @Override + public List> invokeAll(Collection> tasks, long timeout, TimeUnit unit) + throws InterruptedException { + return delegate.invokeAll(tasks, timeout, unit); + } + + @Override + public T invokeAny(Collection> tasks) throws InterruptedException, ExecutionException { + return delegate.invokeAny(tasks); + } + + @Override + public T invokeAny(Collection> tasks, long timeout, TimeUnit unit) + throws InterruptedException, ExecutionException, TimeoutException { + return delegate.invokeAny(tasks, timeout, unit); + } + + @Override + public boolean isShutdown() { + return delegate.isShutdown(); + } + + @Override + public boolean isTerminated() { + return delegate.isTerminated(); + } + + @Override + public void shutdown() { + delegate.shutdown(); + } + + @Override + public List shutdownNow() { + return delegate.shutdownNow(); + } + + @Override + public Future submit(Callable task) { + return new AddToStringFuture(delegate.submit(task), task.toString()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Future submit(Runnable task) { + return new AddToStringFuture(delegate.submit(task), task.toString()); + } + + @Override + public Future submit(Runnable task, T result) { + return new AddToStringFuture(delegate.submit(task, result), task.toString()); + } + + @Override + public void execute(Runnable arg0) { + delegate.execute(arg0); + } + + @Override + public boolean equals(Object obj) { + return delegate.equals(obj); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public String toString() { + return delegate.toString(); + } + + } + + static class AddToStringFuture implements Future { + private final Future delegate; + private final String toString; + + public AddToStringFuture(Future delegate, String toString) { + this.delegate = delegate; + this.toString = toString; + } + + @Override + public boolean cancel(boolean arg0) { + return delegate.cancel(arg0); + } + + @Override + public T get() throws InterruptedException, ExecutionException { + return delegate.get(); + } + + @Override + public T get(long arg0, TimeUnit arg1) throws InterruptedException, ExecutionException, TimeoutException { + return delegate.get(arg0, arg1); + } + + @Override + public boolean isCancelled() { + return delegate.isCancelled(); + } + + @Override + public boolean isDone() { + return delegate.isDone(); + } + + @Override + public boolean equals(Object obj) { + return delegate.equals(obj); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public String toString() { + return toString; + } + + } + @Provides @Singleton @Named(Constants.PROPERTY_USER_THREADS) diff --git a/core/src/main/java/org/jclouds/util/Utils.java b/core/src/main/java/org/jclouds/util/Utils.java index 23b75726b3..41c3667de8 100644 --- a/core/src/main/java/org/jclouds/util/Utils.java +++ b/core/src/main/java/org/jclouds/util/Utils.java @@ -244,7 +244,7 @@ public class Utils { @SuppressWarnings("unchecked") @Deprecated public static Iterable getSupportedProvidersOfTypeInProperties( - final Class type, final Properties properties) { + final Class> type, final Properties properties) { return Providers.getSupportedProvidersOfTypeInProperties(type, properties); } diff --git a/core/src/test/java/org/jclouds/concurrent/FuturesTestingUtils.java b/core/src/test/java/org/jclouds/concurrent/FuturesTestingUtils.java index 2ca98a4f5a..957a46e76e 100644 --- a/core/src/test/java/org/jclouds/concurrent/FuturesTestingUtils.java +++ b/core/src/test/java/org/jclouds/concurrent/FuturesTestingUtils.java @@ -51,7 +51,7 @@ public class FuturesTestingUtils { long start = System.currentTimeMillis(); Map> responses = newHashMap(); for (int i = 0; i < COUNT; i++) - responses.put(i + "", Futures.compose(createFuture(callableExecutor, chainExecutor), + responses.put(i + "", Futures.transform(createFuture(callableExecutor, chainExecutor), new Function() { @Override diff --git a/scriptbuilder/pom.xml b/scriptbuilder/pom.xml index 3f634a073d..c2557de972 100644 --- a/scriptbuilder/pom.xml +++ b/scriptbuilder/pom.xml @@ -38,7 +38,7 @@ com.google.guava guava - r08 + r09 com.google.code.findbugs