Issue 519:update to guava r09

This commit is contained in:
Adrian Cole 2011-04-08 15:36:04 -07:00
parent e05df77b08
commit 0ccdc36480
6 changed files with 158 additions and 7 deletions

View File

@ -111,7 +111,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r08</version>
<version>r09</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>

View File

@ -226,11 +226,12 @@ public class Futures {
return Futures.LazyListenableFutureFunctionAdapter.create(
((org.jclouds.concurrent.Futures.ListenableFutureAdapter<I>) 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);
}
}

View File

@ -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 <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
return delegate.invokeAll(tasks);
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException {
return delegate.invokeAll(tasks, timeout, unit);
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
return delegate.invokeAny(tasks);
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> 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<Runnable> shutdownNow() {
return delegate.shutdownNow();
}
@Override
public <T> Future<T> submit(Callable<T> task) {
return new AddToStringFuture<T>(delegate.submit(task), task.toString());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Future<?> submit(Runnable task) {
return new AddToStringFuture(delegate.submit(task), task.toString());
}
@Override
public <T> Future<T> submit(Runnable task, T result) {
return new AddToStringFuture<T>(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<T> implements Future<T> {
private final Future<T> delegate;
private final String toString;
public AddToStringFuture(Future<T> 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)

View File

@ -244,7 +244,7 @@ public class Utils {
@SuppressWarnings("unchecked")
@Deprecated
public static Iterable<String> getSupportedProvidersOfTypeInProperties(
final Class<? extends RestContextBuilder> type, final Properties properties) {
final Class<? extends RestContextBuilder<?,?>> type, final Properties properties) {
return Providers.getSupportedProvidersOfTypeInProperties(type, properties);
}

View File

@ -51,7 +51,7 @@ public class FuturesTestingUtils {
long start = System.currentTimeMillis();
Map<String, Future<Long>> 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<Long, Long>() {
@Override

View File

@ -38,7 +38,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r08</version>
<version>r09</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>