updated to use standard guava Futures and ListenableFuture

This commit is contained in:
Adrian Cole 2013-01-13 09:31:10 -08:00
parent 713a498c22
commit 3962b30808
93 changed files with 684 additions and 822 deletions

View File

@ -19,12 +19,12 @@
package org.jclouds.atmos.blobstore; package org.jclouds.atmos.blobstore;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.transform;
import static org.jclouds.atmos.options.PutOptions.Builder.publicRead; import static org.jclouds.atmos.options.PutOptions.Builder.publicRead;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -56,7 +56,6 @@ import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.crypto.Crypto; import org.jclouds.crypto.Crypto;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -66,6 +65,7 @@ import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -86,14 +86,14 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
@Inject @Inject
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AtmosAsyncClient async, AtmosClient sync, @Memoized Supplier<Set<? extends Location>> locations, AtmosAsyncClient async, AtmosClient sync,
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions, BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto, DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, Boolean> isPublic) { LoadingCache<String, Boolean> isPublic) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
@ -113,12 +113,12 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return Futures.compose(async.headFile(container + "/" + key), new Function<AtmosObject, BlobMetadata>() { return transform(async.headFile(container + "/" + key), new Function<AtmosObject, BlobMetadata>() {
@Override @Override
public BlobMetadata apply(AtmosObject from) { public BlobMetadata apply(AtmosObject from) {
return object2BlobMd.apply(from); return object2BlobMd.apply(from);
} }
}, service); }, userExecutor);
} }
/** /**
@ -128,13 +128,11 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) { public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) {
return Futures.compose(async.createDirectory(container), new Function<URI, Boolean>() { return transform(async.createDirectory(container), new Function<URI, Boolean>() {
public Boolean apply(URI from) { public Boolean apply(URI from) {
return true; return true;
} }
}, userExecutor);
}, service);
} }
/** /**
@ -142,13 +140,11 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Void> createDirectory(String container, String directory) { public ListenableFuture<Void> createDirectory(String container, String directory) {
return Futures.compose(async.createDirectory(container + "/" + directory), new Function<URI, Void>() { return transform(async.createDirectory(container + "/" + directory), new Function<URI, Void>() {
public Void apply(URI from) { public Void apply(URI from) {
return null;// no etag return null;// no etag
} }
}, userExecutor);
}, service);
} }
/** /**
@ -204,7 +200,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(options); GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
ListenableFuture<AtmosObject> returnVal = async.readFile(container + "/" + key, httpOptions); ListenableFuture<AtmosObject> returnVal = async.readFile(container + "/" + key, httpOptions);
return Futures.compose(returnVal, object2Blob, service); return transform(returnVal, object2Blob, userExecutor);
} }
/** /**
@ -212,7 +208,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<PageSet<? extends StorageMetadata>> list() { public ListenableFuture<PageSet<? extends StorageMetadata>> list() {
return Futures.compose(async.listDirectories(), container2ResourceList, service); return transform(async.listDirectories(), container2ResourceList, userExecutor);
} }
/** /**
@ -224,10 +220,10 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options); container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options);
ListOptions nativeOptions = container2ContainerListOptions.apply(options); ListOptions nativeOptions = container2ContainerListOptions.apply(options);
ListenableFuture<BoundedSet<? extends DirectoryEntry>> returnVal = async.listDirectory(container, nativeOptions); ListenableFuture<BoundedSet<? extends DirectoryEntry>> returnVal = async.listDirectory(container, nativeOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, container2ResourceList, ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, container2ResourceList,
service); userExecutor);
return (ListenableFuture<PageSet<? extends StorageMetadata>>) (options.isDetailed() ? Futures.compose(list, return (ListenableFuture<PageSet<? extends StorageMetadata>>) (options.isDetailed() ? transform(list,
fetchBlobMetadataProvider.get().setContainerName(container), service) : list); fetchBlobMetadataProvider.get().setContainerName(container)) : list);
} }
/** /**
@ -244,7 +240,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
} catch (CacheLoader.InvalidCacheLoadException e) { } catch (CacheLoader.InvalidCacheLoadException e) {
// nulls not permitted // nulls not permitted
} }
return Futures.makeListenable(service.submit(new Callable<String>() { return userExecutor.submit(new Callable<String>() {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
@ -255,7 +251,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public String toString() { public String toString() {
return "putBlob(" + container + "," + blob.getMetadata().getName() + ")"; return "putBlob(" + container + "," + blob.getMetadata().getName() + ")";
} }
}), service); });
} }
@ -277,13 +273,13 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container, public ListenableFuture<Boolean> createContainerInLocation(Location location, String container,
CreateContainerOptions options) { CreateContainerOptions options) {
if (options.isPublicRead()) if (options.isPublicRead())
return Futures.compose(async.createDirectory(container, publicRead()), new Function<URI, Boolean>() { return transform(async.createDirectory(container, publicRead()), new Function<URI, Boolean>() {
public Boolean apply(URI from) { public Boolean apply(URI from) {
return true; return true;
} }
}, service); }, userExecutor);
return createContainerInLocation(location, container); return createContainerInLocation(location, container);
} }

View File

@ -26,11 +26,9 @@ import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -45,12 +43,12 @@ import org.jclouds.blobstore.internal.BlobRuntimeException;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.blobstore.strategy.ListBlobsInContainer; import org.jclouds.blobstore.strategy.ListBlobsInContainer;
import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -65,7 +63,7 @@ public class FindMD5InUserMetadata implements ContainsValueInListStrategy {
protected final ObjectMD5 objectMD5; protected final ObjectMD5 objectMD5;
protected final ListBlobsInContainer getAllBlobMetadata; protected final ListBlobsInContainer getAllBlobMetadata;
private final AtmosAsyncClient client; private final AtmosAsyncClient client;
private final ExecutorService userExecutor; private final ListeningExecutorService userExecutor;
/** /**
* maximum duration of an blob Request * maximum duration of an blob Request
*/ */
@ -74,7 +72,7 @@ public class FindMD5InUserMetadata implements ContainsValueInListStrategy {
protected Long maxTime; protected Long maxTime;
@Inject @Inject
FindMD5InUserMetadata(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, ObjectMD5 objectMD5, FindMD5InUserMetadata(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ObjectMD5 objectMD5,
ListBlobsInContainer getAllBlobMetadata, AtmosAsyncClient client) { ListBlobsInContainer getAllBlobMetadata, AtmosAsyncClient client) {
this.objectMD5 = objectMD5; this.objectMD5 = objectMD5;
this.getAllBlobMetadata = getAllBlobMetadata; this.getAllBlobMetadata = getAllBlobMetadata;
@ -86,10 +84,9 @@ public class FindMD5InUserMetadata implements ContainsValueInListStrategy {
public boolean execute(final String containerName, Object value, ListContainerOptions options) { public boolean execute(final String containerName, Object value, ListContainerOptions options) {
final byte[] toSearch = objectMD5.apply(value); final byte[] toSearch = objectMD5.apply(value);
final BlockingQueue<Boolean> queue = new SynchronousQueue<Boolean>(); final BlockingQueue<Boolean> queue = new SynchronousQueue<Boolean>();
Map<String, Future<?>> responses = Maps.newHashMap(); Map<String, ListenableFuture<?>> responses = Maps.newHashMap();
for (BlobMetadata md : getAllBlobMetadata.execute(containerName, options)) { for (BlobMetadata md : getAllBlobMetadata.execute(containerName, options)) {
final ListenableFuture<AtmosObject> future = Futures.makeListenable( final ListenableFuture<AtmosObject> future = client.headFile(containerName + "/" + md.getName());
client.headFile(containerName + "/" + md.getName()), userExecutor);
future.addListener(new Runnable() { future.addListener(new Runnable() {
public void run() { public void run() {
try { try {

View File

@ -24,7 +24,6 @@ import static com.google.common.util.concurrent.Futures.immediateFuture;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -47,12 +46,13 @@ import org.jclouds.blobstore.LocalAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Implementation of {@link AtmosAsyncClient} which keeps all data in a local Map object. * Implementation of {@link AtmosAsyncClient} which keeps all data in a local Map object.
@ -68,13 +68,13 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
private final BlobMetadataToObject blob2ObjectInfo; private final BlobMetadataToObject blob2ObjectInfo;
private final ListOptionsToBlobStoreListOptions container2ContainerListOptions; private final ListOptionsToBlobStoreListOptions container2ContainerListOptions;
private final ResourceMetadataListToDirectoryEntryList resource2ObjectList; private final ResourceMetadataListToDirectoryEntryList resource2ObjectList;
private final ExecutorService service; private final ListeningExecutorService userExecutor;
@Inject @Inject
private StubAtmosAsyncClient(LocalAsyncBlobStore blobStore, AtmosObject.Factory objectProvider, private StubAtmosAsyncClient(LocalAsyncBlobStore blobStore, AtmosObject.Factory objectProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object, HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
BlobMetadataToObject blob2ObjectInfo, ListOptionsToBlobStoreListOptions container2ContainerListOptions, BlobMetadataToObject blob2ObjectInfo, ListOptionsToBlobStoreListOptions container2ContainerListOptions,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
ResourceMetadataListToDirectoryEntryList resource2ContainerList) { ResourceMetadataListToDirectoryEntryList resource2ContainerList) {
this.blobStore = blobStore; this.blobStore = blobStore;
this.objectProvider = objectProvider; this.objectProvider = objectProvider;
@ -85,7 +85,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
"container2ContainerListOptions"); "container2ContainerListOptions");
this.resource2ObjectList = checkNotNull(resource2ContainerList, "resource2ContainerList"); this.resource2ObjectList = checkNotNull(resource2ContainerList, "resource2ContainerList");
this.service = service; this.userExecutor = userExecutor;
} }
@Override @Override
@ -99,7 +99,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
container = directoryName; container = directoryName;
path = null; path = null;
} }
return Futures.compose(blobStore.createContainerInLocation(null, container), new Function<Boolean, URI>() { return Futures.transform(blobStore.createContainerInLocation(null, container), new Function<Boolean, URI>() {
public URI apply(Boolean from) { public URI apply(Boolean from) {
if (path != null) { if (path != null) {
@ -109,7 +109,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
return URI.create("http://stub/containers/" + container); return URI.create("http://stub/containers/" + container);
} }
}, service); }, userExecutor);
} }
@Override @Override
@ -124,27 +124,27 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
object.getContentMetadata().setName(path + "/" + file); object.getContentMetadata().setName(path + "/" + file);
} }
Blob blob = object2Blob.apply(object); Blob blob = object2Blob.apply(object);
return Futures.compose(blobStore.putBlob(container, blob), new Function<String, URI>() { return Futures.transform(blobStore.putBlob(container, blob), new Function<String, URI>() {
public URI apply(String from) { public URI apply(String from) {
return URI.create(uri); return URI.create(uri);
} }
}, service); }, userExecutor);
} }
@Override @Override
public ListenableFuture<Void> deletePath(String path) { public ListenableFuture<Void> deletePath(String path) {
if (path.indexOf('/') == path.length() - 1) { if (path.indexOf('/') == path.length() - 1) {
// chop off the trailing slash // chop off the trailing slash
return Futures.compose(blobStore.deleteContainerIfEmpty(path.substring(0, path.length() - 1)), return Futures.transform(blobStore.deleteContainerIfEmpty(path.substring(0, path.length() - 1)),
new Function<Boolean, Void>() { new Function<Boolean, Void>() {
public Void apply(Boolean from) { public Void apply(Boolean from) {
return null; return null;
} }
}, service); }, userExecutor);
} else { } else {
String container = path.substring(0, path.indexOf('/')); String container = path.substring(0, path.indexOf('/'));
path = path.substring(path.indexOf('/') + 1); path = path.substring(path.indexOf('/') + 1);
@ -164,11 +164,11 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
else { else {
String container = path.substring(0, path.indexOf('/')); String container = path.substring(0, path.indexOf('/'));
path = path.substring(path.indexOf('/') + 1); path = path.substring(path.indexOf('/') + 1);
return Futures.compose(blobStore.blobMetadata(container, path), new Function<BlobMetadata, UserMetadata>() { return Futures.transform(blobStore.blobMetadata(container, path), new Function<BlobMetadata, UserMetadata>() {
public UserMetadata apply(BlobMetadata from) { public UserMetadata apply(BlobMetadata from) {
return blob2ObjectInfo.apply(from).getUserMetadata(); return blob2ObjectInfo.apply(from).getUserMetadata();
} }
}, service); }, userExecutor);
} }
} }
@ -177,7 +177,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
String container = path.substring(0, path.indexOf('/')); String container = path.substring(0, path.indexOf('/'));
path = path.substring(path.indexOf('/') + 1); path = path.substring(path.indexOf('/') + 1);
try { try {
return Futures.compose(blobStore.getBlob(container, path), blob2Object, service); return Futures.transform(blobStore.getBlob(container, path), blob2Object, userExecutor);
} catch (Exception e) { } catch (Exception e) {
return immediateFailedFuture(Throwables.getRootCause(e)); return immediateFailedFuture(Throwables.getRootCause(e));
} }
@ -187,7 +187,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
public ListenableFuture<BoundedSet<? extends DirectoryEntry>> listDirectories(ListOptions... optionsList) { public ListenableFuture<BoundedSet<? extends DirectoryEntry>> listDirectories(ListOptions... optionsList) {
// org.jclouds.blobstore.options.ListOptions options = container2ContainerListOptions // org.jclouds.blobstore.options.ListOptions options = container2ContainerListOptions
// .apply(optionsList); // .apply(optionsList);
return Futures.compose(blobStore.list(), resource2ObjectList, service); return Futures.transform(blobStore.list(), resource2ObjectList, userExecutor);
} }
@Override @Override
@ -201,7 +201,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
if (!path.equals("")) if (!path.equals(""))
options.inDirectory(path); options.inDirectory(path);
} }
return Futures.compose(blobStore.list(container, options), resource2ObjectList, service); return Futures.transform(blobStore.list(container, options), resource2ObjectList, userExecutor);
} }
@Override @Override
@ -232,7 +232,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
String container = path.substring(0, path.indexOf('/')); String container = path.substring(0, path.indexOf('/'));
String blobName = path.substring(path.indexOf('/') + 1); String blobName = path.substring(path.indexOf('/') + 1);
org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options); org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options);
return Futures.compose(blobStore.getBlob(container, blobName, getOptions), blob2Object, service); return Futures.transform(blobStore.getBlob(container, blobName, getOptions), blob2Object, userExecutor);
} }
@Override @Override

View File

@ -18,8 +18,9 @@
*/ */
package org.jclouds.cloudfiles.blobstore; package org.jclouds.cloudfiles.blobstore;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,7 +37,6 @@ import org.jclouds.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.cloudfiles.CloudFilesClient; import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache; import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions;
@ -45,11 +45,12 @@ import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList;
import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata; import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata;
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob;
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
import org.jclouds.openstack.swift.blobstore.strategy.internal.AsyncMultipartUploadStrategy;
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.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.openstack.swift.blobstore.strategy.internal.AsyncMultipartUploadStrategy; import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -61,7 +62,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
@Inject @Inject
protected CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async, @Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async,
ContainerToResourceMetadata container2ResourceMd, ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -69,7 +70,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations, sync, async, container2ResourceMd, super(context, blobUtils, userExecutor, defaultLocation, locations, sync, async, container2ResourceMd,
container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy); blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
this.enableCDNAndCache = enableCDNAndCache; this.enableCDNAndCache = enableCDNAndCache;
@ -81,7 +82,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container); ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container);
if (options.isPublicRead()) if (options.isPublicRead())
return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() { return transform(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
@Override @Override
public Boolean apply(Boolean input) { public Boolean apply(Boolean input) {
@ -91,7 +92,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
return false; return false;
} }
}, service); }, userExecutor);
return returnVal; return returnVal;
} }
} }

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -41,12 +40,12 @@ import org.jclouds.compute.domain.ImageTemplate;
import org.jclouds.compute.domain.ImageTemplateBuilder; import org.jclouds.compute.domain.ImageTemplateBuilder;
import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.PredicateWithResult; import org.jclouds.predicates.PredicateWithResult;
import org.jclouds.predicates.Retryables; import org.jclouds.predicates.Retryables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* CloudServers implementation of {@link ImageExtension} * CloudServers implementation of {@link ImageExtension}
@ -62,7 +61,7 @@ public class CloudServersImageExtension implements ImageExtension {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final CloudServersClient client; private final CloudServersClient client;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
private final PredicateWithResult<Integer, Image> imageAvailablePredicate; private final PredicateWithResult<Integer, Image> imageAvailablePredicate;
@com.google.inject.Inject(optional = true) @com.google.inject.Inject(optional = true)
@Named("IMAGE_MAX_WAIT") @Named("IMAGE_MAX_WAIT")
@ -73,11 +72,11 @@ public class CloudServersImageExtension implements ImageExtension {
@Inject @Inject
public CloudServersImageExtension(CloudServersClient client, public CloudServersImageExtension(CloudServersClient client,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
PredicateWithResult<Integer, Image> imageAvailablePredicate) { PredicateWithResult<Integer, Image> imageAvailablePredicate) {
this.client = checkNotNull(client); this.client = checkNotNull(client, "client");
this.executor = userThreads; this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.imageAvailablePredicate = imageAvailablePredicate; this.imageAvailablePredicate = checkNotNull(imageAvailablePredicate, "imageAvailablePredicate");
} }
@Override @Override
@ -96,14 +95,14 @@ public class CloudServersImageExtension implements ImageExtension {
CloneImageTemplate cloneTemplate = (CloneImageTemplate) template; CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
final org.jclouds.cloudservers.domain.Image image = client.createImageFromServer(cloneTemplate.getName(), final org.jclouds.cloudservers.domain.Image image = client.createImageFromServer(cloneTemplate.getName(),
Integer.parseInt(cloneTemplate.getSourceNodeId())); Integer.parseInt(cloneTemplate.getSourceNodeId()));
return Futures.makeListenable(executor.submit(new Callable<Image>() { return userExecutor.submit(new Callable<Image>() {
@Override @Override
public Image call() throws Exception { public Image call() throws Exception {
return Retryables.retryGettingResultOrFailing(imageAvailablePredicate, image.getId(), maxWait, waitPeriod, return Retryables.retryGettingResultOrFailing(imageAvailablePredicate, image.getId(), maxWait, waitPeriod,
TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: " + maxWait TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: " + maxWait
+ " secs.]"); + " secs.]");
} }
}), executor); });
} }

View File

@ -22,9 +22,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -66,6 +63,8 @@ import com.google.common.collect.ImmutableList;
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.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.UncheckedExecutionException;
/** /**
@ -89,7 +88,7 @@ public class CloudSigmaComputeServiceAdapter implements
private final Predicate<DriveInfo> driveNotClaimed; private final Predicate<DriveInfo> driveNotClaimed;
private final String defaultVncPassword; private final String defaultVncPassword;
private final LoadingCache<String, DriveInfo> cache; private final LoadingCache<String, DriveInfo> cache;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -98,13 +97,13 @@ public class CloudSigmaComputeServiceAdapter implements
@Inject @Inject
public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, Predicate<DriveInfo> driveNotClaimed, public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, Predicate<DriveInfo> driveNotClaimed,
@Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, @Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword,
LoadingCache<String, DriveInfo> cache, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { LoadingCache<String, DriveInfo> cache, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!"); checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!");
this.cache = checkNotNull(cache, "cache"); this.cache = checkNotNull(cache, "cache");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
@ -171,10 +170,10 @@ public class CloudSigmaComputeServiceAdapter implements
@Override @Override
public Iterable<DriveInfo> listImages() { public Iterable<DriveInfo> listImages() {
return FluentIterable.from(transformParallel(client.listStandardDrives(), return FluentIterable.from(transformParallel(client.listStandardDrives(),
new Function<String, Future<? extends DriveInfo>>() { new Function<String, ListenableFuture<? extends DriveInfo>>() {
@Override @Override
public Future<DriveInfo> apply(String input) { public ListenableFuture<DriveInfo> apply(String input) {
try { try {
return Futures.immediateFuture(cache.getUnchecked(input)); return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) { } catch (CacheLoader.InvalidCacheLoadException e) {
@ -189,7 +188,7 @@ public class CloudSigmaComputeServiceAdapter implements
public String toString() { public String toString() {
return "seedDriveCache()"; return "seedDriveCache()";
} }
}, executor, null, logger, "drives")).filter(PREINSTALLED_DISK); }, userExecutor, null, logger, "drives")).filter(PREINSTALLED_DISK);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -35,7 +35,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
@ -96,6 +95,7 @@ import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -124,7 +124,7 @@ public class EC2ComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client client, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, EC2Client client,
ConcurrentMap<RegionAndName, KeyPair> credentialsMap, ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap, @Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention,
@ -133,7 +133,7 @@ public class EC2ComputeService extends BaseComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension); persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.client = client; this.client = client;
this.credentialsMap = credentialsMap; this.credentialsMap = credentialsMap;
this.securityGroupMap = securityGroupMap; this.securityGroupMap = securityGroupMap;

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -39,7 +38,6 @@ import org.jclouds.compute.domain.ImageTemplate;
import org.jclouds.compute.domain.ImageTemplateBuilder; import org.jclouds.compute.domain.ImageTemplateBuilder;
import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
@ -50,6 +48,7 @@ import org.jclouds.predicates.Retryables;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* EC2 implementation of {@link ImageExtension} please note that {@link #createImage(ImageTemplate)} * EC2 implementation of {@link ImageExtension} please note that {@link #createImage(ImageTemplate)}
@ -64,7 +63,7 @@ public class EC2ImageExtension implements ImageExtension {
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final EC2Client ec2Client; private final EC2Client ec2Client;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
private final PredicateWithResult<String, Image> imageReadyPredicate; private final PredicateWithResult<String, Image> imageReadyPredicate;
@com.google.inject.Inject(optional = true) @com.google.inject.Inject(optional = true)
@Named("IMAGE_MAX_WAIT") @Named("IMAGE_MAX_WAIT")
@ -74,10 +73,10 @@ public class EC2ImageExtension implements ImageExtension {
private long waitPeriod = 1; private long waitPeriod = 1;
@Inject @Inject
public EC2ImageExtension(EC2Client ec2Client, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, public EC2ImageExtension(EC2Client ec2Client, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
PredicateWithResult<String, Image> imageReadyPredicate) { PredicateWithResult<String, Image> imageReadyPredicate) {
this.ec2Client = checkNotNull(ec2Client); this.ec2Client = checkNotNull(ec2Client);
this.executor = checkNotNull(userThreads); this.userExecutor = checkNotNull(userExecutor);
this.imageReadyPredicate = imageReadyPredicate; this.imageReadyPredicate = imageReadyPredicate;
} }
@ -105,14 +104,14 @@ public class EC2ImageExtension implements ImageExtension {
final String imageId = ec2Client.getAMIServices().createImageInRegion(region, cloneTemplate.getName(), final String imageId = ec2Client.getAMIServices().createImageInRegion(region, cloneTemplate.getName(),
instanceId, CreateImageOptions.NONE); instanceId, CreateImageOptions.NONE);
return Futures.makeListenable(executor.submit(new Callable<Image>() { return userExecutor.submit(new Callable<Image>() {
@Override @Override
public Image call() throws Exception { public Image call() throws Exception {
return Retryables.retryGettingResultOrFailing(imageReadyPredicate, region + "/" + imageId, maxWait, return Retryables.retryGettingResultOrFailing(imageReadyPredicate, region + "/" + imageId, maxWait,
waitPeriod, TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: " waitPeriod, TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: "
+ maxWait + " secs.]"); + maxWait + " secs.]");
} }
}), executor); });
} }
@Override @Override

View File

@ -23,8 +23,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -38,6 +36,8 @@ import org.jclouds.ec2.options.DescribeImagesOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -51,13 +51,12 @@ public class DescribeImagesParallel implements
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final EC2AsyncClient async; protected final EC2AsyncClient async;
final ExecutorService executor; final ListeningExecutorService userExecutor;
@Inject @Inject
public DescribeImagesParallel(EC2AsyncClient async, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { public DescribeImagesParallel(EC2AsyncClient async, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
super();
this.async = async; this.async = async;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
@ -65,15 +64,11 @@ public class DescribeImagesParallel implements
Iterable<Entry<String, DescribeImagesOptions>> queries) { Iterable<Entry<String, DescribeImagesOptions>> queries) {
return concat(transformParallel( return concat(transformParallel(
queries, queries,
new Function<Entry<String, DescribeImagesOptions>, Future<? extends Set<? extends org.jclouds.ec2.domain.Image>>>() { new Function<Entry<String, DescribeImagesOptions>, ListenableFuture<? extends Set<? extends org.jclouds.ec2.domain.Image>>>() {
public ListenableFuture<Set<? extends org.jclouds.ec2.domain.Image>> apply(
@Override
public Future<Set<? extends org.jclouds.ec2.domain.Image>> apply(
Entry<String, DescribeImagesOptions> from) { Entry<String, DescribeImagesOptions> from) {
return async.getAMIServices().describeImagesInRegion(from.getKey(), from.getValue()); return async.getAMIServices().describeImagesInRegion(from.getKey(), from.getValue());
} }
}, userExecutor, null, logger, "amis"));
}, executor, null, logger, "amis"));
} }
} }

View File

@ -30,7 +30,6 @@ import static org.jclouds.ec2.compute.util.EC2ComputeUtils.getZoneFromLocationOr
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -65,6 +64,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
/** /**
* creates futures that correlate to * creates futures that correlate to
@ -129,7 +129,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
}; };
@Override @Override
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate = template.clone(); Template mutableTemplate = template.clone();

View File

@ -27,8 +27,6 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -50,6 +48,8 @@ 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.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -70,16 +70,16 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
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;
protected final ExecutorService executor; protected final ListeningExecutorService userExecutor;
@Inject @Inject
protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Supplier<Set<String>> regions, protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.regions = checkNotNull(regions, "regions"); this.regions = checkNotNull(regions, "regions");
this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata"); this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
@ -97,21 +97,14 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel( Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
regions.get(), new Function<String, Future<? extends Set<? extends Reservation<? extends RunningInstance>>>>() { regions.get(), new Function<String, ListenableFuture<? extends Set<? extends Reservation<? extends RunningInstance>>>>() {
@Override @Override
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) { public ListenableFuture<? extends Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7126754 return client.getInstanceServices().describeInstancesInRegion(from);
return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
} }
}, executor, maxTime, logger, "reservations"); }, userExecutor, maxTime, logger, "reservations");
return concat(concat(reservations)); return concat(concat(reservations));
} }
@SuppressWarnings("unchecked")
private static <T> Future<T> castToSpecificTypedFuture(Future<? extends T> input) {
return (Future<T>) input;
}
} }

View File

@ -25,8 +25,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import static org.jclouds.elasticstack.util.Servers.small; import static org.jclouds.elasticstack.util.Servers.small;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -67,6 +65,8 @@ import com.google.common.collect.ImmutableList;
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.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.UncheckedExecutionException;
/** /**
@ -82,7 +82,7 @@ public class ElasticStackComputeServiceAdapter implements
private final Map<String, WellKnownImage> preinstalledImages; private final Map<String, WellKnownImage> preinstalledImages;
private final LoadingCache<String, DriveInfo> cache; private final LoadingCache<String, DriveInfo> cache;
private final String defaultVncPassword; private final String defaultVncPassword;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -92,14 +92,14 @@ public class ElasticStackComputeServiceAdapter implements
public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate<DriveInfo> driveNotClaimed, public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate<DriveInfo> driveNotClaimed,
Map<String, WellKnownImage> preinstalledImages, LoadingCache<String, DriveInfo> cache, Map<String, WellKnownImage> preinstalledImages, LoadingCache<String, DriveInfo> cache,
@Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, @Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages"); this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages");
this.cache = checkNotNull(cache, "cache"); this.cache = checkNotNull(cache, "cache");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword"); this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!"); checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
@ -164,10 +164,10 @@ public class ElasticStackComputeServiceAdapter implements
@Override @Override
public Iterable<DriveInfo> listImages() { public Iterable<DriveInfo> listImages() {
return FluentIterable.from(transformParallel(preinstalledImages.keySet(), return FluentIterable.from(transformParallel(preinstalledImages.keySet(),
new Function<String, Future<? extends DriveInfo>>() { new Function<String, ListenableFuture<? extends DriveInfo>>() {
@Override @Override
public Future<? extends DriveInfo> apply(String input) { public ListenableFuture<? extends DriveInfo> apply(String input) {
try { try {
return Futures.immediateFuture(cache.getUnchecked(input)); return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) { } catch (CacheLoader.InvalidCacheLoadException e) {
@ -183,7 +183,7 @@ public class ElasticStackComputeServiceAdapter implements
return "seedDriveCache()"; return "seedDriveCache()";
} }
}, executor, null, logger, "drives")).filter(notNull()); }, userExecutor, null, logger, "drives")).filter(notNull());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -25,7 +25,6 @@ import static org.jclouds.openstack.nova.v2_0.predicates.KeyPairPredicates.nameM
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -77,6 +76,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -104,7 +104,7 @@ public class NovaComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, NovaApi novaApi, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, NovaApi novaApi,
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap, LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap,
LoadingCache<ZoneAndName, KeyPair> keyPairCache, LoadingCache<ZoneAndName, KeyPair> keyPairCache,
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId, Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId,
@ -113,7 +113,7 @@ public class NovaComputeService extends BaseComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension); persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.novaApi = checkNotNull(novaApi, "novaApi"); this.novaApi = checkNotNull(novaApi, "novaApi");
this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap"); this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap");
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache"); this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -39,7 +38,6 @@ import org.jclouds.compute.domain.ImageTemplate;
import org.jclouds.compute.domain.ImageTemplateBuilder; import org.jclouds.compute.domain.ImageTemplateBuilder;
import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.nova.v2_0.domain.Server;
@ -48,6 +46,7 @@ import org.jclouds.predicates.PredicateWithResult;
import org.jclouds.predicates.Retryables; import org.jclouds.predicates.Retryables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Nova implementation of {@link ImageExtension} * Nova implementation of {@link ImageExtension}
@ -63,7 +62,7 @@ public class NovaImageExtension implements ImageExtension {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final NovaApi novaApi; private final NovaApi novaApi;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@com.google.inject.Inject(optional = true) @com.google.inject.Inject(optional = true)
@Named("IMAGE_MAX_WAIT") @Named("IMAGE_MAX_WAIT")
private long maxWait = 3600; private long maxWait = 3600;
@ -74,10 +73,10 @@ public class NovaImageExtension implements ImageExtension {
@Inject @Inject
public NovaImageExtension(NovaApi novaApi, public NovaImageExtension(NovaApi novaApi,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
PredicateWithResult<ZoneAndId, Image> imageReadyPredicate) { PredicateWithResult<ZoneAndId, Image> imageReadyPredicate) {
this.novaApi = checkNotNull(novaApi); this.novaApi = checkNotNull(novaApi);
this.executor = userThreads; this.userExecutor = userExecutor;
this.imageReadyPredicate = imageReadyPredicate; this.imageReadyPredicate = imageReadyPredicate;
} }
@ -105,14 +104,14 @@ public class NovaImageExtension implements ImageExtension {
logger.info(">> Registered new Image %s, waiting for it to become available.", newImageId); logger.info(">> Registered new Image %s, waiting for it to become available.", newImageId);
return Futures.makeListenable(executor.submit(new Callable<Image>() { return userExecutor.submit(new Callable<Image>() {
@Override @Override
public Image call() throws Exception { public Image call() throws Exception {
return Retryables.retryGettingResultOrFailing(imageReadyPredicate, targetImageZoneAndId, maxWait, return Retryables.retryGettingResultOrFailing(imageReadyPredicate, targetImageZoneAndId, maxWait,
waitPeriod, TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: " waitPeriod, TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: "
+ maxWait + " secs.]"); + maxWait + " secs.]");
} }
}), executor); });
} }
@Override @Override

View File

@ -26,8 +26,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -43,7 +41,6 @@ import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import org.jclouds.concurrent.Futures;
import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.compute.functions.AllocateAndAddFloatingIpToNode; import org.jclouds.openstack.nova.v2_0.compute.functions.AllocateAndAddFloatingIpToNode;
import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions; import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
@ -56,6 +53,9 @@ import com.google.common.base.Throwables;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -76,11 +76,11 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention, GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode, AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode,
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache, LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaApi novaApi) { LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaApi novaApi) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache"); this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache"); this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
@ -90,7 +90,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
} }
@Override @Override
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate = template.clone(); Template mutableTemplate = template.clone();
@ -149,14 +149,14 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
} }
@Override @Override
protected Future<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group, protected ListenableFuture<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group,
final String name, Template template) { final String name, Template template) {
Future<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template); ListenableFuture<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template);
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions()); NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
if (templateOptions.shouldAutoAssignFloatingIp()) { if (templateOptions.shouldAutoAssignFloatingIp()) {
return Futures.compose(future, createAndAddFloatingIpToNode, executor); return Futures.transform(future, createAndAddFloatingIpToNode, userExecutor);
} else { } else {
return future; return future;
} }

View File

@ -21,26 +21,20 @@ package org.jclouds.rackspace.cloudloadbalancers.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy; import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.logging.Logger;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi; import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
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.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.ImmutableSet.Builder;
/** /**
* *
@ -48,38 +42,25 @@ import com.google.common.collect.Sets;
*/ */
@Singleton @Singleton
public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBalancersStrategy { public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBalancersStrategy {
@Resource
@Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
protected Logger logger = Logger.NULL;
private final CloudLoadBalancersApi aclient; private final CloudLoadBalancersApi aclient;
private final Function<LoadBalancer, LoadBalancerMetadata> converter; private final Function<LoadBalancer, LoadBalancerMetadata> converter;
private final ExecutorService executor; // leaving this here for possible future parallelization
private final Supplier<Set<String>> zones; private final Supplier<Set<String>> zones;
@Inject @Inject
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersApi aclient, protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersApi aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter, Function<LoadBalancer, LoadBalancerMetadata> converter, @Zone Supplier<Set<String>> zones) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Zone Supplier<Set<String>> zones) {
this.aclient = checkNotNull(aclient, "aclient"); this.aclient = checkNotNull(aclient, "aclient");
this.zones = checkNotNull(zones, "zones"); this.zones = checkNotNull(zones, "zones");
this.converter = checkNotNull(converter, "converter"); this.converter = checkNotNull(converter, "converter");
this.executor = checkNotNull(executor, "executor");
} }
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
Set<LoadBalancerMetadata> loadBalancerMetadatas = Sets.newHashSet(); Builder<LoadBalancerMetadata> loadBalancers = ImmutableSet.<LoadBalancerMetadata> builder();
for (String zone : zones.get()) { // TODO: parallel
for (String zone: zones.get()) { loadBalancers.addAll(aclient.getLoadBalancerApiForZone(zone).list().concat().transform(converter));
FluentIterable<LoadBalancerMetadata> lbm =
aclient.getLoadBalancerApiForZone(zone).list().concat().transform(converter);
for (LoadBalancerMetadata loadBalancerMetadata: lbm) {
loadBalancerMetadatas.add(loadBalancerMetadata);
}
} }
return loadBalancers.build();
return loadBalancerMetadatas;
} }
} }

View File

@ -19,6 +19,9 @@
package org.jclouds.s3; package org.jclouds.s3;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.s3.domain.AccessControlList; import org.jclouds.s3.domain.AccessControlList;

View File

@ -19,9 +19,9 @@
package org.jclouds.s3.blobstore; package org.jclouds.s3.blobstore;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -42,7 +42,6 @@ import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3AsyncClient;
@ -69,6 +68,7 @@ import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -91,14 +91,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
@Inject @Inject
protected S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync, @Memoized Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync,
Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata, Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, AccessControlList> bucketAcls) { LoadingCache<String, AccessControlList> bucketAcls) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
@ -117,12 +117,12 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<PageSet<? extends StorageMetadata>> list() { public ListenableFuture<PageSet<? extends StorageMetadata>> list() {
return Futures.compose(async.listOwnedBuckets(), return transform(async.listOwnedBuckets(),
new Function<Set<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() { new Function<Set<BucketMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(Set<BucketMetadata> from) { public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(Set<BucketMetadata> from) {
return convertBucketsToStorageMetadata.apply(from); return convertBucketsToStorageMetadata.apply(from);
} }
}, service); }, userExecutor);
} }
/** /**
@ -156,14 +156,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
* bucket name * bucket name
*/ */
@Override @Override
// TODO get rid of compose, as it serializes async results when the executor is single-threaded. // TODO get rid of transform, as it serializes async results when the executor is single-threaded.
public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) { public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
ListBucketOptions httpOptions = container2BucketListOptions.apply(options); ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions); ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, bucket2ResourceList, ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, bucket2ResourceList,
service); userExecutor);
return (options.isDetailed()) ? Futures.compose(list, return (options.isDetailed()) ? transform(list,
fetchBlobMetadataProvider.get().setContainerName(container), service) : list; fetchBlobMetadataProvider.get().setContainerName(container), userExecutor) : list;
} }
/** /**
@ -196,14 +196,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return Futures.compose(async.headObject(container, key), new Function<ObjectMetadata, BlobMetadata>() { return transform(async.headObject(container, key), new Function<ObjectMetadata, BlobMetadata>() {
@Override @Override
public BlobMetadata apply(ObjectMetadata from) { public BlobMetadata apply(ObjectMetadata from) {
return object2BlobMd.apply(from); return object2BlobMd.apply(from);
} }
}, service); }, userExecutor);
} }
/** /**
@ -217,7 +217,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
@Override @Override
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(options); GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
return Futures.compose(async.getObject(container, key, httpOptions), object2Blob, service); return transform(async.getObject(container, key, httpOptions), object2Blob, userExecutor);
} }
/** /**

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -39,6 +37,8 @@ import org.jclouds.logging.Logger;
import org.jclouds.s3.domain.BucketMetadata; import org.jclouds.s3.domain.BucketMetadata;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@Singleton @Singleton
public class BucketsToStorageMetadata implements public class BucketsToStorageMetadata implements
@ -47,11 +47,11 @@ public class BucketsToStorageMetadata implements
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final ExecutorService userExecutor; private final ListeningExecutorService userExecutor;
private final BucketToResourceMetadata bucket2ResourceMd; private final BucketToResourceMetadata bucket2ResourceMd;
@Inject @Inject
public BucketsToStorageMetadata(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, BucketToResourceMetadata bucket2ResourceMd) { public BucketsToStorageMetadata(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, BucketToResourceMetadata bucket2ResourceMd) {
this.userExecutor = checkNotNull(userExecutor, "userExecutor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd"); this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd");
} }
@ -62,9 +62,9 @@ public class BucketsToStorageMetadata implements
// parallel as listing buckets is slow when looking up regions // parallel as listing buckets is slow when looking up regions
Iterable<? extends StorageMetadata> buckets = FutureIterables Iterable<? extends StorageMetadata> buckets = FutureIterables
.<BucketMetadata, StorageMetadata> transformParallel(input, .<BucketMetadata, StorageMetadata> transformParallel(input,
new Function<BucketMetadata, Future<? extends StorageMetadata>>() { new Function<BucketMetadata, ListenableFuture<? extends StorageMetadata>>() {
@Override @Override
public Future<? extends StorageMetadata> apply(final BucketMetadata from) { public ListenableFuture<? extends StorageMetadata> apply(final BucketMetadata from) {
return userExecutor.submit(new Callable<StorageMetadata>() { return userExecutor.submit(new Callable<StorageMetadata>() {
@Override @Override

View File

@ -24,12 +24,11 @@ import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCK
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.util.AWSUtils; import org.jclouds.aws.util.AWSUtils;
@ -40,6 +39,9 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.s3.S3ApiMetadata; import org.jclouds.s3.S3ApiMetadata;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
/** /**
* @author Adrian Cole * @author Adrian Cole
* *

View File

@ -23,6 +23,7 @@ import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.currentOrNull;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;

View File

@ -36,7 +36,6 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import com.google.common.reflect.Invokable;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.s3.S3Fallbacks.TrueOn404OrNotFoundFalseOnIllegalState; import org.jclouds.s3.S3Fallbacks.TrueOn404OrNotFoundFalseOnIllegalState;
@ -71,6 +70,7 @@ import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.reflect.Invokable;
import com.google.inject.Module; import com.google.inject.Module;
/** /**

View File

@ -43,13 +43,13 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.s3.domain.AccessControlList; import org.jclouds.s3.domain.AccessControlList;
import org.jclouds.s3.domain.CannedAccessPolicy;
import org.jclouds.s3.domain.ObjectMetadata;
import org.jclouds.s3.domain.S3Object;
import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee; import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee;
import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee; import org.jclouds.s3.domain.AccessControlList.EmailAddressGrantee;
import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI;
import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.domain.AccessControlList.Permission;
import org.jclouds.s3.domain.CannedAccessPolicy;
import org.jclouds.s3.domain.ObjectMetadata;
import org.jclouds.s3.domain.S3Object;
import org.jclouds.s3.options.PutObjectOptions; import org.jclouds.s3.options.PutObjectOptions;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -21,13 +21,13 @@ package org.jclouds.s3.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.immediateFailedFuture; import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -44,7 +44,6 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.util.BlobStoreUtils; import org.jclouds.blobstore.util.BlobStoreUtils;
import org.jclouds.concurrent.Futures;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationBuilder;
@ -78,6 +77,7 @@ import com.google.common.base.Function;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Implementation of {@link S3AsyncBlobStore} which keeps all data in a local Map object. * Implementation of {@link S3AsyncBlobStore} which keeps all data in a local Map object.
@ -99,17 +99,17 @@ public class StubS3AsyncClient implements S3AsyncClient {
private final ResourceToBucketList resource2BucketList; private final ResourceToBucketList resource2BucketList;
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs; private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs;
private final ConcurrentMap<String, Location> containerToLocation; private final ConcurrentMap<String, Location> containerToLocation;
private final ExecutorService service; private final ListeningExecutorService userExecutor;
@Inject @Inject
private StubS3AsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, private StubS3AsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
LocalAsyncBlobStore blobStore, ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs, LocalAsyncBlobStore blobStore, ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
ConcurrentMap<String, Location> containerToLocation, DateService dateService, ConcurrentMap<String, Location> containerToLocation, DateService dateService,
S3Object.Factory objectProvider, Blob.Factory blobProvider, S3Object.Factory objectProvider, Blob.Factory blobProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object, HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
BlobToObjectMetadata blob2ObjectMetadata, BucketToContainerListOptions bucket2ContainerListOptions, BlobToObjectMetadata blob2ObjectMetadata, BucketToContainerListOptions bucket2ContainerListOptions,
ResourceToBucketList resource2BucketList) { ResourceToBucketList resource2BucketList) {
this.service = service; this.userExecutor = userExecutor;
this.containerToBlobs = containerToBlobs; this.containerToBlobs = containerToBlobs;
this.containerToLocation = containerToLocation; this.containerToLocation = containerToLocation;
this.blobStore = blobStore; this.blobStore = blobStore;
@ -146,7 +146,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
public ListenableFuture<ListBucketResponse> listBucket(final String name, ListBucketOptions... optionsList) { public ListenableFuture<ListBucketResponse> listBucket(final String name, ListBucketOptions... optionsList) {
ListContainerOptions options = bucket2ContainerListOptions.apply(optionsList); ListContainerOptions options = bucket2ContainerListOptions.apply(optionsList);
return Futures.compose(blobStore.list(name, options), resource2BucketList, service); return transform(blobStore.list(name, options), resource2BucketList, userExecutor);
} }
public ListenableFuture<ObjectMetadata> copyObject(final String sourceBucket, final String sourceObject, public ListenableFuture<ObjectMetadata> copyObject(final String sourceBucket, final String sourceObject,
@ -274,16 +274,15 @@ public class StubS3AsyncClient implements S3AsyncClient {
public ListenableFuture<S3Object> getObject(final String bucketName, final String key, final GetOptions... options) { public ListenableFuture<S3Object> getObject(final String bucketName, final String key, final GetOptions... options) {
org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options); org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options);
return Futures.compose(blobStore.getBlob(bucketName, key, getOptions), blob2Object, service); return transform(blobStore.getBlob(bucketName, key, getOptions), blob2Object, userExecutor);
} }
public ListenableFuture<ObjectMetadata> headObject(String bucketName, String key) { public ListenableFuture<ObjectMetadata> headObject(String bucketName, String key) {
return Futures.compose(blobStore.blobMetadata(bucketName, key), new Function<BlobMetadata, ObjectMetadata>() { return transform(blobStore.blobMetadata(bucketName, key), new Function<BlobMetadata, ObjectMetadata>() {
@Override
public ObjectMetadata apply(BlobMetadata from) { public ObjectMetadata apply(BlobMetadata from) {
return blob2ObjectMetadata.apply(from); return blob2ObjectMetadata.apply(from);
} }
}, service); }, userExecutor);
} }
public ListenableFuture<? extends Set<BucketMetadata>> listOwnedBuckets() { public ListenableFuture<? extends Set<BucketMetadata>> listOwnedBuckets() {

View File

@ -19,10 +19,10 @@
package org.jclouds.openstack.swift.blobstore; package org.jclouds.openstack.swift.blobstore;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.transform;
import static org.jclouds.blobstore.util.BlobStoreUtils.createParentIfNeededAsync; import static org.jclouds.blobstore.util.BlobStoreUtils.createParentIfNeededAsync;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -44,7 +44,6 @@ import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
@ -65,6 +64,7 @@ import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -86,7 +86,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
@Inject @Inject
protected SwiftAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected SwiftAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync, @Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync,
CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd, CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -94,7 +94,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, userExecutor, defaultLocation, locations);
this.sync = sync; this.sync = sync;
this.async = async; this.async = async;
this.container2ResourceMd = container2ResourceMd; this.container2ResourceMd = container2ResourceMd;
@ -113,13 +113,13 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<PageSet<? extends StorageMetadata>> list() { public ListenableFuture<PageSet<? extends StorageMetadata>> list() {
return Futures.compose(async.listContainers(), return transform(async.listContainers(),
new Function<Set<ContainerMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() { new Function<Set<ContainerMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply( public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(
Set<ContainerMetadata> from) { Set<ContainerMetadata> from) {
return new PageSetImpl<StorageMetadata>(Iterables.transform(from, container2ResourceMd), null); return new PageSetImpl<StorageMetadata>(Iterables.transform(from, container2ResourceMd), null);
} }
}, service); }, userExecutor);
} }
/** /**
@ -152,10 +152,10 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
org.jclouds.openstack.swift.options.ListContainerOptions httpOptions = container2ContainerListOptions org.jclouds.openstack.swift.options.ListContainerOptions httpOptions = container2ContainerListOptions
.apply(options); .apply(options);
ListenableFuture<PageSet<ObjectInfo>> returnVal = async.listObjects(container, httpOptions); ListenableFuture<PageSet<ObjectInfo>> returnVal = async.listObjects(container, httpOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, container2ResourceList, ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, container2ResourceList,
service); userExecutor);
return options.isDetailed() ? Futures.compose(list, fetchBlobMetadataProvider.get().setContainerName(container), return options.isDetailed() ? transform(list, fetchBlobMetadataProvider.get().setContainerName(container),
service) : list; userExecutor) : list;
} }
/** /**
@ -181,7 +181,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return Futures.compose(async.getObjectInfo(container, key), return transform(async.getObjectInfo(container, key),
new Function<MutableObjectInfoWithMetadata, BlobMetadata>() { new Function<MutableObjectInfoWithMetadata, BlobMetadata>() {
@Override @Override
@ -189,7 +189,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
return object2BlobMd.apply(from); return object2BlobMd.apply(from);
} }
}, service); }, userExecutor);
} }
/** /**
@ -204,7 +204,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(options); GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
ListenableFuture<SwiftObject> returnVal = async.getObject(container, key, httpOptions); ListenableFuture<SwiftObject> returnVal = async.getObject(container, key, httpOptions);
return Futures.compose(returnVal, object2Blob, service); return transform(returnVal, object2Blob, userExecutor);
} }
/** /**

View File

@ -1,27 +1,7 @@
package org.jclouds.openstack.swift.blobstore.strategy.internal; package org.jclouds.openstack.swift.blobstore.strategy.internal;
import com.google.common.annotations.VisibleForTesting; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject;
import org.jclouds.Constants;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.internal.BlobRuntimeException;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.io.Payload;
import org.jclouds.io.PayloadSlicer;
import org.jclouds.logging.Logger;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.SwiftApiMetadata;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
import org.jclouds.util.Throwables2;
import javax.annotation.Resource;
import javax.inject.Named;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.SortedMap; import java.util.SortedMap;
@ -33,11 +13,32 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.base.Preconditions.checkNotNull; import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.internal.BlobRuntimeException;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.io.Payload;
import org.jclouds.io.PayloadSlicer;
import org.jclouds.logging.Logger;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.SwiftApiMetadata;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
import org.jclouds.util.Throwables2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject;
public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStrategy { public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStrategy {
@Resource @Resource
@ -74,17 +75,17 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@Named(Constants.PROPERTY_REQUEST_TIMEOUT) @Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime; protected Long maxTime;
private final ExecutorService ioWorkerExecutor; private final ListeningExecutorService ioExecutor;
protected final SwiftAsyncBlobStore ablobstore; protected final SwiftAsyncBlobStore ablobstore;
protected final PayloadSlicer slicer; protected final PayloadSlicer slicer;
@Inject @Inject
public ParallelMultipartUploadStrategy(SwiftAsyncBlobStore ablobstore, PayloadSlicer slicer, public ParallelMultipartUploadStrategy(SwiftAsyncBlobStore ablobstore, PayloadSlicer slicer,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor) { @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor) {
this.ablobstore = checkNotNull(ablobstore, "ablobstore"); this.ablobstore = checkNotNull(ablobstore, "ablobstore");
this.slicer = checkNotNull(slicer, "slicer"); this.slicer = checkNotNull(slicer, "slicer");
this.ioWorkerExecutor = checkNotNull(ioWorkerExecutor, "ioWorkerExecutor"); this.ioExecutor = checkNotNull(ioExecutor, "ioExecutor");
} }
@ -136,14 +137,13 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
latch.countDown(); latch.countDown();
} }
} }
}, ioWorkerExecutor); }, ioExecutor);
futureParts.put(part, futureETag); futureParts.put(part, futureETag);
} }
@Override @Override
public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options, final BlobToObject blob2Object) { public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options, final BlobToObject blob2Object) {
return Futures.makeListenable( return ioExecutor.submit(new Callable<String>() {
ioWorkerExecutor.submit(new Callable<String>() {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
String key = blob.getMetadata().getName(); String key = blob.getMetadata().getName();
@ -235,7 +235,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get(); futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get();
} }
} }
}), ioWorkerExecutor); });
} }
class Part { class Part {

View File

@ -20,13 +20,13 @@ package org.jclouds.openstack.swift.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.Futures.transform;
import java.net.URI; import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,7 +39,6 @@ import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.SwiftAsyncClient; import org.jclouds.openstack.swift.SwiftAsyncClient;
@ -60,6 +59,7 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Implementation of {@link SwiftAsyncClient} which keeps all data in a local Map object. * Implementation of {@link SwiftAsyncClient} which keeps all data in a local Map object.
@ -76,16 +76,16 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
private final ResourceToObjectInfo blob2ObjectInfo; private final ResourceToObjectInfo blob2ObjectInfo;
private final ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions; private final ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions;
private final ResourceToObjectList resource2ObjectList; private final ResourceToObjectList resource2ObjectList;
private final ExecutorService service; private final ListeningExecutorService userExecutor;
@Inject @Inject
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
LocalAsyncBlobStore blobStore, LocalAsyncBlobStore blobStore,
SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter, SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo, ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo,
ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions, ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions,
ResourceToObjectList resource2ContainerList) { ResourceToObjectList resource2ContainerList) {
this.service = service; this.userExecutor = userExecutor;
this.blobStore = blobStore; this.blobStore = blobStore;
this.objectProvider = objectProvider; this.objectProvider = objectProvider;
this.httpGetOptionsConverter = httpGetOptionsConverter; this.httpGetOptionsConverter = httpGetOptionsConverter;
@ -127,11 +127,11 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
public ListenableFuture<SwiftObject> getObject(String container, String key, GetOptions... options) { public ListenableFuture<SwiftObject> getObject(String container, String key, GetOptions... options) {
org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options); org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options);
return Futures.compose(blobStore.getBlob(container, key, getOptions), blob2Object, service); return transform(blobStore.getBlob(container, key, getOptions), blob2Object, userExecutor);
} }
public ListenableFuture<MutableObjectInfoWithMetadata> getObjectInfo(String container, String key) { public ListenableFuture<MutableObjectInfoWithMetadata> getObjectInfo(String container, String key) {
return Futures.compose(blobStore.blobMetadata(container, key), return transform(blobStore.blobMetadata(container, key),
new Function<BlobMetadata, MutableObjectInfoWithMetadata>() { new Function<BlobMetadata, MutableObjectInfoWithMetadata>() {
@Override @Override
@ -140,7 +140,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
return blob2ObjectInfo.apply(from); return blob2ObjectInfo.apply(from);
} }
}, service); }, userExecutor);
} }
public ListenableFuture<? extends Set<ContainerMetadata>> listContainers( public ListenableFuture<? extends Set<ContainerMetadata>> listContainers(
@ -181,7 +181,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
public ListenableFuture<PageSet<ObjectInfo>> listObjects(String container, public ListenableFuture<PageSet<ObjectInfo>> listObjects(String container,
org.jclouds.openstack.swift.options.ListContainerOptions... optionsList) { org.jclouds.openstack.swift.options.ListContainerOptions... optionsList) {
ListContainerOptions options = container2ContainerListOptions.apply(optionsList); ListContainerOptions options = container2ContainerListOptions.apply(optionsList);
return Futures.compose(blobStore.list(container, options), resource2ObjectList, service); return transform(blobStore.list(container, options), resource2ObjectList, userExecutor);
} }
public ListenableFuture<Boolean> copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject) { public ListenableFuture<Boolean> copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject) {

View File

@ -21,9 +21,6 @@ package org.jclouds.vcloud.functions;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,6 +36,8 @@ import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -49,27 +48,25 @@ public class CatalogItemsInCatalog implements Function<Catalog, Iterable<Catalog
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
CatalogItemsInCatalog(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { CatalogItemsInCatalog(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<CatalogItem> apply(Catalog from) { public Iterable<CatalogItem> apply(Catalog from) {
return transformParallel(filter(from.values(), new Predicate<ReferenceType>() { return transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) { public boolean apply(ReferenceType input) {
return input.getType().equals(VCloudMediaType.CATALOGITEM_XML); return input.getType().equals(VCloudMediaType.CATALOGITEM_XML);
} }
}), new Function<ReferenceType, Future<? extends CatalogItem>>() { }), new Function<ReferenceType, ListenableFuture<? extends CatalogItem>>() {
@Override public ListenableFuture<CatalogItem> apply(ReferenceType from) {
public Future<CatalogItem> apply(ReferenceType from) {
return aclient.getCatalogClient().getCatalogItem(from.getHref()); return aclient.getCatalogClient().getCatalogItem(from.getHref());
} }
}, executor, null, logger, "catalogItems in " + from.getHref()); }, userExecutor, null, logger, "catalogItems in " + from.getHref());
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -46,21 +45,20 @@ public class CatalogsInOrg implements Function<Org, Iterable<Catalog>> {
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
CatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { CatalogsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<Catalog> apply(final Org org) { public Iterable<Catalog> apply(final Org org) {
return transformParallel(org.getCatalogs().values(), new Function<ReferenceType, Future<? extends Catalog>>() { return transformParallel(org.getCatalogs().values(), new Function<ReferenceType, ListenableFuture<? extends Catalog>>() {
@Override public ListenableFuture<Catalog> apply(ReferenceType from) {
public Future<Catalog> apply(ReferenceType from) {
return aclient.getCatalogClient().getCatalog(from.getHref()); return aclient.getCatalogClient().getCatalog(from.getHref());
} }
}, executor, null, logger, "catalogs in " + org.getName()); }, userExecutor, null, logger, "catalogs in " + org.getName());
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.domain.network.OrgNetwork;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -46,22 +45,21 @@ public class NetworksInOrg implements Function<Org, Iterable<OrgNetwork>> {
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
NetworksInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { NetworksInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<OrgNetwork> apply(final Org org) { public Iterable<OrgNetwork> apply(final Org org) {
return transformParallel(org.getNetworks().values(), new Function<ReferenceType, Future<? extends OrgNetwork>>() { return transformParallel(org.getNetworks().values(), new Function<ReferenceType, ListenableFuture<? extends OrgNetwork>>() {
@Override public ListenableFuture<? extends OrgNetwork> apply(ReferenceType from) {
public Future<? extends OrgNetwork> apply(ReferenceType from) {
return aclient.getNetworkClient().getNetwork(from.getHref()); return aclient.getNetworkClient().getNetwork(from.getHref());
} }
}, executor, null, logger, "OrgNetworks in org " + org.getName()); }, userExecutor, null, logger, "OrgNetworks in org " + org.getName());
} }
} }

View File

@ -21,8 +21,6 @@ package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -39,6 +37,8 @@ import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -48,12 +48,12 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<O
@Resource @Resource
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
OrgsForLocations(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { OrgsForLocations(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
/** /**
@ -63,22 +63,19 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<O
@Override @Override
public Iterable<Org> apply(Iterable<Location> from) { public Iterable<Org> apply(Iterable<Location> from) {
FluentIterable<URI> uris = FluentIterable.from(from).filter(new Predicate<Location>() { FluentIterable<URI> uris = FluentIterable.from(from).filter(new Predicate<Location>() {
@Override
public boolean apply(Location input) { public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE; return input.getScope() == LocationScope.ZONE;
} }
}).transform(new Function<Location, URI>() { }).transform(new Function<Location, URI>() {
@Override
public URI apply(Location from) { public URI apply(Location from) {
return URI.create(from.getParent().getId()); return URI.create(from.getParent().getId());
} }
}); });
return transformParallel(uris, new Function<URI, Future<? extends Org>>() { return transformParallel(uris, new Function<URI, ListenableFuture<? extends Org>>() {
@Override public ListenableFuture<Org> apply(URI from) {
public Future<Org> apply(URI from) {
return aclient.getOrgClient().getOrg(from); return aclient.getOrgClient().getOrg(from);
} }
}, executor, null, logger, "organizations for uris"); }, userExecutor, null, logger, "organizations for uris");
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -45,24 +44,21 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<Org>> {
@Resource @Resource
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
OrgsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { OrgsForNames(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<Org> apply(Iterable<String> from) { public Iterable<Org> apply(Iterable<String> from) {
return Iterables.filter(transformParallel(from, new Function<String, Future<? extends Org>>() { return Iterables.filter(transformParallel(from, new Function<String, ListenableFuture<? extends Org>>() {
public ListenableFuture<Org> apply(String from) {
@Override
public Future<Org> apply(String from) {
return aclient.getOrgClient().findOrgNamed(from); return aclient.getOrgClient().findOrgNamed(from);
} }
}, userExecutor, null, logger, "organizations for names"), Predicates.notNull());
}, executor, null, logger, "organizations for names"), Predicates.notNull());
} }
} }

View File

@ -22,9 +22,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.Constants.PROPERTY_USER_THREADS; import static org.jclouds.Constants.PROPERTY_USER_THREADS;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -40,6 +37,8 @@ import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -50,32 +49,26 @@ public class VAppTemplatesForCatalogItems implements Function<Iterable<CatalogIt
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, @Named(PROPERTY_USER_THREADS) ExecutorService executor) { VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, @Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<VAppTemplate> apply(Iterable<CatalogItem> from) { public Iterable<VAppTemplate> apply(Iterable<CatalogItem> from) {
return filter(transformParallel(filter(from, new Predicate<CatalogItem>() { return filter(transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override
public boolean apply(CatalogItem input) { public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<CatalogItem, ListenableFuture<? extends VAppTemplate>>() {
}), new Function<CatalogItem, Future<? extends VAppTemplate>>() { public ListenableFuture<VAppTemplate> apply(CatalogItem from) {
@Override
public Future<VAppTemplate> apply(CatalogItem from) {
return aclient.getVAppTemplateClient().getVAppTemplate(from.getEntity().getHref()); return aclient.getVAppTemplateClient().getVAppTemplate(from.getEntity().getHref());
} }
}, userExecutor, null, logger, "vappTemplates in"), Predicates.notNull());
}, executor, null, logger, "vappTemplates in"), Predicates.notNull());
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.vcloud.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -46,23 +45,21 @@ public class VDCsInOrg implements Function<Org, Iterable<VDC>> {
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient; private final VCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { VDCsInOrg(VCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<VDC> apply(final Org org) { public Iterable<VDC> apply(final Org org) {
return transformParallel(org.getVDCs().values(), new Function<ReferenceType, Future<? extends VDC>>() { return transformParallel(org.getVDCs().values(), new Function<ReferenceType, ListenableFuture<? extends VDC>>() {
@Override public ListenableFuture<? extends VDC> apply(ReferenceType from) {
public Future<? extends VDC> apply(ReferenceType from) {
return aclient.getVDCClient().getVDC(from.getHref()); return aclient.getVDCClient().getVDC(from.getHref());
} }
}, userExecutor, null, logger, "vdcs in org " + org.getName());
}, executor, null, logger, "vdcs in org " + org.getName());
} }
} }

View File

@ -26,8 +26,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -42,6 +40,8 @@ import org.jclouds.vcloud.domain.VAppTemplate;
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.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -55,41 +55,34 @@ public class VAppTemplatesSupplier implements Supplier<Set<VAppTemplate>> {
private final Supplier<Map<String, Org>> orgMap; private final Supplier<Map<String, Org>> orgMap;
private final Function<Org, Iterable<VAppTemplate>> imagesInOrg; private final Function<Org, Iterable<VAppTemplate>> imagesInOrg;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VAppTemplatesSupplier(Supplier<Map<String, Org>> orgMap, VAppTemplatesSupplier(Supplier<Map<String, Org>> orgMap,
Function<Org, Iterable<VAppTemplate>> imagesInOrg, Function<Org, Iterable<VAppTemplate>> imagesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.orgMap = checkNotNull(orgMap, "orgMap"); this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg"); this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
public Set<VAppTemplate> get() { public Set<VAppTemplate> get() {
Iterable<Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<? extends Iterable<VAppTemplate>> images = transformParallel(orgs, Iterable<? extends Iterable<VAppTemplate>> images = transformParallel(orgs,
new Function<Org, Future<? extends Iterable<VAppTemplate>>>() { new Function<Org, ListenableFuture<? extends Iterable<VAppTemplate>>>() {
public ListenableFuture<Iterable<VAppTemplate>> apply(final Org from) {
@Override
public Future<Iterable<VAppTemplate>> apply(final Org from) {
checkNotNull(from, "org"); checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<VAppTemplate>>() { return userExecutor.submit(new Callable<Iterable<VAppTemplate>>() {
@Override
public Iterable<VAppTemplate> call() throws Exception { public Iterable<VAppTemplate> call() throws Exception {
return imagesInOrg.apply(from); return imagesInOrg.apply(from);
} }
@Override
public String toString() { public String toString() {
return "imagesInOrg(" + from.getHref() + ")"; return "imagesInOrg(" + from.getHref() + ")";
} }
}); });
} }
}, userExecutor, null, logger, "images in " + orgs);
}, executor, null, logger, "images in " + orgs);
return newLinkedHashSet(concat(images)); return newLinkedHashSet(concat(images));
} }
} }

View File

@ -36,7 +36,6 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.ExecutorService;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -80,6 +79,7 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
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;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Implementation of {@link BaseAsyncBlobStore} which uses a pluggable * Implementation of {@link BaseAsyncBlobStore} which uses a pluggable
@ -103,13 +103,13 @@ public class LocalAsyncBlobStore extends BaseAsyncBlobStore {
@Inject @Inject
protected LocalAsyncBlobStore(BlobStoreContext context, protected LocalAsyncBlobStore(BlobStoreContext context,
BlobUtils blobUtils, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
Supplier<Location> defaultLocation, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Location>> locations,
ContentMetadataCodec contentMetadataCodec, ContentMetadataCodec contentMetadataCodec,
IfDirectoryReturnNameStrategy ifDirectoryReturnName, IfDirectoryReturnNameStrategy ifDirectoryReturnName,
Factory blobFactory, LocalStorageStrategy storageStrategy) { Factory blobFactory, LocalStorageStrategy storageStrategy) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blobFactory = blobFactory; this.blobFactory = blobFactory;
this.contentMetadataCodec = contentMetadataCodec; this.contentMetadataCodec = contentMetadataCodec;
this.ifDirectoryReturnName = ifDirectoryReturnName; this.ifDirectoryReturnName = ifDirectoryReturnName;

View File

@ -24,7 +24,6 @@ import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursi
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -48,6 +47,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
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;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -57,17 +57,17 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
protected final BlobStoreContext context; protected final BlobStoreContext context;
protected final BlobUtils blobUtils; protected final BlobUtils blobUtils;
protected final ExecutorService service; protected final ListeningExecutorService userExecutor;
protected final Supplier<Location> defaultLocation; protected final Supplier<Location> defaultLocation;
protected final Supplier<Set<? extends Location>> locations; protected final Supplier<Set<? extends Location>> locations;
@Inject @Inject
protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations) { @Memoized Supplier<Set<? extends Location>> locations) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.blobUtils = checkNotNull(blobUtils, "blobUtils"); this.blobUtils = checkNotNull(blobUtils, "blobUtils");
this.service = checkNotNull(service, "service"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
} }
@ -117,7 +117,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Long> countBlobs(final String containerName, final ListContainerOptions options) { public ListenableFuture<Long> countBlobs(final String containerName, final ListContainerOptions options) {
return org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Long>() { return userExecutor.submit(new Callable<Long>() {
public Long call() throws Exception { public Long call() throws Exception {
return blobUtils.countBlobs(containerName, options); return blobUtils.countBlobs(containerName, options);
} }
@ -126,7 +126,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "countBlobs(" + containerName + ")"; return "countBlobs(" + containerName + ")";
} }
}), service); });
} }
/** /**
@ -149,7 +149,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Void> clearContainer(final String containerName, final ListContainerOptions options) { public ListenableFuture<Void> clearContainer(final String containerName, final ListContainerOptions options) {
return org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Void>() { return userExecutor.submit(new Callable<Void>() {
public Void call() throws Exception { public Void call() throws Exception {
blobUtils.clearContainer(containerName, options); blobUtils.clearContainer(containerName, options);
@ -160,7 +160,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "clearContainer(" + containerName + ")"; return "clearContainer(" + containerName + ")";
} }
}), service); });
} }
/** /**
@ -171,7 +171,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Void> deleteDirectory(final String containerName, final String directory) { public ListenableFuture<Void> deleteDirectory(final String containerName, final String directory) {
return org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Void>() { return userExecutor.submit(new Callable<Void>() {
public Void call() throws Exception { public Void call() throws Exception {
blobUtils.deleteDirectory(containerName, directory); blobUtils.deleteDirectory(containerName, directory);
@ -182,7 +182,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "deleteDirectory(" + containerName + "," + directory + ")"; return "deleteDirectory(" + containerName + "," + directory + ")";
} }
}), service); });
} }
/** /**
@ -194,7 +194,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
* virtual path * virtual path
*/ */
public ListenableFuture<Boolean> directoryExists(final String containerName, final String directory) { public ListenableFuture<Boolean> directoryExists(final String containerName, final String directory) {
return org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Boolean>() { return userExecutor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return blobUtils.directoryExists(containerName, directory); return blobUtils.directoryExists(containerName, directory);
@ -204,7 +204,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "directoryExists(" + containerName + "," + directory + ")"; return "directoryExists(" + containerName + "," + directory + ")";
} }
}), service); });
} }
/** /**
@ -217,9 +217,8 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/ */
public ListenableFuture<Void> createDirectory(final String containerName, final String directory) { public ListenableFuture<Void> createDirectory(final String containerName, final String directory) {
return blobUtils.directoryExists(containerName, directory) ? Futures.immediateFuture((Void) null) return blobUtils.directoryExists(containerName, directory) ? Futures.immediateFuture((Void) null)
: org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Void>() { : userExecutor.submit(new Callable<Void>() {
public Void call() throws Exception { public Void call() throws Exception {
blobUtils.createDirectory(containerName, directory); blobUtils.createDirectory(containerName, directory);
return null; return null;
@ -229,7 +228,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "createDirectory(" + containerName + "," + directory + ")"; return "createDirectory(" + containerName + "," + directory + ")";
} }
}), service); });
} }
/** /**
@ -254,7 +253,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<Void> deleteContainer(final String container) { public ListenableFuture<Void> deleteContainer(final String container) {
return org.jclouds.concurrent.Futures.makeListenable(service.submit(new Callable<Void>() { return userExecutor.submit(new Callable<Void>() {
public Void call() throws Exception { public Void call() throws Exception {
deletePathAndEnsureGone(container); deletePathAndEnsureGone(container);
@ -265,7 +264,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() { public String toString() {
return "deleteContainer(" + container + ")"; return "deleteContainer(" + container + ")";
} }
}), service); });
} }
protected void deletePathAndEnsureGone(String path) { protected void deletePathAndEnsureGone(String path) {

View File

@ -24,10 +24,8 @@ import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -46,6 +44,8 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -60,7 +60,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final BackoffLimitedRetryHandler retryHandler; protected final BackoffLimitedRetryHandler retryHandler;
private final ExecutorService userExecutor; private final ListeningExecutorService userExecutor;
protected final AsyncBlobStore connection; protected final AsyncBlobStore connection;
/** Maximum duration in milliseconds of a request. */ /** Maximum duration in milliseconds of a request. */
@ -69,10 +69,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected Long maxTime = Long.MAX_VALUE; protected Long maxTime = Long.MAX_VALUE;
@Inject @Inject
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore connection, AsyncBlobStore connection, BackoffLimitedRetryHandler retryHandler) {
BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.connection = connection; this.connection = connection;
this.retryHandler = retryHandler; this.retryHandler = retryHandler;
@ -95,7 +93,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
for (int numErrors = 0; numErrors < maxErrors; ) { for (int numErrors = 0; numErrors < maxErrors; ) {
// fetch partial directory listing // fetch partial directory listing
PageSet<? extends StorageMetadata> listing; PageSet<? extends StorageMetadata> listing;
Future<PageSet<? extends StorageMetadata>> listFuture = ListenableFuture<PageSet<? extends StorageMetadata>> listFuture =
connection.list(containerName, options); connection.list(containerName, options);
try { try {
listing = listFuture.get(maxTime, TimeUnit.MILLISECONDS); listing = listFuture.get(maxTime, TimeUnit.MILLISECONDS);
@ -141,7 +139,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
} }
// remove blobs and now-empty subdirectories // remove blobs and now-empty subdirectories
Map<StorageMetadata, Future<?>> responses = Maps.newHashMap(); Map<StorageMetadata, ListenableFuture<?>> responses = Maps.newHashMap();
for (StorageMetadata md : listing) { for (StorageMetadata md : listing) {
String fullPath = parentIsFolder(options, md) ? options.getDir() + "/" String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
+ md.getName() : md.getName(); + md.getName() : md.getName();
@ -174,7 +172,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
retryHandler.imposeBackoffExponentialDelay(numErrors, message); retryHandler.imposeBackoffExponentialDelay(numErrors, message);
continue; continue;
} finally { } finally {
for (Future<?> future : responses.values()) { for (ListenableFuture<?> future : responses.values()) {
future.cancel(true); future.cancel(true);
} }
} }

View File

@ -21,9 +21,6 @@ package org.jclouds.blobstore.strategy.internal;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -43,6 +40,8 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -55,7 +54,7 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
protected final BackoffLimitedRetryHandler retryHandler; protected final BackoffLimitedRetryHandler retryHandler;
protected final AsyncBlobStore ablobstore; protected final AsyncBlobStore ablobstore;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER) @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -69,7 +68,7 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
protected Long maxTime; protected Long maxTime;
@Inject @Inject
FetchBlobMetadata(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, AsyncBlobStore ablobstore, FetchBlobMetadata(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, AsyncBlobStore ablobstore,
BackoffLimitedRetryHandler retryHandler) { BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.ablobstore = ablobstore; this.ablobstore = ablobstore;
@ -91,10 +90,10 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
return input.getType() == StorageType.BLOB; return input.getType() == StorageType.BLOB;
} }
}), new Function<StorageMetadata, Future<? extends BlobMetadata>>() { }), new Function<StorageMetadata, ListenableFuture<? extends BlobMetadata>>() {
@Override @Override
public Future<BlobMetadata> apply(StorageMetadata from) { public ListenableFuture<BlobMetadata> apply(StorageMetadata from) {
return ablobstore.blobMetadata(container, from.getName()); return ablobstore.blobMetadata(container, from.getName());
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.blobstore.strategy.internal;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -39,6 +36,8 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -53,7 +52,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
protected final ListBlobsInContainer getAllBlobMetadata; protected final ListBlobsInContainer getAllBlobMetadata;
protected final BackoffLimitedRetryHandler retryHandler; protected final BackoffLimitedRetryHandler retryHandler;
protected final AsyncBlobStore ablobstore; protected final AsyncBlobStore ablobstore;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER) @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -65,7 +64,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
protected Long maxTime; protected Long maxTime;
@Inject @Inject
GetAllBlobsInListAndRetryOnFailure(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, GetAllBlobsInListAndRetryOnFailure(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
ListBlobsInContainer getAllBlobMetadata, AsyncBlobStore ablobstore, BackoffLimitedRetryHandler retryHandler) { ListBlobsInContainer getAllBlobMetadata, AsyncBlobStore ablobstore, BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.ablobstore = ablobstore; this.ablobstore = ablobstore;
@ -75,10 +74,10 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
public Iterable<Blob> execute(final String container, ListContainerOptions options) { public Iterable<Blob> execute(final String container, ListContainerOptions options) {
Iterable<? extends BlobMetadata> list = getAllBlobMetadata.execute(container, options); Iterable<? extends BlobMetadata> list = getAllBlobMetadata.execute(container, options);
return transformParallel(list, new Function<BlobMetadata, Future<? extends Blob>>() { return transformParallel(list, new Function<BlobMetadata, ListenableFuture<? extends Blob>>() {
@Override @Override
public Future<Blob> apply(BlobMetadata from) { public ListenableFuture<Blob> apply(BlobMetadata from) {
return ablobstore.getBlob(container, from.getName()); return ablobstore.getBlob(container, from.getName());
} }

View File

@ -23,8 +23,6 @@ import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -41,6 +39,8 @@ import org.jclouds.logging.Logger;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -68,7 +68,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
private final AsyncBlobStore ablobstore; private final AsyncBlobStore ablobstore;
private final BlobStore blobstore; private final BlobStore blobstore;
private final ExecutorService userExecutor; private final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER) @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -81,7 +81,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
@Inject @Inject
MarkersDeleteDirectoryStrategy( MarkersDeleteDirectoryStrategy(
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore ablobstore, BlobStore blobstore) { AsyncBlobStore ablobstore, BlobStore blobstore) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.ablobstore = ablobstore; this.ablobstore = ablobstore;
@ -94,7 +94,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) { for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) {
names.add(directory + suffix); names.add(directory + suffix);
} }
Map<String, Future<?>> responses = Maps.newHashMap(); Map<String, ListenableFuture<?>> responses = Maps.newHashMap();
for (String name : names) { for (String name : names) {
responses.put(name, ablobstore.removeBlob(containerName, name)); responses.put(name, ablobstore.removeBlob(containerName, name));
} }

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Throwables.propagate;
import static org.jclouds.concurrent.FutureIterables.awaitCompletion; import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -39,6 +37,8 @@ import org.jclouds.blobstore.strategy.PutBlobsStrategy;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -49,7 +49,7 @@ import com.google.inject.Inject;
public class PutBlobsStrategyImpl implements PutBlobsStrategy { public class PutBlobsStrategyImpl implements PutBlobsStrategy {
private final AsyncBlobStore ablobstore; private final AsyncBlobStore ablobstore;
private final ExecutorService userExecutor; private final ListeningExecutorService userExecutor;
@Resource @Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER) @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -61,7 +61,7 @@ public class PutBlobsStrategyImpl implements PutBlobsStrategy {
protected Long maxTime; protected Long maxTime;
@Inject @Inject
PutBlobsStrategyImpl(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, PutBlobsStrategyImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore ablobstore) { AsyncBlobStore ablobstore) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.ablobstore = ablobstore; this.ablobstore = ablobstore;
@ -69,7 +69,7 @@ public class PutBlobsStrategyImpl implements PutBlobsStrategy {
@Override @Override
public void execute(String containerName, Iterable<? extends Blob> blobs) { public void execute(String containerName, Iterable<? extends Blob> blobs) {
Map<Blob, Future<?>> responses = Maps.newLinkedHashMap(); Map<Blob, ListenableFuture<?>> responses = Maps.newLinkedHashMap();
for (Blob blob : blobs) { for (Blob blob : blobs) {
responses.put(blob, ablobstore.putBlob(containerName, blob)); responses.put(blob, ablobstore.putBlob(containerName, blob));
} }

View File

@ -43,7 +43,6 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@ -58,7 +57,6 @@ import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.concurrent.Futures;
import org.jclouds.crypto.Crypto; import org.jclouds.crypto.Crypto;
import org.jclouds.encryption.internal.JCECrypto; import org.jclouds.encryption.internal.JCECrypto;
import org.jclouds.http.BaseJettyTest; import org.jclouds.http.BaseJettyTest;
@ -84,6 +82,8 @@ import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.io.InputSupplier; import com.google.common.io.InputSupplier;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -139,7 +139,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
final AtomicInteger blobCount = new AtomicInteger(); final AtomicInteger blobCount = new AtomicInteger();
final String container = getContainerName(); final String container = getContainerName();
try { try {
Map<Integer, Future<?>> responses = Maps.newHashMap(); Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
responses.put(i, this.exec.submit(new Callable<Void>() { responses.put(i, this.exec.submit(new Callable<Void>() {
@ -179,10 +179,10 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
final String name = "constitution.txt"; final String name = "constitution.txt";
uploadConstitution(container, name, expectedContentDisposition); uploadConstitution(container, name, expectedContentDisposition);
Map<Integer, Future<?>> responses = Maps.newHashMap(); Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
responses.put(i, Futures.compose(view.getAsyncBlobStore().getBlob(container, name), responses.put(i, Futures.transform(view.getAsyncBlobStore().getBlob(container, name),
new Function<Blob, Void>() { new Function<Blob, Void>() {
@Override @Override

View File

@ -32,7 +32,6 @@ import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -63,6 +62,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.inject.Module; import com.google.inject.Module;
public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreContext> { public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreContext> {
@ -106,7 +107,7 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
return ImmutableSet.<Module> of(getLoggingModule(), createHttpModule()); return ImmutableSet.<Module> of(getLoggingModule(), createHttpModule());
} }
protected ExecutorService exec; protected ListeningExecutorService exec;
/** /**
* we are doing this at a class level, as the context.getBlobStore() object is going to be shared * we are doing this at a class level, as the context.getBlobStore() object is going to be shared
@ -116,7 +117,7 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
*/ */
@BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext") @BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext")
public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception { public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception {
exec = Executors.newCachedThreadPool(); exec = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
} }

View File

@ -23,7 +23,6 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_T
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -62,6 +61,7 @@ import org.jclouds.trmk.vcloud_0_8.compute.strategy.CleanupOrphanKeys;
import com.google.common.base.Optional; import com.google.common.base.Optional;
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.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -85,13 +85,13 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, CleanupOrphanKeys cleanupOrphanKeys,
Optional<ImageExtension> imageExtension) { Optional<ImageExtension> imageExtension) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy, super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension); persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.cleanupOrphanKeys = cleanupOrphanKeys; this.cleanupOrphanKeys = cleanupOrphanKeys;
} }

View File

@ -21,8 +21,6 @@ package org.jclouds.trmk.vcloud_0_8.compute.strategy;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -41,6 +39,8 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions; import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* creates futures that correlate to * creates futures that correlate to
@ -58,15 +58,15 @@ public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends Creat
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention, GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise; this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise;
} }
@Override @Override
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: "
+ template.getLocation(); + template.getLocation();

View File

@ -26,8 +26,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -42,6 +40,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.Org;
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.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -55,27 +55,27 @@ public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>>
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final Function<Org, Iterable<? extends Hardware>> sizesInOrg; private final Function<Org, Iterable<? extends Hardware>> sizesInOrg;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VCloudHardwareSupplier(Supplier<Map<String, ? extends Org>> orgMap, VCloudHardwareSupplier(Supplier<Map<String, ? extends Org>> orgMap,
Function<Org, Iterable<? extends Hardware>> sizesInOrg, Function<Org, Iterable<? extends Hardware>> sizesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.orgMap = checkNotNull(orgMap, "orgMap"); this.orgMap = checkNotNull(orgMap, "orgMap");
this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg"); this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
public Set<? extends Hardware> get() { public Set<? extends Hardware> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<? extends Iterable<? extends Hardware>> sizes = transformParallel(orgs, Iterable<? extends Iterable<? extends Hardware>> sizes = transformParallel(orgs,
new Function<Org, Future<? extends Iterable<? extends Hardware>>>() { new Function<Org, ListenableFuture<? extends Iterable<? extends Hardware>>>() {
@Override @Override
public Future<Iterable<? extends Hardware>> apply(final Org from) { public ListenableFuture<Iterable<? extends Hardware>> apply(final Org from) {
checkNotNull(from, "org"); checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Hardware>>() { return userExecutor.submit(new Callable<Iterable<? extends Hardware>>() {
@Override @Override
public Iterable<? extends Hardware> call() throws Exception { public Iterable<? extends Hardware> call() throws Exception {
@ -89,7 +89,7 @@ public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>>
}); });
} }
}, executor, null, logger, "sizes in " + orgs); }, userExecutor, null, logger, "sizes in " + orgs);
return newLinkedHashSet(concat(sizes)); return newLinkedHashSet(concat(sizes));
} }
} }

View File

@ -26,8 +26,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -42,6 +40,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.Org;
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.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -55,27 +55,27 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final Function<Org, Iterable<? extends Image>> imagesInOrg; private final Function<Org, Iterable<? extends Image>> imagesInOrg;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap, VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap,
Function<Org, Iterable<? extends Image>> imagesInOrg, Function<Org, Iterable<? extends Image>> imagesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.orgMap = checkNotNull(orgMap, "orgMap"); this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg"); this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
public Set<? extends Image> get() { public Set<? extends Image> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<? extends Iterable<? extends Image>> images = transformParallel(orgs, Iterable<? extends Iterable<? extends Image>> images = transformParallel(orgs,
new Function<Org, Future<? extends Iterable<? extends Image>>>() { new Function<Org, ListenableFuture<? extends Iterable<? extends Image>>>() {
@Override @Override
public Future<Iterable<? extends Image>> apply(final Org from) { public ListenableFuture<Iterable<? extends Image>> apply(final Org from) {
checkNotNull(from, "org"); checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Image>>() { return userExecutor.submit(new Callable<Iterable<? extends Image>>() {
@Override @Override
public Iterable<? extends Image> call() throws Exception { public Iterable<? extends Image> call() throws Exception {
@ -89,7 +89,7 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
}); });
} }
}, executor, null, logger, "images in " + orgs); }, userExecutor, null, logger, "images in " + orgs);
return newLinkedHashSet(concat(images)); return newLinkedHashSet(concat(images));
} }
} }

View File

@ -21,9 +21,6 @@ package org.jclouds.trmk.vcloud_0_8.functions;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,6 +36,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -49,35 +48,26 @@ public class AllCatalogItemsInCatalog implements Function<Catalog, Iterable<? ex
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
AllCatalogItemsInCatalog(TerremarkVCloudAsyncClient aclient, AllCatalogItemsInCatalog(TerremarkVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends CatalogItem> apply(Catalog from) { public Iterable<? extends CatalogItem> apply(Catalog from) {
return transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
Iterable<? extends CatalogItem> catalogItems = transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) { public boolean apply(ReferenceType input) {
return input.getType().equals(TerremarkVCloudMediaType.CATALOGITEM_XML); return input.getType().equals(TerremarkVCloudMediaType.CATALOGITEM_XML);
} }
}), new Function<ReferenceType, ListenableFuture<? extends CatalogItem>>() {
}), new Function<ReferenceType, Future<? extends CatalogItem>>() { public ListenableFuture<? extends CatalogItem> apply(ReferenceType from) {
return aclient.getCatalogItem(from.getHref());
@SuppressWarnings("unchecked")
@Override
public Future<CatalogItem> apply(ReferenceType from) {
return (Future<CatalogItem>) aclient.getCatalogItem(from.getHref());
} }
}, userExecutor, null, logger, "catalogItems in " + from.getHref());
}, executor, null, logger, "catalogItems in " + from.getHref());
return catalogItems;
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -46,25 +45,21 @@ public class AllCatalogsInOrg implements Function<Org, Iterable<? extends Catalo
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
AllCatalogsInOrg(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { AllCatalogsInOrg(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends Catalog> apply(final Org org) { public Iterable<? extends Catalog> apply(final Org org) {
Iterable<? extends Catalog> catalogs = transformParallel(org.getCatalogs().values(), return transformParallel(org.getCatalogs().values(),
new Function<ReferenceType, Future<? extends Catalog>>() { new Function<ReferenceType, ListenableFuture<? extends Catalog>>() {
@SuppressWarnings("unchecked") public ListenableFuture<? extends Catalog> apply(ReferenceType from) {
@Override return aclient.getCatalog(from.getHref());
public Future<Catalog> apply(ReferenceType from) {
return (Future<Catalog>) aclient.getCatalog(from.getHref());
} }
}, userExecutor, null, logger, "catalogs in " + org.getName());
}, executor, null, logger, "catalogs in " + org.getName());
return catalogs;
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -35,6 +32,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -45,26 +44,22 @@ public class AllVDCsInOrg implements Function<Org, Iterable<? extends org.jcloud
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
AllVDCsInOrg(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { AllVDCsInOrg(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(final Org org) { public Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(final Org org) {
return transformParallel(org.getVDCs().values(),
Iterable<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> catalogItems = transformParallel(org.getVDCs().values(), new Function<ReferenceType, ListenableFuture<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>() {
new Function<ReferenceType, Future<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>() { public ListenableFuture<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(ReferenceType from) {
@Override
public Future<? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> apply(ReferenceType from) {
return aclient.getVDC(from.getHref()); return aclient.getVDC(from.getHref());
} }
}, userExecutor, null, logger, "vdcs in org " + org.getName());
}, executor, null, logger, "vdcs in org " + org.getName());
return catalogItems;
} }
} }

View File

@ -23,8 +23,6 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -41,6 +39,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -50,12 +50,12 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
@Resource @Resource
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
OrgsForLocations(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { OrgsForLocations(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
/** /**
@ -64,28 +64,18 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
*/ */
@Override @Override
public Iterable<? extends Org> apply(Iterable<? extends Location> from) { public Iterable<? extends Org> apply(Iterable<? extends Location> from) {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() { return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
@Override
public boolean apply(Location input) { public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE; return input.getScope() == LocationScope.ZONE;
} }
}), new Function<Location, URI>() { }), new Function<Location, URI>() {
@Override
public URI apply(Location from) { public URI apply(Location from) {
return URI.create(from.getParent().getId()); return URI.create(from.getParent().getId());
} }
})), new Function<URI, ListenableFuture<? extends Org>>() {
})), new Function<URI, Future<? extends Org>>() { public ListenableFuture<? extends Org> apply(URI from) {
@Override
public Future<? extends Org> apply(URI from) {
return aclient.getOrg(from); return aclient.getOrg(from);
} }
}, userExecutor, null, logger, "organizations for uris");
}, executor, null, logger, "organizations for uris");
} }
} }

View File

@ -20,9 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.functions;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -34,6 +31,8 @@ import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudAsyncClient;
import org.jclouds.trmk.vcloud_0_8.domain.Org; import org.jclouds.trmk.vcloud_0_8.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -43,23 +42,21 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<? exten
@Resource @Resource
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
OrgsForNames(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { OrgsForNames(TerremarkVCloudAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends Org> apply(Iterable<String> from) { public Iterable<? extends Org> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<? extends Org>>() { return transformParallel(from, new Function<String, ListenableFuture<? extends Org>>() {
@Override public ListenableFuture<? extends Org> apply(String from) {
public Future<? extends Org> apply(String from) {
return aclient.findOrgNamed(from); return aclient.findOrgNamed(from);
} }
}, userExecutor, null, logger, "organizations for names");
}, executor, null, logger, "organizations for names");
} }
} }

View File

@ -21,9 +21,6 @@ package org.jclouds.trmk.vcloud_0_8.functions;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,6 +36,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -50,31 +49,26 @@ public class VAppTemplatesForCatalogItems implements
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VAppTemplatesForCatalogItems(TerremarkVCloudAsyncClient aclient, VAppTemplatesForCatalogItems(TerremarkVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends VAppTemplate> apply(Iterable<? extends CatalogItem> from) { public Iterable<? extends VAppTemplate> apply(Iterable<? extends CatalogItem> from) {
return transformParallel(filter(from, new Predicate<CatalogItem>() { return transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override
public boolean apply(CatalogItem input) { public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML); return input.getEntity().getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<CatalogItem, ListenableFuture<? extends VAppTemplate>>() {
}), new Function<CatalogItem, Future<? extends VAppTemplate>>() { public ListenableFuture<? extends VAppTemplate> apply(CatalogItem from) {
@Override
public Future<? extends VAppTemplate> apply(CatalogItem from) {
return aclient.getVAppTemplate(from.getEntity().getHref()); return aclient.getVAppTemplate(from.getEntity().getHref());
} }
}, userExecutor, null, logger, "vappTemplates in");
}, executor, null, logger, "vappTemplates in");
} }
} }

View File

@ -22,9 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -40,6 +37,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -51,31 +50,26 @@ public class VAppTemplatesForResourceEntities implements
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient; private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
VAppTemplatesForResourceEntities(TerremarkVCloudAsyncClient aclient, VAppTemplatesForResourceEntities(TerremarkVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient; this.aclient = aclient;
this.executor = executor; this.userExecutor = userExecutor;
} }
@Override @Override
public Iterable<? extends VAppTemplate> apply(Iterable<? extends ReferenceType> from) { public Iterable<? extends VAppTemplate> apply(Iterable<? extends ReferenceType> from) {
return transformParallel(filter(checkNotNull(from, "named resources"), new Predicate<ReferenceType>() { return transformParallel(filter(checkNotNull(from, "named resources"), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) { public boolean apply(ReferenceType input) {
return input.getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML); return input.getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
} }
}), new Function<ReferenceType, ListenableFuture<? extends VAppTemplate>>() {
}), new Function<ReferenceType, Future<? extends VAppTemplate>>() { public ListenableFuture<? extends VAppTemplate> apply(ReferenceType from) {
@Override
public Future<? extends VAppTemplate> apply(ReferenceType from) {
return aclient.getVAppTemplate(from.getHref()); return aclient.getVAppTemplate(from.getHref());
} }
}, userExecutor, null, logger, "vappTemplates in");
}, executor, null, logger, "vappTemplates in");
} }
} }

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -36,6 +35,7 @@ import org.jclouds.compute.events.StatementOnNodeFailure;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.scriptbuilder.InitScript;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -44,6 +44,7 @@ import com.google.common.base.Predicates;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named; import com.google.inject.name.Named;
@ -63,7 +64,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final ExecutorService userThreads; private final ListeningExecutorService userExecutor;
private final EventBus eventBus; private final EventBus eventBus;
private final SudoAwareInitManager commandRunner; private final SudoAwareInitManager commandRunner;
@ -75,19 +76,19 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
@Inject @Inject
public BlockUntilInitScriptStatusIsZeroThenReturnOutput( public BlockUntilInitScriptStatusIsZeroThenReturnOutput(
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, EventBus eventBus, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, EventBus eventBus,
ComputeServiceConstants.InitStatusProperties properties, @Assisted SudoAwareInitManager commandRunner) { ComputeServiceConstants.InitStatusProperties properties, @Assisted SudoAwareInitManager commandRunner) {
this(userThreads, eventBus, Predicates.<String> alwaysTrue(), commandRunner); this(userExecutor, eventBus, Predicates.<String> alwaysTrue(), commandRunner);
// this is mutable only until we can determine how to decouple "this" from here // this is mutable only until we can determine how to decouple "this" from here
notRunningAnymore = new LoopUntilTrueOrThrowCancellationException(new ExitStatusOfCommandGreaterThanZero( notRunningAnymore = new LoopUntilTrueOrThrowCancellationException(new ExitStatusOfCommandGreaterThanZero(
commandRunner), properties.initStatusMaxPeriod, properties.initStatusInitialPeriod, this); commandRunner), properties.initStatusMaxPeriod, properties.initStatusInitialPeriod, this);
} }
@VisibleForTesting @VisibleForTesting
public BlockUntilInitScriptStatusIsZeroThenReturnOutput(ExecutorService userThreads, EventBus eventBus, public BlockUntilInitScriptStatusIsZeroThenReturnOutput(ListeningExecutorService userExecutor, EventBus eventBus,
Predicate<String> notRunningAnymore, SudoAwareInitManager commandRunner) { Predicate<String> notRunningAnymore, SudoAwareInitManager commandRunner) {
this.commandRunner = checkNotNull(commandRunner, "commandRunner"); this.commandRunner = checkNotNull(commandRunner, "commandRunner");
this.userThreads = checkNotNull(userThreads, "userThreads"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.eventBus = checkNotNull(eventBus, "eventBus"); this.eventBus = checkNotNull(eventBus, "eventBus");
this.notRunningAnymore = checkNotNull(notRunningAnymore, "notRunningAnymore"); this.notRunningAnymore = checkNotNull(notRunningAnymore, "notRunningAnymore");
} }
@ -136,7 +137,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
* place * place
*/ */
public BlockUntilInitScriptStatusIsZeroThenReturnOutput init() { public BlockUntilInitScriptStatusIsZeroThenReturnOutput init() {
userThreads.submit(this); userExecutor.submit(this);
return this; return this;
} }

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Throwables.propagate; import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Maps.newLinkedHashMap; import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.filter;
import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.Sets.newLinkedHashSet;
import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.Futures.immediateFuture;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
@ -40,10 +39,8 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -65,10 +62,10 @@ import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.extensions.ImageExtension; import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -107,6 +104,7 @@ import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -143,7 +141,7 @@ public class BaseComputeService implements ComputeService {
private final InitAdminAccess initAdminAccess; private final InitAdminAccess initAdminAccess;
private final PersistNodeCredentials persistNodeCredentials; private final PersistNodeCredentials persistNodeCredentials;
private final RunScriptOnNode.Factory runScriptOnNodeFactory; private final RunScriptOnNode.Factory runScriptOnNodeFactory;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
private final Optional<ImageExtension> imageExtension; private final Optional<ImageExtension> imageExtension;
@Inject @Inject
@ -161,7 +159,7 @@ public class BaseComputeService implements ComputeService {
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended, @Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials, RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
Optional<ImageExtension> imageExtension) { Optional<ImageExtension> imageExtension) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.credentialStore = checkNotNull(credentialStore, "credentialStore");
@ -186,8 +184,8 @@ public class BaseComputeService implements ComputeService {
this.initAdminAccess = checkNotNull(initAdminAccess, "initAdminAccess"); this.initAdminAccess = checkNotNull(initAdminAccess, "initAdminAccess");
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
this.persistNodeCredentials = checkNotNull(persistNodeCredentials, "persistNodeCredentials"); this.persistNodeCredentials = checkNotNull(persistNodeCredentials, "persistNodeCredentials");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.imageExtension = imageExtension; this.imageExtension = checkNotNull(imageExtension, "imageExtension");
} }
/** /**
@ -213,11 +211,11 @@ public class BaseComputeService implements ComputeService {
if (template.getOptions().getRunScript() != null) if (template.getOptions().getRunScript() != null)
initAdminAccess.visit(template.getOptions().getRunScript()); initAdminAccess.visit(template.getOptions().getRunScript());
Map<?, Future<Void>> responses = runNodesAndAddToSetStrategy.execute(group, count, template, goodNodes, badNodes, Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(group, count, template, goodNodes, badNodes,
customizationResponses); customizationResponses);
Map<?, Exception> executionExceptions; Map<?, Exception> executionExceptions;
try { try {
executionExceptions = awaitCompletion(responses, executor, null, logger, "createNodesInGroup(" + group + ")"); executionExceptions = awaitCompletion(responses, userExecutor, null, logger, "createNodesInGroup(" + group + ")");
} catch (TimeoutException te) { } catch (TimeoutException te) {
throw propagate(te); throw propagate(te);
} }
@ -257,29 +255,24 @@ public class BaseComputeService implements ComputeService {
@Override @Override
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) { public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter); logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(filter(transformParallel(nodesMatchingFilterAndNotTerminated(filter), Set<NodeMetadata> set = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, Future<? extends NodeMetadata>>() { new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping // TODO make an async interface instead of re-wrapping
@Override @Override
public Future<NodeMetadata> apply(final NodeMetadata from) { public ListenableFuture<NodeMetadata> apply(final NodeMetadata from) {
return executor.submit(new Callable<NodeMetadata>() { return userExecutor.submit(new Callable<NodeMetadata>() {
@Nullable
@Override
public NodeMetadata call() throws Exception { public NodeMetadata call() throws Exception {
doDestroyNode(from.getId()); doDestroyNode(from.getId());
return from; return from;
} }
@Override
public String toString() { public String toString() {
return "destroyNode(" + from.getId() + ")"; return "destroyNode(" + from.getId() + ")";
} }
}); });
} }
}, executor, null, logger, "destroyNodesMatching(" + filter + ")"), notNull())); }, userExecutor, null, logger, "destroyNodesMatching(" + filter + ")"));
logger.debug("<< destroyed(%d)", set.size()); logger.debug("<< destroyed(%d)", set.size());
cleanUpIncidentalResourcesOfDeadNodes(set); cleanUpIncidentalResourcesOfDeadNodes(set);
@ -432,15 +425,15 @@ public class BaseComputeService implements ComputeService {
public void rebootNodesMatching(Predicate<NodeMetadata> filter) { public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> rebooting nodes matching(%s)", filter); logger.debug(">> rebooting nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() { new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public ListenableFuture<Void> apply(NodeMetadata from) {
rebootNode(from.getId()); rebootNode(from.getId());
return immediateFuture(null); return immediateFuture(null);
} }
}, executor, null, logger, "rebootNodesMatching(" + filter + ")"); }, userExecutor, null, logger, "rebootNodesMatching(" + filter + ")");
logger.debug("<< rebooted"); logger.debug("<< rebooted");
} }
@ -463,15 +456,15 @@ public class BaseComputeService implements ComputeService {
public void resumeNodesMatching(Predicate<NodeMetadata> filter) { public void resumeNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> resuming nodes matching(%s)", filter); logger.debug(">> resuming nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() { new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public ListenableFuture<Void> apply(NodeMetadata from) {
resumeNode(from.getId()); resumeNode(from.getId());
return immediateFuture(null); return immediateFuture(null);
} }
}, executor, null, logger, "resumeNodesMatching(" + filter + ")"); }, userExecutor, null, logger, "resumeNodesMatching(" + filter + ")");
logger.debug("<< resumed"); logger.debug("<< resumed");
} }
@ -494,15 +487,15 @@ public class BaseComputeService implements ComputeService {
public void suspendNodesMatching(Predicate<NodeMetadata> filter) { public void suspendNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> suspending nodes matching(%s)", filter); logger.debug(">> suspending nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() { new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async // TODO use native async
@Override @Override
public Future<Void> apply(NodeMetadata from) { public ListenableFuture<Void> apply(NodeMetadata from) {
suspendNode(from.getId()); suspendNode(from.getId());
return immediateFuture(null); return immediateFuture(null);
} }
}, executor, null, logger, "suspendNodesMatching(" + filter + ")"); }, userExecutor, null, logger, "suspendNodesMatching(" + filter + ")");
logger.debug("<< suspended"); logger.debug("<< suspended");
} }
@ -543,7 +536,7 @@ public class BaseComputeService implements ComputeService {
Map<NodeMetadata, ExecResponse> goodNodes = newLinkedHashMap(); Map<NodeMetadata, ExecResponse> goodNodes = newLinkedHashMap();
Map<NodeMetadata, Exception> badNodes = newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = newLinkedHashMap();
Map<NodeMetadata, Future<ExecResponse>> responses = newLinkedHashMap(); Map<NodeMetadata, ListenableFuture<ExecResponse>> responses = newLinkedHashMap();
Map<?, Exception> exceptions = ImmutableMap.<Object, Exception> of(); Map<?, Exception> exceptions = ImmutableMap.<Object, Exception> of();
initAdminAccess.visit(runScript); initAdminAccess.visit(runScript);
@ -552,11 +545,11 @@ public class BaseComputeService implements ComputeService {
nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), runScript, options, badNodes); nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), runScript, options, badNodes);
if (Iterables.size(scriptRunners) > 0) { if (Iterables.size(scriptRunners) > 0) {
for (RunScriptOnNode runner : scriptRunners) { for (RunScriptOnNode runner : scriptRunners) {
responses.put(runner.getNode(), executor.submit(new RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap( responses.put(runner.getNode(), userExecutor.submit(new RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
runner, goodNodes, badNodes))); runner, goodNodes, badNodes)));
} }
try { try {
exceptions = awaitCompletion(responses, executor, null, logger, "runScriptOnNodesMatching(" + filter + ")"); exceptions = awaitCompletion(responses, userExecutor, null, logger, "runScriptOnNodesMatching(" + filter + ")");
} catch (TimeoutException te) { } catch (TimeoutException te) {
throw propagate(te); throw propagate(te);
} }
@ -638,22 +631,18 @@ public class BaseComputeService implements ComputeService {
final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options); final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options);
ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options); ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options);
response.addListener(new Runnable() { response.addListener(new Runnable() {
@Override
public void run() { public void run() {
persistNodeCredentials.ifAdminAccess(runScript).apply(node1); persistNodeCredentials.ifAdminAccess(runScript).apply(node1);
} }
}, userExecutor);
}, executor);
return response; return response;
} }
private Iterable<? extends RunScriptOnNode> transformNodesIntoInitializedScriptRunners( private Iterable<RunScriptOnNode> transformNodesIntoInitializedScriptRunners(
Iterable<? extends NodeMetadata> nodes, Statement script, RunScriptOptions options, Iterable<? extends NodeMetadata> nodes, Statement script, RunScriptOptions options,
Map<NodeMetadata, Exception> badNodes) { Map<NodeMetadata, Exception> badNodes) {
return filter( return filter(transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes),
transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes), userExecutor, null, logger, "initialize script runners"), notNull());
executor, null, logger, "initialize script runners"), notNull());
} }
private Set<? extends NodeMetadata> detailsOnAllNodes() { private Set<? extends NodeMetadata> detailsOnAllNodes() {
@ -690,7 +679,7 @@ public class BaseComputeService implements ComputeService {
} }
private final class TransformNodesIntoInitializedScriptRunners implements private final class TransformNodesIntoInitializedScriptRunners implements
Function<NodeMetadata, Future<? extends RunScriptOnNode>> { Function<NodeMetadata, ListenableFuture<? extends RunScriptOnNode>> {
private final Map<NodeMetadata, Exception> badNodes; private final Map<NodeMetadata, Exception> badNodes;
private final Statement script; private final Statement script;
private final RunScriptOptions options; private final RunScriptOptions options;
@ -703,9 +692,9 @@ public class BaseComputeService implements ComputeService {
} }
@Override @Override
public Future<RunScriptOnNode> apply(NodeMetadata node) { public ListenableFuture<RunScriptOnNode> apply(NodeMetadata node) {
node = updateNodeWithCredentialsIfPresent(node, options); node = updateNodeWithCredentialsIfPresent(node, options);
return executor.submit(initScriptRunnerFactory.create(node, script, options, badNodes)); return userExecutor.submit(initScriptRunnerFactory.create(node, script, options, badNodes));
} }
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.compute.internal; package org.jclouds.compute.internal;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -40,6 +39,7 @@ import org.jclouds.xml.XMLParser;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -55,11 +55,11 @@ public class UtilsImpl extends org.jclouds.rest.internal.UtilsImpl implements Ut
@Inject @Inject
UtilsImpl(Injector injector, Json json, XMLParser xml, HttpClient simpleClient, HttpAsyncClient simpleAsyncClient, UtilsImpl(Injector injector, Json json, XMLParser xml, HttpClient simpleClient, HttpAsyncClient simpleAsyncClient,
Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, EventBus eventBus, @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor, EventBus eventBus,
Map<String, Credentials> credentialStore, LoggerFactory loggerFactory, Map<String, Credentials> credentialStore, LoggerFactory loggerFactory,
Function<NodeMetadata, SshClient> sshForNode) { Function<NodeMetadata, SshClient> sshForNode) {
super(injector, json, xml, simpleClient, simpleAsyncClient, encryption, date, userThreads, ioThreads, eventBus, super(injector, json, xml, simpleClient, simpleAsyncClient, encryption, date, userExecutor, ioExecutor, eventBus,
credentialStore, loggerFactory); credentialStore, loggerFactory);
this.sshForNode = sshForNode; this.sshForNode = sshForNode;
} }

View File

@ -20,7 +20,6 @@ package org.jclouds.compute.strategy;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Future;
import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
@ -28,6 +27,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet; import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
/** /**
@ -37,6 +37,6 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class) @ImplementedBy(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class)
public interface CreateNodesInGroupThenAddToSet { public interface CreateNodesInGroupThenAddToSet {
Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses); Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses);
} }

View File

@ -24,13 +24,10 @@ import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Maps.newLinkedHashMap; import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.Sets.newLinkedHashSet;
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus; import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
import static org.jclouds.concurrent.Futures.compose;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -42,6 +39,7 @@ import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
@ -53,6 +51,9 @@ import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* creates futures that correlate to * creates futures that correlate to
@ -95,7 +96,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
protected final CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy; protected final CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy;
protected final ListNodesStrategy listNodesStrategy; protected final ListNodesStrategy listNodesStrategy;
protected final GroupNamingConvention.Factory namingConvention; protected final GroupNamingConvention.Factory namingConvention;
protected final ExecutorService executor; protected final ListeningExecutorService userExecutor;
protected final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory; protected final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
@Inject @Inject
@ -103,12 +104,12 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy, CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention, GroupNamingConvention.Factory namingConvention,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory) { CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory) {
this.addNodeWithGroupStrategy = addNodeWithGroupStrategy; this.addNodeWithGroupStrategy = addNodeWithGroupStrategy;
this.listNodesStrategy = listNodesStrategy; this.listNodesStrategy = listNodesStrategy;
this.namingConvention = namingConvention; this.namingConvention = namingConvention;
this.executor = executor; this.userExecutor = userExecutor;
this.customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory = customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory; this.customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory = customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
} }
@ -117,13 +118,13 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
* simultaneously runs the nodes and applies options to them. * simultaneously runs the nodes and applies options to them.
*/ */
@Override @Override
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Map<String, Future<Void>> responses = newLinkedHashMap(); Map<String, ListenableFuture<Void>> responses = newLinkedHashMap();
for (String name : getNextNames(group, template, count)) { for (String name : getNextNames(group, template, count)) {
responses.put(name, compose(createNodeInGroupWithNameAndTemplate(group, name, template), responses.put(name, Futures.transform(createNodeInGroupWithNameAndTemplate(group, name, template),
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory.create(template.getOptions(), goodNodes, customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory.create(template.getOptions(), goodNodes,
badNodes, customizationResponses), executor)); badNodes, customizationResponses), userExecutor));
} }
return responses; return responses;
} }
@ -141,10 +142,10 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
* *
* <pre> * <pre>
* &#064;Override * &#064;Override
* protected Future&lt;AtomicReference&lt;NodeMetadata&gt;&gt; createNodeInGroupWithNameAndTemplate(String group, String name, * protected ListenableFuture&lt;AtomicReference&lt;NodeMetadata&gt;&gt; createNodeInGroupWithNameAndTemplate(String group, String name,
* Template template) { * Template template) {
* *
* Future&lt;AtomicReference&lt;NodeMetadata&gt;&gt; future = super.addNodeIntoGroupWithNameAndTemplate(group, name, template); * ListenableFuture&lt;AtomicReference&lt;NodeMetadata&gt;&gt; future = super.addNodeIntoGroupWithNameAndTemplate(group, name, template);
* return Futures.compose(future, new Function&lt;AtomicReference&lt;NodeMetadata&gt;, AtomicReference&lt;NodeMetadata&gt;&gt;() { * return Futures.compose(future, new Function&lt;AtomicReference&lt;NodeMetadata&gt;, AtomicReference&lt;NodeMetadata&gt;&gt;() {
* *
* &#064;Override * &#064;Override
@ -164,9 +165,9 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
* @param template user-specified template * @param template user-specified template
* @return node that is created, yet not necessarily in {@link Status#RUNNING} * @return node that is created, yet not necessarily in {@link Status#RUNNING}
*/ */
protected Future<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group, String name, protected ListenableFuture<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group, String name,
Template template) { Template template) {
return executor.submit(new AddNode(name, group, template)); return userExecutor.submit(new AddNode(name, group, template));
} }
/** /**

View File

@ -21,10 +21,9 @@ package org.jclouds.compute.stub.config;
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus; import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -37,11 +36,11 @@ import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
@ -51,9 +50,10 @@ import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableList.Builder; import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -63,7 +63,7 @@ import com.google.common.collect.ImmutableList.Builder;
public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAdapter { public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAdapter {
private final Supplier<Location> location; private final Supplier<Location> location;
private final ConcurrentMap<String, NodeMetadata> nodes; private final ConcurrentMap<String, NodeMetadata> nodes;
private final ExecutorService ioThreads; private final ListeningExecutorService ioExecutor;
private final Provider<Integer> idProvider; private final Provider<Integer> idProvider;
private final String publicIpPrefix; private final String publicIpPrefix;
private final String privateIpPrefix; private final String privateIpPrefix;
@ -73,12 +73,12 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Inject @Inject
public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, Supplier<Location> location, @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor, Supplier<Location> location,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, @Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
JustProvider locationSupplier, Map<OsFamily, Map<String, String>> osToVersionMap) { JustProvider locationSupplier, Map<OsFamily, Map<String, String>> osToVersionMap) {
this.nodes = nodes; this.nodes = nodes;
this.ioThreads=ioThreads; this.ioExecutor = ioExecutor;
this.location = location; this.location = location;
this.idProvider = idProvider; this.idProvider = idProvider;
this.publicIpPrefix = publicIpPrefix; this.publicIpPrefix = publicIpPrefix;
@ -96,7 +96,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
if (millis == 0l) if (millis == 0l)
setStateOnNode(status, node); setStateOnNode(status, node);
else else
ioThreads.execute(new Runnable() { ioExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -187,7 +187,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
return; return;
setStateOnNodeAfterDelay(Status.PENDING, node, 0); setStateOnNodeAfterDelay(Status.PENDING, node, 0);
setStateOnNodeAfterDelay(Status.TERMINATED, node, 50); setStateOnNodeAfterDelay(Status.TERMINATED, node, 50);
ioThreads.execute(new Runnable() { ioExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -22,8 +22,6 @@ import static com.google.common.collect.Maps.newLinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -37,6 +35,8 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -45,22 +45,22 @@ import com.google.common.collect.Multimap;
@Singleton @Singleton
public class ComputeUtils { public class ComputeUtils {
private final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory; private final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
public ComputeUtils( public ComputeUtils(
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory = customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory; this.customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory = customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
this.executor = executor; this.userExecutor = userExecutor;
} }
public Map<?, Future<Void>> customizeNodesAndAddToGoodMapOrPutExceptionIntoBadMap(TemplateOptions options, public Map<?, ListenableFuture<Void>> customizeNodesAndAddToGoodMapOrPutExceptionIntoBadMap(TemplateOptions options,
Iterable<NodeMetadata> runningNodes, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Iterable<NodeMetadata> runningNodes, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes,
Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Map<NodeMetadata, Future<Void>> responses = newLinkedHashMap(); Map<NodeMetadata, ListenableFuture<Void>> responses = newLinkedHashMap();
for (NodeMetadata node : runningNodes) { for (NodeMetadata node : runningNodes) {
responses.put(node, executor.submit(customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory.create( responses.put(node, userExecutor.submit(customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory.create(
options, new AtomicReference<NodeMetadata>(node), goodNodes, badNodes, customizationResponses))); options, new AtomicReference<NodeMetadata>(node), goodNodes, badNodes, customizationResponses)));
} }
return responses; return responses;

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.compute.util; package org.jclouds.compute.util;
import static java.lang.String.format;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.or; import static com.google.common.base.Predicates.or;
@ -27,12 +26,12 @@ import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.size; import static com.google.common.collect.Iterables.size;
import static com.google.common.util.concurrent.Atomics.newReference; import static com.google.common.util.concurrent.Atomics.newReference;
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator; import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
import static java.lang.String.format;
import static org.jclouds.Constants.PROPERTY_USER_THREADS; import static org.jclouds.Constants.PROPERTY_USER_THREADS;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -66,16 +65,16 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
private final SocketOpen socketTester; private final SocketOpen socketTester;
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning; private final Predicate<AtomicReference<NodeMetadata>> nodeRunning;
private final ListeningExecutorService executor; private final ListeningExecutorService userExecutor;
@Inject @Inject
@VisibleForTesting @VisibleForTesting
ConcurrentOpenSocketFinder(SocketOpen socketTester, ConcurrentOpenSocketFinder(SocketOpen socketTester,
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning, @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
@Named(PROPERTY_USER_THREADS) ExecutorService userThreads) { @Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.socketTester = checkNotNull(socketTester, "socketTester"); this.socketTester = checkNotNull(socketTester, "socketTester");
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning"); this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
this.executor = listeningDecorator(checkNotNull(userThreads, "userThreads")); this.userExecutor = listeningDecorator(checkNotNull(userExecutor, "userExecutor"));
} }
@Override @Override
@ -123,7 +122,7 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
Builder<ListenableFuture<?>> futures = ImmutableList.builder(); Builder<ListenableFuture<?>> futures = ImmutableList.builder();
for (final HostAndPort socket : input) { for (final HostAndPort socket : input) {
futures.add(executor.submit(new Runnable() { futures.add(userExecutor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -27,7 +27,6 @@ import static org.testng.Assert.fail;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.jclouds.compute.callables.BlockUntilInitScriptStatusIsZeroThenReturnOutput.ExitStatusOfCommandGreaterThanZero; import org.jclouds.compute.callables.BlockUntilInitScriptStatusIsZeroThenReturnOutput.ExitStatusOfCommandGreaterThanZero;
@ -42,6 +41,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
/** /**
@ -139,7 +139,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
EventBus eventBus = new EventBus(); EventBus eventBus = new EventBus();
public void testExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException { public void testExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException {
ExecutorService userThreads = MoreExecutors.sameThreadExecutor(); ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
.addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString")
@ -155,7 +155,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
replay(commandRunner, initScript); replay(commandRunner, initScript);
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput(
userThreads, eventBus, notRunningAnymore, commandRunner); userExecutor, eventBus, notRunningAnymore, commandRunner);
future.run(); future.run();
@ -167,7 +167,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
public void testFirstExitStatusOneButSecondExitStatusZeroReturnsExecResponse() throws InterruptedException, public void testFirstExitStatusOneButSecondExitStatusZeroReturnsExecResponse() throws InterruptedException,
ExecutionException { ExecutionException {
ExecutorService userThreads = MoreExecutors.sameThreadExecutor(); ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
@ -190,7 +190,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
replay(commandRunner, initScript); replay(commandRunner, initScript);
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput(
userThreads, eventBus, notRunningAnymore, commandRunner); userExecutor, eventBus, notRunningAnymore, commandRunner);
future.run(); future.run();
@ -201,7 +201,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
} }
public void testCancelInterruptStopsCommand() throws InterruptedException, ExecutionException { public void testCancelInterruptStopsCommand() throws InterruptedException, ExecutionException {
ExecutorService userThreads = MoreExecutors.sameThreadExecutor(); ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod( SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod(
"refreshAndRunAction").addMockedMethod("runAction").addMockedMethod("getStatement").addMockedMethod( "refreshAndRunAction").addMockedMethod("runAction").addMockedMethod("getStatement").addMockedMethod(
@ -229,7 +229,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
replay(commandRunner, initScript); replay(commandRunner, initScript);
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput(
userThreads, eventBus, notRunningAnymore, commandRunner); userExecutor, eventBus, notRunningAnymore, commandRunner);
future.cancel(true); future.cancel(true);
@ -246,7 +246,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
public void testCancelDontInterruptLeavesCommandRunningAndReturnsLastStatus() throws InterruptedException, public void testCancelDontInterruptLeavesCommandRunningAndReturnsLastStatus() throws InterruptedException,
ExecutionException { ExecutionException {
ExecutorService userThreads = MoreExecutors.sameThreadExecutor(); ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
.addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString")
@ -262,7 +262,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutputTest {
replay(commandRunner, initScript); replay(commandRunner, initScript);
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput(
userThreads, eventBus, notRunningAnymore, commandRunner); userExecutor, eventBus, notRunningAnymore, commandRunner);
future.cancel(false); future.cancel(false);

View File

@ -423,7 +423,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
final long timeoutMs = 20 * 60 * 1000; final long timeoutMs = 20 * 60 * 1000;
List<String> groups = Lists.newArrayList(); List<String> groups = Lists.newArrayList();
List<ListenableFuture<NodeMetadata>> futures = Lists.newArrayList(); List<ListenableFuture<NodeMetadata>> futures = Lists.newArrayList();
ListeningExecutorService executor = MoreExecutors.listeningDecorator(context.utils().userExecutor()); ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(context.utils().userExecutor());
try { try {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -431,7 +431,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
final String group = "twin" + groupNum; final String group = "twin" + groupNum;
groups.add(group); groups.add(group);
ListenableFuture<NodeMetadata> future = executor.submit(new Callable<NodeMetadata>() { ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
public NodeMetadata call() throws Exception { public NodeMetadata call() throws Exception {
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080) NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080)
.blockOnPort(22, 300 + groupNum))); .blockOnPort(22, 300 + groupNum)));

View File

@ -30,7 +30,6 @@ import static org.testng.Assert.fail;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -47,6 +46,8 @@ import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
@Test(singleThreaded = true) @Test(singleThreaded = true)
public class ConcurrentOpenSocketFinderTest { public class ConcurrentOpenSocketFinderTest {
@ -67,24 +68,24 @@ public class ConcurrentOpenSocketFinderTest {
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning = alwaysTrue(); private final Predicate<AtomicReference<NodeMetadata>> nodeRunning = alwaysTrue();
private final Predicate<AtomicReference<NodeMetadata>> nodeNotRunning = alwaysFalse(); private final Predicate<AtomicReference<NodeMetadata>> nodeNotRunning = alwaysFalse();
private ExecutorService threadPool; private ListeningExecutorService userExecutor;
@BeforeClass @BeforeClass
public void setUp() { public void setUp() {
threadPool = Executors.newCachedThreadPool(); userExecutor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void tearDown() { public void tearDown() {
if (threadPool != null) if (userExecutor != null)
threadPool.shutdownNow(); userExecutor.shutdownNow();
} }
@Test @Test
public void testRespectsTimeout() throws Exception { public void testRespectsTimeout() throws Exception {
final long timeoutMs = 1000; final long timeoutMs = 1000;
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeRunning, threadPool); OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeRunning, userExecutor);
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
stopwatch.start(); stopwatch.start();
@ -109,7 +110,7 @@ public class ConcurrentOpenSocketFinderTest {
} }
}; };
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(secondSocketOpen, nodeRunning, threadPool); OpenSocketFinder finder = new ConcurrentOpenSocketFinder(secondSocketOpen, nodeRunning, userExecutor);
HostAndPort result = finder.findOpenSocketOnNode(node, 22, 2000, MILLISECONDS); HostAndPort result = finder.findOpenSocketOnNode(node, 22, 2000, MILLISECONDS);
assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22)); assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22));
@ -122,7 +123,7 @@ public class ConcurrentOpenSocketFinderTest {
HostAndPort.fromParts("1.2.3.4", 22), new SlowCallable<Boolean>(true, 1500), HostAndPort.fromParts("1.2.3.4", 22), new SlowCallable<Boolean>(true, 1500),
HostAndPort.fromParts("1.2.3.5", 22), new SlowCallable<Boolean>(true, 1000))); HostAndPort.fromParts("1.2.3.5", 22), new SlowCallable<Boolean>(true, 1000)));
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketTester, nodeRunning, threadPool); OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketTester, nodeRunning, userExecutor);
HostAndPort result = finder.findOpenSocketOnNode(node, 22, 2000, MILLISECONDS); HostAndPort result = finder.findOpenSocketOnNode(node, 22, 2000, MILLISECONDS);
assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22)); assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22));
@ -131,7 +132,7 @@ public class ConcurrentOpenSocketFinderTest {
@Test @Test
public void testAbortsWhenNodeNotRunning() throws Exception { public void testAbortsWhenNodeNotRunning() throws Exception {
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeNotRunning, threadPool) { OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeNotRunning, userExecutor) {
@Override @Override
protected <T> Predicate<T> retryPredicate(final Predicate<T> findOrBreak, long period, long timeoutValue, protected <T> Predicate<T> retryPredicate(final Predicate<T> findOrBreak, long period, long timeoutValue,
TimeUnit timeUnits) { TimeUnit timeUnits) {

View File

@ -24,7 +24,6 @@ import static org.jclouds.io.ByteSources.asByteSource;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutorService;
import javax.inject.Named; import javax.inject.Named;
@ -48,6 +47,7 @@ import org.jclouds.io.Payloads;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -62,10 +62,10 @@ public class ApacheHCHttpCommandExecutorService extends BaseHttpCommandExecutorS
@Inject @Inject
ApacheHCHttpCommandExecutorService(HttpUtils utils, ContentMetadataCodec contentMetadataCodec, ApacheHCHttpCommandExecutorService(HttpUtils utils, ContentMetadataCodec contentMetadataCodec,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor, @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor,
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler, DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
DelegatingErrorHandler errorHandler, HttpWire wire, HttpClient client) { DelegatingErrorHandler errorHandler, HttpWire wire, HttpClient client) {
super(utils, contentMetadataCodec, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire); super(utils, contentMetadataCodec, ioExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
this.client = client; this.client = client;
this.apacheHCUtils = new ApacheHCUtils(contentMetadataCodec); this.apacheHCUtils = new ApacheHCUtils(contentMetadataCodec);
} }

View File

@ -18,14 +18,14 @@
*/ */
package org.jclouds.enterprise.config; package org.jclouds.enterprise.config;
import java.util.concurrent.ExecutorService;
import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.joda.config.JodaDateServiceModule; import org.jclouds.date.joda.config.JodaDateServiceModule;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule; import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.netty.config.NettyPayloadModule; import org.jclouds.netty.config.NettyPayloadModule;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Configures Enterprise-grade components * Configures Enterprise-grade components
* *
@ -35,8 +35,8 @@ import org.jclouds.netty.config.NettyPayloadModule;
@ConfiguresExecutorService @ConfiguresExecutorService
public class EnterpriseConfigurationModule extends ExecutorServiceModule { public class EnterpriseConfigurationModule extends ExecutorServiceModule {
public EnterpriseConfigurationModule(ExecutorService userThreads, ExecutorService ioThreads) { public EnterpriseConfigurationModule(ListeningExecutorService userExecutor, ListeningExecutorService ioExecutor) {
super(userThreads, ioThreads); super(userExecutor, ioExecutor);
} }
public EnterpriseConfigurationModule() { public EnterpriseConfigurationModule() {

View File

@ -19,11 +19,12 @@
package org.jclouds.gae; package org.jclouds.gae;
import static com.google.common.base.Throwables.propagate; import static com.google.common.base.Throwables.propagate;
import static com.google.common.util.concurrent.Futures.transform;
import static com.google.common.util.concurrent.JdkFutureAdapters.listenInPoolThread;
import static org.jclouds.http.HttpUtils.checkRequestHasContentLengthOrChunkedEncoding; import static org.jclouds.http.HttpUtils.checkRequestHasContentLengthOrChunkedEncoding;
import static org.jclouds.http.HttpUtils.wirePayloadIfEnabled; import static org.jclouds.http.HttpUtils.wirePayloadIfEnabled;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutorService;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -31,7 +32,6 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.concurrent.Futures;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpCommandExecutorService; import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -50,6 +50,7 @@ import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Google App Engine version of {@link HttpCommandExecutorService} using their fetchAsync call * Google App Engine version of {@link HttpCommandExecutorService} using their fetchAsync call
@ -58,7 +59,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*/ */
@Singleton @Singleton
public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorService { public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorService {
private final ExecutorService service; private final ListeningExecutorService ioExecutor;
private final URLFetchService urlFetchService; private final URLFetchService urlFetchService;
private final ConvertToGaeRequest convertToGaeRequest; private final ConvertToGaeRequest convertToGaeRequest;
private final ConvertToJcloudsResponse convertToJcloudsResponse; private final ConvertToJcloudsResponse convertToJcloudsResponse;
@ -75,11 +76,12 @@ public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorSe
protected final HttpUtils utils; protected final HttpUtils utils;
@Inject @Inject
public AsyncGaeHttpCommandExecutorService(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, public AsyncGaeHttpCommandExecutorService(
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor,
URLFetchService urlFetchService, ConvertToGaeRequest convertToGaeRequest, URLFetchService urlFetchService, ConvertToGaeRequest convertToGaeRequest,
ConvertToJcloudsResponse convertToJcloudsResponse, DelegatingRetryHandler retryHandler, ConvertToJcloudsResponse convertToJcloudsResponse, DelegatingRetryHandler retryHandler,
IOExceptionRetryHandler ioRetryHandler, DelegatingErrorHandler errorHandler, HttpUtils utils, HttpWire wire) { IOExceptionRetryHandler ioRetryHandler, DelegatingErrorHandler errorHandler, HttpUtils utils, HttpWire wire) {
this.service = service; this.ioExecutor = ioExecutor;
this.urlFetchService = urlFetchService; this.urlFetchService = urlFetchService;
this.convertToGaeRequest = convertToGaeRequest; this.convertToGaeRequest = convertToGaeRequest;
this.convertToJcloudsResponse = convertToJcloudsResponse; this.convertToJcloudsResponse = convertToJcloudsResponse;
@ -109,10 +111,10 @@ public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorSe
HTTPRequest nativeRequest = filterLogAndConvertRe(command.getCurrentRequest()); HTTPRequest nativeRequest = filterLogAndConvertRe(command.getCurrentRequest());
ListenableFuture<HttpResponse> response = Futures.compose(urlFetchService.fetchAsync(nativeRequest), ListenableFuture<HttpResponse> response = transform(
convertToJcloudsResponse, service); listenInPoolThread(urlFetchService.fetchAsync(nativeRequest)), convertToJcloudsResponse);
return Futures.compose(response, new Function<HttpResponse, HttpResponse>() { return transform(response, new Function<HttpResponse, HttpResponse>() {
@Override @Override
public HttpResponse apply(HttpResponse response) { public HttpResponse apply(HttpResponse response) {
@ -159,7 +161,7 @@ public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorSe
} }
return shouldContinue; return shouldContinue;
} }
}, service); }, ioExecutor);
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.gae; package org.jclouds.gae;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -28,6 +27,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.JcloudsVersion; import org.jclouds.JcloudsVersion;
import org.jclouds.concurrent.SingleThreaded; import org.jclouds.concurrent.SingleThreaded;
import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
@ -42,6 +42,7 @@ import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* Google App Engine version of {@link HttpCommandExecutorService} * Google App Engine version of {@link HttpCommandExecutorService}
@ -61,7 +62,7 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
@Inject @Inject
public GaeHttpCommandExecutorService(URLFetchService urlFetchService, HttpUtils utils, public GaeHttpCommandExecutorService(URLFetchService urlFetchService, HttpUtils utils,
ContentMetadataCodec contentMetadataCodec, ContentMetadataCodec contentMetadataCodec,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioExecutor, @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor,
IOExceptionRetryHandler ioRetryHandler, DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler, DelegatingRetryHandler retryHandler,
DelegatingErrorHandler errorHandler, HttpWire wire, ConvertToGaeRequest convertToGaeRequest, DelegatingErrorHandler errorHandler, HttpWire wire, ConvertToGaeRequest convertToGaeRequest,
ConvertToJcloudsResponse convertToJcloudsResponse) { ConvertToJcloudsResponse convertToJcloudsResponse) {

View File

@ -41,8 +41,8 @@ public class AsyncGoogleAppEngineConfigurationModule extends GoogleAppEngineConf
super(); super();
} }
public AsyncGoogleAppEngineConfigurationModule(Module executorServiceModule) { public AsyncGoogleAppEngineConfigurationModule(Module userExecutorModule) {
super(executorServiceModule); super(userExecutorModule);
} }
/** /**

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ConfiguresExecutorService;
import org.jclouds.concurrent.config.DescribingExecutorService; import org.jclouds.concurrent.config.WithSubmissionTrace;
import com.google.appengine.api.ThreadManager; import com.google.appengine.api.ThreadManager;
import com.google.apphosting.api.ApiProxy; import com.google.apphosting.api.ApiProxy;
@ -99,20 +99,20 @@ public class CurrentRequestExecutorServiceModule extends AbstractModule {
int maxThreads = 10; int maxThreads = 10;
long keepAlive = ApiProxy.getCurrentEnvironment().getRemainingMillis(); long keepAlive = ApiProxy.getCurrentEnvironment().getRemainingMillis();
ExecutorService pool = newScalingThreadPool(0, maxThreads, keepAlive, factory); ExecutorService pool = newScalingThreadPool(0, maxThreads, keepAlive, factory);
return MoreExecutors.listeningDecorator(new DescribingExecutorService(pool)); return WithSubmissionTrace.wrap(MoreExecutors.listeningDecorator(pool));
} }
@Provides @Provides
@Singleton @Singleton
@Named(Constants.PROPERTY_USER_THREADS) @Named(Constants.PROPERTY_USER_THREADS)
protected ExecutorService userThreads() { protected ListeningExecutorService userExecutor() {
return memoizedCurrentRequestExecutorService.get(); return memoizedCurrentRequestExecutorService.get();
} }
@Provides @Provides
@Singleton @Singleton
@Named(Constants.PROPERTY_IO_WORKER_THREADS) @Named(Constants.PROPERTY_IO_WORKER_THREADS)
protected ExecutorService ioThreads() { protected ListeningExecutorService ioExecutor() {
return memoizedCurrentRequestExecutorService.get(); return memoizedCurrentRequestExecutorService.get();
} }
} }

View File

@ -47,7 +47,7 @@ import com.google.inject.Scopes;
@ConfiguresExecutorService @ConfiguresExecutorService
@SingleThreaded @SingleThreaded
public class GoogleAppEngineConfigurationModule extends AbstractModule { public class GoogleAppEngineConfigurationModule extends AbstractModule {
private final Module executorServiceModule; private final Module userExecutorModule;
public GoogleAppEngineConfigurationModule() { public GoogleAppEngineConfigurationModule() {
this(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); this(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
@ -59,8 +59,8 @@ public class GoogleAppEngineConfigurationModule extends AbstractModule {
* @param currentRequestExecutorService * @param currentRequestExecutorService
* @see CurrentRequestExecutorServiceModule#currentRequestExecutorService * @see CurrentRequestExecutorServiceModule#currentRequestExecutorService
*/ */
public GoogleAppEngineConfigurationModule(Module executorServiceModule) { public GoogleAppEngineConfigurationModule(Module userExecutorModule) {
this.executorServiceModule = executorServiceModule; this.userExecutorModule = userExecutorModule;
} }
/** /**
@ -70,12 +70,12 @@ public class GoogleAppEngineConfigurationModule extends AbstractModule {
* @see CurrentRequestExecutorServiceModule#memoizedCurrentRequestExecutorService * @see CurrentRequestExecutorServiceModule#memoizedCurrentRequestExecutorService
*/ */
public GoogleAppEngineConfigurationModule(Supplier<ListeningExecutorService> memoizedCurrentRequestExecutorService) { public GoogleAppEngineConfigurationModule(Supplier<ListeningExecutorService> memoizedCurrentRequestExecutorService) {
this.executorServiceModule = new CurrentRequestExecutorServiceModule(memoizedCurrentRequestExecutorService); this.userExecutorModule = new CurrentRequestExecutorServiceModule(memoizedCurrentRequestExecutorService);
} }
@Override @Override
protected void configure() { protected void configure() {
install(executorServiceModule); install(userExecutorModule);
bind(SocketOpen.class).to(SocketOpenUnsupported.class).in(Scopes.SINGLETON); bind(SocketOpen.class).to(SocketOpenUnsupported.class).in(Scopes.SINGLETON);
bindHttpCommandExecutorService(); bindHttpCommandExecutorService();
} }

View File

@ -235,11 +235,11 @@ public class JschSshClientLiveTest {
@Test @Test
public void testExecHostnameConcurrentlyWithSameSessions() throws Exception { public void testExecHostnameConcurrentlyWithSameSessions() throws Exception {
final SshClient client = setupClient(); final SshClient client = setupClient();
ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
List<ListenableFuture<ExecResponse>> futures = Lists.newArrayList(); List<ListenableFuture<ExecResponse>> futures = Lists.newArrayList();
try { try {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
futures.add(executor.submit(new Callable<ExecResponse>() { futures.add(userExecutor.submit(new Callable<ExecResponse>() {
@Override @Override
public ExecResponse call() { public ExecResponse call() {
ExecResponse response = client.exec("hostname"); ExecResponse response = client.exec("hostname");
@ -256,7 +256,7 @@ public class JschSshClientLiveTest {
: sshHost); : sshHost);
} }
} finally { } finally {
executor.shutdownNow(); userExecutor.shutdownNow();
client.disconnect(); client.disconnect();
} }
} }

View File

@ -22,7 +22,6 @@ package org.jclouds.abiquo.rest.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -40,6 +39,7 @@ import org.jclouds.rest.internal.UtilsImpl;
import org.jclouds.xml.XMLParser; import org.jclouds.xml.XMLParser;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -57,11 +57,11 @@ public class ExtendedUtils extends UtilsImpl implements Utils {
@Inject @Inject
public ExtendedUtils(final Injector injector, final Json json, final XMLParser xml, final HttpClient simpleApi, public ExtendedUtils(final Injector injector, final Json json, final XMLParser xml, final HttpClient simpleApi,
final HttpAsyncClient simpleAsyncApi, final Crypto encryption, final DateService date, final HttpAsyncClient simpleAsyncApi, final Crypto encryption, final DateService date,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userThreads, @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) final ExecutorService ioThreads, final EventBus eventBus, @Named(Constants.PROPERTY_IO_WORKER_THREADS) final ListeningExecutorService ioExecutor, final EventBus eventBus,
final Map<String, Credentials> credentialStore, final LoggerFactory loggerFactory, final Map<String, Credentials> credentialStore, final LoggerFactory loggerFactory,
final AbiquoHttpClient abiquoHttpClient, final AbiquoHttpAsyncClient abiquoHttpAsyncApi) { final AbiquoHttpClient abiquoHttpClient, final AbiquoHttpAsyncClient abiquoHttpAsyncApi) {
super(injector, json, xml, simpleApi, simpleAsyncApi, encryption, date, userThreads, ioThreads, eventBus, super(injector, json, xml, simpleApi, simpleAsyncApi, encryption, date, userExecutor, ioExecutor, eventBus,
credentialStore, loggerFactory); credentialStore, loggerFactory);
this.abiquoHttpClient = checkNotNull(abiquoHttpClient, "abiquoHttpClient"); this.abiquoHttpClient = checkNotNull(abiquoHttpClient, "abiquoHttpClient");
this.abiquoHttpAsyncApi = checkNotNull(abiquoHttpAsyncApi, "abiquoHttpAsyncApi"); this.abiquoHttpAsyncApi = checkNotNull(abiquoHttpAsyncApi, "abiquoHttpAsyncApi");

View File

@ -24,9 +24,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap; import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -44,6 +41,8 @@ import com.abiquo.server.core.cloud.VirtualApplianceDto;
import com.abiquo.server.core.cloud.VirtualAppliancesDto; import com.abiquo.server.core.cloud.VirtualAppliancesDto;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -58,7 +57,7 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
protected final ListVirtualDatacenters listVirtualDatacenters; protected final ListVirtualDatacenters listVirtualDatacenters;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -69,7 +68,7 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
@Inject @Inject
ListVirtualAppliances(final RestContext<AbiquoApi, AbiquoAsyncApi> context, ListVirtualAppliances(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor, @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor,
final ListVirtualDatacenters listVirtualDatacenters) { final ListVirtualDatacenters listVirtualDatacenters) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters"); this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters");
@ -92,9 +91,9 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final Iterable<VirtualDatacenter> vdcs) { private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final Iterable<VirtualDatacenter> vdcs) {
Iterable<VirtualAppliancesDto> vapps = transformParallel(vdcs, Iterable<VirtualAppliancesDto> vapps = transformParallel(vdcs,
new Function<VirtualDatacenter, Future<? extends VirtualAppliancesDto>>() { new Function<VirtualDatacenter, ListenableFuture<? extends VirtualAppliancesDto>>() {
@Override @Override
public Future<VirtualAppliancesDto> apply(final VirtualDatacenter input) { public ListenableFuture<VirtualAppliancesDto> apply(final VirtualDatacenter input) {
return context.getAsyncApi().getCloudApi().listVirtualAppliances(input.unwrap()); return context.getAsyncApi().getCloudApi().listVirtualAppliances(input.unwrap());
} }
}, userExecutor, maxTime, logger, "getting virtual appliances"); }, userExecutor, maxTime, logger, "getting virtual appliances");

View File

@ -25,8 +25,6 @@ import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -46,6 +44,8 @@ import com.abiquo.server.core.cloud.VirtualDatacentersDto;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -58,7 +58,7 @@ import com.google.inject.Singleton;
public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacenter> { public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacenter> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context; protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -69,7 +69,7 @@ public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacente
@Inject @Inject
ListVirtualDatacenters(final RestContext<AbiquoApi, AbiquoAsyncApi> context, ListVirtualDatacenters(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) { @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@ -103,9 +103,9 @@ public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacente
private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final List<Integer> ids) { private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final List<Integer> ids) {
Iterable<VirtualDatacenterDto> vdcs = transformParallel(ids, Iterable<VirtualDatacenterDto> vdcs = transformParallel(ids,
new Function<Integer, Future<? extends VirtualDatacenterDto>>() { new Function<Integer, ListenableFuture<? extends VirtualDatacenterDto>>() {
@Override @Override
public Future<VirtualDatacenterDto> apply(final Integer input) { public ListenableFuture<VirtualDatacenterDto> apply(final Integer input) {
return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input); return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input);
} }
}, userExecutor, maxTime, logger, "getting virtual datacenters"); }, userExecutor, maxTime, logger, "getting virtual datacenters");

View File

@ -24,9 +24,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap; import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -45,6 +42,8 @@ import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -57,7 +56,7 @@ import com.google.inject.Singleton;
public class ListVirtualMachines implements ListRootEntities<VirtualMachine> { public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context; protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
protected final ListVirtualAppliances listVirtualAppliances; protected final ListVirtualAppliances listVirtualAppliances;
@ -70,7 +69,7 @@ public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
@Inject @Inject
ListVirtualMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context, ListVirtualMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor, @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor,
final ListVirtualAppliances listVirtualAppliances) { final ListVirtualAppliances listVirtualAppliances) {
super(); super();
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
@ -99,9 +98,9 @@ public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
private Iterable<VirtualMachineWithNodeExtendedDto> listConcurrentVirtualMachines( private Iterable<VirtualMachineWithNodeExtendedDto> listConcurrentVirtualMachines(
final Iterable<VirtualAppliance> vapps, final VirtualMachineOptions options) { final Iterable<VirtualAppliance> vapps, final VirtualMachineOptions options) {
Iterable<VirtualMachinesWithNodeExtendedDto> vms = transformParallel(vapps, Iterable<VirtualMachinesWithNodeExtendedDto> vms = transformParallel(vapps,
new Function<VirtualAppliance, Future<? extends VirtualMachinesWithNodeExtendedDto>>() { new Function<VirtualAppliance, ListenableFuture<? extends VirtualMachinesWithNodeExtendedDto>>() {
@Override @Override
public Future<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) { public ListenableFuture<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) {
return context.getAsyncApi().getCloudApi().listVirtualMachines(input.unwrap(), options); return context.getAsyncApi().getCloudApi().listVirtualMachines(input.unwrap(), options);
} }
}, userExecutor, maxTime, logger, "getting virtual machines"); }, userExecutor, maxTime, logger, "getting virtual machines");

View File

@ -24,9 +24,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap; import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -45,6 +42,8 @@ import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -57,7 +56,7 @@ import com.google.inject.Singleton;
public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineTemplate, Enterprise> { public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineTemplate, Enterprise> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context; protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -68,7 +67,7 @@ public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineT
@Inject @Inject
ListVirtualMachineTemplates(final RestContext<AbiquoApi, AbiquoAsyncApi> context, ListVirtualMachineTemplates(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) { @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) {
super(); super();
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
@ -92,9 +91,9 @@ public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineT
private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final Enterprise parent, private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final Enterprise parent,
final Iterable<Datacenter> dcs) { final Iterable<Datacenter> dcs) {
Iterable<VirtualMachineTemplatesDto> templates = transformParallel(dcs, Iterable<VirtualMachineTemplatesDto> templates = transformParallel(dcs,
new Function<Datacenter, Future<? extends VirtualMachineTemplatesDto>>() { new Function<Datacenter, ListenableFuture<? extends VirtualMachineTemplatesDto>>() {
@Override @Override
public Future<VirtualMachineTemplatesDto> apply(final Datacenter input) { public ListenableFuture<VirtualMachineTemplatesDto> apply(final Datacenter input) {
return context.getAsyncApi().getVirtualMachineTemplateApi() return context.getAsyncApi().getVirtualMachineTemplateApi()
.listVirtualMachineTemplates(parent.getId(), input.getId()); .listVirtualMachineTemplates(parent.getId(), input.getId());
} }

View File

@ -24,9 +24,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.abiquo.domain.DomainWrapper.wrap; import static org.jclouds.abiquo.domain.DomainWrapper.wrap;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -47,6 +44,8 @@ import com.abiquo.server.core.infrastructure.RackDto;
import com.abiquo.server.core.infrastructure.RacksDto; import com.abiquo.server.core.infrastructure.RacksDto;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -59,7 +58,7 @@ import com.google.inject.Singleton;
public class ListMachines implements ListRootEntities<Machine> { public class ListMachines implements ListRootEntities<Machine> {
protected RestContext<AbiquoApi, AbiquoAsyncApi> context; protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor; protected final ListeningExecutorService userExecutor;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -70,7 +69,7 @@ public class ListMachines implements ListRootEntities<Machine> {
@Inject @Inject
ListMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context, ListMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) { @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) {
super(); super();
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
@ -93,9 +92,9 @@ public class ListMachines implements ListRootEntities<Machine> {
} }
private Iterable<RackDto> listConcurrentRacks(final Iterable<Datacenter> datacenters) { private Iterable<RackDto> listConcurrentRacks(final Iterable<Datacenter> datacenters) {
Iterable<RacksDto> racks = transformParallel(datacenters, new Function<Datacenter, Future<? extends RacksDto>>() { Iterable<RacksDto> racks = transformParallel(datacenters, new Function<Datacenter, ListenableFuture<? extends RacksDto>>() {
@Override @Override
public Future<RacksDto> apply(final Datacenter input) { public ListenableFuture<RacksDto> apply(final Datacenter input) {
return context.getAsyncApi().getInfrastructureApi().listRacks(input.unwrap()); return context.getAsyncApi().getInfrastructureApi().listRacks(input.unwrap());
} }
}, userExecutor, maxTime, logger, "getting racks"); }, userExecutor, maxTime, logger, "getting racks");
@ -104,9 +103,9 @@ public class ListMachines implements ListRootEntities<Machine> {
} }
private Iterable<MachineDto> listConcurrentMachines(final Iterable<RackDto> racks) { private Iterable<MachineDto> listConcurrentMachines(final Iterable<RackDto> racks) {
Iterable<MachinesDto> machines = transformParallel(racks, new Function<RackDto, Future<? extends MachinesDto>>() { Iterable<MachinesDto> machines = transformParallel(racks, new Function<RackDto, ListenableFuture<? extends MachinesDto>>() {
@Override @Override
public Future<MachinesDto> apply(final RackDto input) { public ListenableFuture<MachinesDto> apply(final RackDto input) {
return context.getAsyncApi().getInfrastructureApi().listMachines(input); return context.getAsyncApi().getInfrastructureApi().listMachines(input);
} }
}, userExecutor, maxTime, logger, "getting machines"); }, userExecutor, maxTime, logger, "getting machines");

View File

@ -21,11 +21,10 @@ package org.jclouds.elb.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.util.concurrent.Futures.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -34,7 +33,6 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.collect.PagedIterable; import org.jclouds.collect.PagedIterable;
import org.jclouds.concurrent.Futures;
import org.jclouds.elb.ELBAsyncApi; import org.jclouds.elb.ELBAsyncApi;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.elb.domain.regionscoped.LoadBalancerInRegion; import org.jclouds.elb.domain.regionscoped.LoadBalancerInRegion;
@ -47,6 +45,7 @@ import org.jclouds.logging.Logger;
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.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -60,29 +59,29 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
private final ELBAsyncApi aapi; private final ELBAsyncApi aapi;
private final Function<LoadBalancerInRegion, LoadBalancerMetadata> converter; private final Function<LoadBalancerInRegion, LoadBalancerMetadata> converter;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
private final Supplier<Set<String>> regions; private final Supplier<Set<String>> regions;
@Inject @Inject
protected ELBListLoadBalancersStrategy(ELBAsyncApi aapi, protected ELBListLoadBalancersStrategy(ELBAsyncApi aapi,
Function<LoadBalancerInRegion, LoadBalancerMetadata> converter, Function<LoadBalancerInRegion, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Region Supplier<Set<String>> regions) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, @Region Supplier<Set<String>> regions) {
this.aapi = checkNotNull(aapi, "aapi"); this.aapi = checkNotNull(aapi, "aapi");
this.regions = checkNotNull(regions, "regions"); this.regions = checkNotNull(regions, "regions");
this.converter = checkNotNull(converter, "converter"); this.converter = checkNotNull(converter, "converter");
this.executor = checkNotNull(executor, "executor"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
} }
@Override @Override
public Iterable<LoadBalancerMetadata> listLoadBalancers() { public Iterable<LoadBalancerMetadata> listLoadBalancers() {
Iterable<LoadBalancerInRegion> loadBalancers = concat(transformParallel(regions.get(), Iterable<LoadBalancerInRegion> loadBalancers = concat(transformParallel(regions.get(),
new Function<String, Future<? extends Iterable<LoadBalancerInRegion>>>() { new Function<String, ListenableFuture<? extends Iterable<LoadBalancerInRegion>>>() {
@Override @Override
public ListenableFuture<? extends Iterable<LoadBalancerInRegion>> apply(final String from) { public ListenableFuture<? extends Iterable<LoadBalancerInRegion>> apply(final String from) {
// TODO: ELB.listLoadBalancers // TODO: ELB.listLoadBalancers
return Futures.compose(aapi.getLoadBalancerApiForRegion(from).list(), return transform(aapi.getLoadBalancerApiForRegion(from).list(),
new Function<PagedIterable<LoadBalancer>, Iterable<LoadBalancerInRegion>>() { new Function<PagedIterable<LoadBalancer>, Iterable<LoadBalancerInRegion>>() {
@Override @Override
@ -96,10 +95,10 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
}); });
} }
}, executor); }, userExecutor);
} }
}, executor, null, logger, "loadbalancers")); }, userExecutor, null, logger, "loadbalancers"));
return transform(loadBalancers, converter); return transform(loadBalancers, converter);
} }
} }

View File

@ -25,7 +25,6 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_T
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -75,6 +74,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -101,7 +101,7 @@ public class JoyentCloudComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, JoyentCloudApi novaApi, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, JoyentCloudApi novaApi,
LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache, LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache,
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByDatacenterId, Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByDatacenterId,
GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension) { GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension) {
@ -109,7 +109,7 @@ public class JoyentCloudComputeService extends BaseComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension); persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.novaApi = checkNotNull(novaApi, "novaApi"); this.novaApi = checkNotNull(novaApi, "novaApi");
this.keyCache = checkNotNull(keyCache, "keyCache"); this.keyCache = checkNotNull(keyCache, "keyCache");
this.orphanedGroupsByDatacenterId = checkNotNull(orphanedGroupsByDatacenterId, "orphanedGroupsByDatacenterId"); this.orphanedGroupsByDatacenterId = checkNotNull(orphanedGroupsByDatacenterId, "orphanedGroupsByDatacenterId");

View File

@ -24,8 +24,6 @@ import static org.jclouds.joyent.cloudapi.v6_5.config.JoyentCloudProperties.AUTO
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -46,6 +44,8 @@ import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatacenterAndNam
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -64,17 +64,17 @@ public class ApplyJoyentCloudTemplateOptionsCreateNodesWithGroupEncodedIntoNameT
ListNodesStrategy listNodesStrategy, ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention, GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache, LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache,
@Named(AUTOGENERATE_KEYS) boolean defaultToAutogenerateKeys) { @Named(AUTOGENERATE_KEYS) boolean defaultToAutogenerateKeys) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.keyCache = checkNotNull(keyCache, "keyCache"); this.keyCache = checkNotNull(keyCache, "keyCache");
this.defaultToAutogenerateKeys = defaultToAutogenerateKeys; this.defaultToAutogenerateKeys = defaultToAutogenerateKeys;
} }
@Override @Override
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate = template.clone(); Template mutableTemplate = template.clone();

View File

@ -25,7 +25,6 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
@ -127,14 +126,12 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
@Inject @Inject
protected LoadingCache<Image, Master> mastersCache; protected LoadingCache<Image, Master> mastersCache;
private final ExecutorService singleThreadExec = sameThreadExecutor();
private String masterName; private String masterName;
@Override @Override
protected Iterable<Module> setupModules() { protected Iterable<Module> setupModules() {
return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule( return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule(
singleThreadExec, singleThreadExec)); sameThreadExecutor(), sameThreadExecutor()));
} }
@Override @Override

View File

@ -29,7 +29,6 @@ import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_GENERATE_INSTA
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -74,6 +73,7 @@ import com.google.common.base.Optional;
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.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -100,7 +100,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, AWSEC2Client client, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, AWSEC2Client client,
ConcurrentMap<RegionAndName, KeyPair> credentialsMap, ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap, @Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
@Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap, @Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap,
@ -111,7 +111,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess, nodeTerminated, nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess,
persistNodeCredentials, timeouts, executor, client, credentialsMap, securityGroupMap, imageExtension, persistNodeCredentials, timeouts, userExecutor, client, credentialsMap, securityGroupMap, imageExtension,
namingConvention, generateInstanceNames); namingConvention, generateInstanceNames);
this.client = client; this.client = client;
this.placementGroupMap = placementGroupMap; this.placementGroupMap = placementGroupMap;

View File

@ -26,8 +26,6 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -44,6 +42,8 @@ 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.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -59,9 +59,9 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Inject @Inject
protected AWSEC2ListNodesStrategy(AWSEC2AsyncClient client, @Region Supplier<Set<String>> regions, protected AWSEC2ListNodesStrategy(AWSEC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
SpotInstanceRequestToAWSRunningInstance spotConverter) { SpotInstanceRequestToAWSRunningInstance spotConverter) {
super(client, regions, runningInstanceToNodeMetadata, executor); super(client, regions, runningInstanceToNodeMetadata, userExecutor);
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.spotConverter = checkNotNull(spotConverter, "spotConverter"); this.spotConverter = checkNotNull(spotConverter, "spotConverter");
} }
@ -69,14 +69,13 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Override @Override
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions.get(), Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions.get(),
new Function<String, Future<? extends Set<SpotInstanceRequest>>>() { new Function<String, ListenableFuture<? extends Set<SpotInstanceRequest>>>() {
@Override @Override
public Future<? extends Set<SpotInstanceRequest>> apply(String from) { public ListenableFuture<? extends Set<SpotInstanceRequest>> apply(String from) {
return client.getSpotInstanceServices() return client.getSpotInstanceServices().describeSpotInstanceRequestsInRegion(from);
.describeSpotInstanceRequestsInRegion(from);
} }
}, executor, maxTime, logger, "reservations")), spotConverter), notNull()); }, userExecutor, maxTime, logger, "reservations")), spotConverter), notNull());
return concat(super.pollRunningInstances(), spots); return concat(super.pollRunningInstances(), spots);
} }

View File

@ -26,8 +26,6 @@ import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGI
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -55,6 +53,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
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.ListeningExecutorService;
/** /**
* *
@ -71,7 +71,7 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
private final Set<String> clusterComputeIds; private final Set<String> clusterComputeIds;
private final CallForImages.Factory factory; private final CallForImages.Factory factory;
private final ExecutorService executor; private final ListeningExecutorService userExecutor;
private final Supplier<Set<String>> regions; private final Supplier<Set<String>> regions;
private final Map<String, String> queries; private final Map<String, String> queries;
@ -83,14 +83,14 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
@ImageQuery Map<String, String> queries, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions, @ImageQuery Map<String, String> queries, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions,
Supplier<LoadingCache<RegionAndName, ? extends Image>> cache, Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
CallForImages.Factory factory, @ClusterCompute Set<String> clusterComputeIds, CallForImages.Factory factory, @ClusterCompute Set<String> clusterComputeIds,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.factory = factory; this.factory = factory;
this.regions = regions; this.regions = regions;
this.queries = queries; this.queries = queries;
this.clusterRegions = Splitter.on(',').split(clusterRegions); this.clusterRegions = Splitter.on(',').split(clusterRegions);
this.cache = cache; this.cache = cache;
this.clusterComputeIds = clusterComputeIds; this.clusterComputeIds = clusterComputeIds;
this.executor = executor; this.userExecutor = userExecutor;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -99,7 +99,7 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
String amiQuery = queries.get(PROPERTY_EC2_AMI_QUERY); String amiQuery = queries.get(PROPERTY_EC2_AMI_QUERY);
String ccAmiQuery = queries.get(PROPERTY_EC2_CC_AMI_QUERY); String ccAmiQuery = queries.get(PROPERTY_EC2_CC_AMI_QUERY);
Future<Iterable<Image>> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY); ListenableFuture<Iterable<Image>> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY);
ImmutableSet<Image> clusterImages; ImmutableSet<Image> clusterImages;
try { try {
clusterImages = ImmutableSet.copyOf(images(clusterRegions, ccAmiQuery, PROPERTY_EC2_CC_AMI_QUERY).get()); clusterImages = ImmutableSet.copyOf(images(clusterRegions, ccAmiQuery, PROPERTY_EC2_CC_AMI_QUERY).get());
@ -136,12 +136,12 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
}; };
} }
private Future<Iterable<Image>> images(Iterable<String> regions, String query, String tag) { private ListenableFuture<Iterable<Image>> images(Iterable<String> regions, String query, String tag) {
if (query == null) { if (query == null) {
logger.debug(">> no %s specified, skipping image parsing", tag); logger.debug(">> no %s specified, skipping image parsing", tag);
return Futures.<Iterable<Image>> immediateFuture(ImmutableSet.<Image> of()); return Futures.<Iterable<Image>> immediateFuture(ImmutableSet.<Image> of());
} else { } else {
return executor.submit(factory.parseImagesFromRegionsUsingFilter(regions, QueryStringToMultimap.INSTANCE return userExecutor.submit(factory.parseImagesFromRegionsUsingFilter(regions, QueryStringToMultimap.INSTANCE
.apply(query))); .apply(query)));
} }
} }

View File

@ -21,7 +21,6 @@ package org.jclouds.aws.s3.blobstore;
import static org.jclouds.s3.domain.ObjectMetadata.StorageClass.REDUCED_REDUNDANCY; import static org.jclouds.s3.domain.ObjectMetadata.StorageClass.REDUCED_REDUNDANCY;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -60,6 +59,7 @@ import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -73,7 +73,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore {
@Inject @Inject
public AWSS3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, public AWSS3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AWSS3AsyncClient async, AWSS3Client sync, @Memoized Supplier<Set<? extends Location>> locations, AWSS3AsyncClient async, AWSS3Client sync,
Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata, Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
@ -81,7 +81,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, AccessControlList> bucketAcls, LoadingCache<String, AccessControlList> bucketAcls,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations, async, sync, convertBucketsToStorageMetadata, super(context, blobUtils, userExecutor, defaultLocation, locations, async, sync, convertBucketsToStorageMetadata,
container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object, container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object,
object2BlobMd, fetchBlobMetadataProvider, bucketAcls); object2BlobMd, fetchBlobMetadataProvider, bucketAcls);
this.multipartUploadStrategy = multipartUploadStrategy; this.multipartUploadStrategy = multipartUploadStrategy;

View File

@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -48,7 +47,6 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.internal.BlobRuntimeException; import org.jclouds.blobstore.internal.BlobRuntimeException;
import org.jclouds.blobstore.options.PutOptions; import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.PayloadSlicer; import org.jclouds.io.PayloadSlicer;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -58,6 +56,7 @@ import org.jclouds.util.Throwables2;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject; import com.google.inject.Inject;
public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStrategy { public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStrategy {
@ -72,7 +71,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@VisibleForTesting @VisibleForTesting
static final int DEFAULT_MAX_PERCENT_RETRIES = 10; static final int DEFAULT_MAX_PERCENT_RETRIES = 10;
private final ExecutorService ioWorkerExecutor; private final ListeningExecutorService ioExecutor;
@Inject(optional = true) @Inject(optional = true)
@Named("jclouds.mpu.parallel.degree") @Named("jclouds.mpu.parallel.degree")
@ -101,10 +100,10 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@Inject @Inject
public ParallelMultipartUploadStrategy(AWSS3AsyncBlobStore ablobstore, PayloadSlicer slicer, public ParallelMultipartUploadStrategy(AWSS3AsyncBlobStore ablobstore, PayloadSlicer slicer,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor) { @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor) {
this.ablobstore = checkNotNull(ablobstore, "ablobstore"); this.ablobstore = checkNotNull(ablobstore, "ablobstore");
this.slicer = checkNotNull(slicer, "slicer"); this.slicer = checkNotNull(slicer, "slicer");
this.ioWorkerExecutor = checkNotNull(ioWorkerExecutor, "ioWorkerExecutor"); this.ioExecutor = checkNotNull(ioExecutor, "ioExecutor");
} }
protected void prepareUploadPart(final String container, final String key, protected void prepareUploadPart(final String container, final String key,
@ -149,14 +148,13 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
latch.countDown(); latch.countDown();
} }
} }
}, ioWorkerExecutor); }, ioExecutor);
futureParts.put(part, futureETag); futureParts.put(part, futureETag);
} }
@Override @Override
public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options) { public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options) {
return Futures.makeListenable( return ioExecutor.submit(new Callable<String>() {
ioWorkerExecutor.submit(new Callable<String>() {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
String key = blob.getMetadata().getName(); String key = blob.getMetadata().getName();
@ -250,7 +248,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
futureETag.get(maxTime,TimeUnit.SECONDS) : futureETag.get(); futureETag.get(maxTime,TimeUnit.SECONDS) : futureETag.get();
} }
} }
}), ioWorkerExecutor); });
} }
class Part { class Part {

View File

@ -19,10 +19,10 @@
package org.jclouds.azureblob.blobstore; package org.jclouds.azureblob.blobstore;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.transform;
import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata; import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -56,7 +56,6 @@ import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.options.PutOptions; import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -64,6 +63,7 @@ import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -81,14 +81,14 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
@Inject @Inject
AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async, @Memoized Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async,
ContainerToResourceMetadata container2ResourceMd, ContainerToResourceMetadata container2ResourceMd,
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob, ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd, BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd,
BlobToHttpGetOptions blob2ObjectGetOptions) { BlobToHttpGetOptions blob2ObjectGetOptions) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, userExecutor, defaultLocation, locations);
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions, this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
@ -106,8 +106,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>> list() { public ListenableFuture<org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>> list() {
return Futures return transform(
.compose(
async.listContainers(includeMetadata()), async.listContainers(includeMetadata()),
new Function<BoundedSet<ContainerProperties>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() { new Function<BoundedSet<ContainerProperties>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply( public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(
@ -115,7 +114,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
return new PageSetImpl<StorageMetadata>(Iterables.transform(from, container2ResourceMd), return new PageSetImpl<StorageMetadata>(Iterables.transform(from, container2ResourceMd),
from.getNextMarker()); from.getNextMarker());
} }
}, service); }, userExecutor);
} }
/** /**
@ -152,7 +151,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) { public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
ListBlobsOptions azureOptions = blobStore2AzureContainerListOptions.apply(options); ListBlobsOptions azureOptions = blobStore2AzureContainerListOptions.apply(options);
ListenableFuture<ListBlobsResponse> returnVal = async.listBlobs(container, azureOptions.includeMetadata()); ListenableFuture<ListBlobsResponse> returnVal = async.listBlobs(container, azureOptions.includeMetadata());
return Futures.compose(returnVal, azure2BlobStoreResourceList, service); return transform(returnVal, azure2BlobStoreResourceList, userExecutor);
} }
/** /**
@ -178,7 +177,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
GetOptions azureOptions = blob2ObjectGetOptions.apply(options); GetOptions azureOptions = blob2ObjectGetOptions.apply(options);
ListenableFuture<AzureBlob> returnVal = async.getBlob(container, key, azureOptions); ListenableFuture<AzureBlob> returnVal = async.getBlob(container, key, azureOptions);
return Futures.compose(returnVal, azureBlob2Blob, service); return transform(returnVal, azureBlob2Blob, userExecutor);
} }
/** /**
@ -230,14 +229,11 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
*/ */
@Override @Override
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return Futures.compose(async.getBlobProperties(container, key), new Function<BlobProperties, BlobMetadata>() { return transform(async.getBlobProperties(container, key), new Function<BlobProperties, BlobMetadata>() {
@Override
public BlobMetadata apply(BlobProperties from) { public BlobMetadata apply(BlobProperties from) {
return blob2BlobMd.apply(from); return blob2BlobMd.apply(from);
} }
}, userExecutor);
}, service);
} }
@Override @Override

View File

@ -29,8 +29,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -74,6 +72,8 @@ import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* defines the connection between the {@link GleSYSApi} implementation and * defines the connection between the {@link GleSYSApi} implementation and
@ -89,17 +89,17 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
private final GleSYSApi api; private final GleSYSApi api;
private final GleSYSAsyncApi aapi; private final GleSYSAsyncApi aapi;
private final ExecutorService userThreads; private final ListeningExecutorService userExecutor;
private final Timeouts timeouts; private final Timeouts timeouts;
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
@Inject @Inject
public GleSYSComputeServiceAdapter(GleSYSApi api, GleSYSAsyncApi aapi, public GleSYSComputeServiceAdapter(GleSYSApi api, GleSYSAsyncApi aapi,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Timeouts timeouts,
@Memoized Supplier<Set<? extends Location>> locations) { @Memoized Supplier<Set<? extends Location>> locations) {
this.api = checkNotNull(api, "api"); this.api = checkNotNull(api, "api");
this.aapi = checkNotNull(aapi, "aapi"); this.aapi = checkNotNull(aapi, "aapi");
this.userThreads = checkNotNull(userThreads, "userThreads"); this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.timeouts = checkNotNull(timeouts, "timeouts"); this.timeouts = checkNotNull(timeouts, "timeouts");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
} }
@ -209,13 +209,11 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
@Override @Override
public Iterable<ServerDetails> listNodes() { public Iterable<ServerDetails> listNodes() {
return transformParallel(api.getServerApi().list(), new Function<Server, Future<? extends ServerDetails>>() { return transformParallel(api.getServerApi().list(), new Function<Server, ListenableFuture<? extends ServerDetails>>() {
@Override public ListenableFuture<ServerDetails> apply(Server from) {
public Future<ServerDetails> apply(Server from) {
return aapi.getServerApi().get(from.getId()); return aapi.getServerApi().get(from.getId());
} }
}, userExecutor, null, logger, "server details");
}, userThreads, null, logger, "server details");
} }
@Override @Override

View File

@ -23,7 +23,6 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_T
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -61,6 +60,7 @@ import org.jclouds.scriptbuilder.functions.InitAdminAccess;
import com.google.common.base.Optional; import com.google.common.base.Optional;
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.util.concurrent.ListeningExecutorService;
/** /**
* @author Andrew Kennedy * @author Andrew Kennedy
@ -82,13 +82,13 @@ public class GoGridComputeService extends BaseComputeService {
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended, @Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials, RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
Optional<ImageExtension> imageExtension) { Optional<ImageExtension> imageExtension) {
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy, super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension); persistNodeCredentials, timeouts, userExecutor, imageExtension);
} }
/** /**

View File

@ -18,8 +18,9 @@
*/ */
package org.jclouds.hpcloud.objectstorage.blobstore; package org.jclouds.hpcloud.objectstorage.blobstore;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -33,10 +34,9 @@ import org.jclouds.blobstore.options.CreateContainerOptions;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi; import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.blobstore.functions.EnableCDNAndCache; import org.jclouds.hpcloud.objectstorage.blobstore.functions.EnableCDNAndCache;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions;
@ -50,6 +50,7 @@ import org.jclouds.openstack.swift.blobstore.strategy.internal.AsyncMultipartUpl
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.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/** /**
* *
@ -61,7 +62,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
@Inject @Inject
protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, HPCloudObjectStorageApi sync, HPCloudObjectStorageAsyncApi async, @Memoized Supplier<Set<? extends Location>> locations, HPCloudObjectStorageApi sync, HPCloudObjectStorageAsyncApi async,
ContainerToResourceMetadata container2ResourceMd, ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -69,7 +70,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations, sync, async, container2ResourceMd, super(context, blobUtils, userExecutor, defaultLocation, locations, sync, async, container2ResourceMd,
container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy); blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
this.enableAndCache = enableAndCache; this.enableAndCache = enableAndCache;
@ -81,7 +82,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container); ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container);
if (options.isPublicRead()) if (options.isPublicRead())
return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() { return transform(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
@Override @Override
public Boolean apply(Boolean input) { public Boolean apply(Boolean input) {
@ -91,7 +92,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
return false; return false;
} }
}, service); }, userExecutor);
return returnVal; return returnVal;
} }
} }