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;
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 java.net.URI;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.crypto.Crypto;
import org.jclouds.domain.Location;
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.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -86,14 +86,14 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
@Inject
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,
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, Boolean> isPublic) {
super(context, blobUtils, service, defaultLocation, locations);
super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.sync = checkNotNull(sync, "sync");
this.async = checkNotNull(async, "async");
@ -113,12 +113,12 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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
public BlobMetadata apply(AtmosObject from) {
return object2BlobMd.apply(from);
}
}, service);
}, userExecutor);
}
/**
@ -128,13 +128,11 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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) {
return true;
}
}, service);
}, userExecutor);
}
/**
@ -142,13 +140,11 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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) {
return null;// no etag
}
}, service);
}, userExecutor);
}
/**
@ -204,7 +200,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
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
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);
ListOptions nativeOptions = container2ContainerListOptions.apply(options);
ListenableFuture<BoundedSet<? extends DirectoryEntry>> returnVal = async.listDirectory(container, nativeOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, container2ResourceList,
service);
return (ListenableFuture<PageSet<? extends StorageMetadata>>) (options.isDetailed() ? Futures.compose(list,
fetchBlobMetadataProvider.get().setContainerName(container), service) : list);
ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, container2ResourceList,
userExecutor);
return (ListenableFuture<PageSet<? extends StorageMetadata>>) (options.isDetailed() ? transform(list,
fetchBlobMetadataProvider.get().setContainerName(container)) : list);
}
/**
@ -244,7 +240,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
} catch (CacheLoader.InvalidCacheLoadException e) {
// nulls not permitted
}
return Futures.makeListenable(service.submit(new Callable<String>() {
return userExecutor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
@ -255,7 +251,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public String toString() {
return "putBlob(" + container + "," + blob.getMetadata().getName() + ")";
}
}), service);
});
}
@ -277,13 +273,13 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container,
CreateContainerOptions options) {
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) {
return true;
}
}, service);
}, userExecutor);
return createContainerInLocation(location, container);
}

View File

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

View File

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

View File

@ -18,8 +18,9 @@
*/
package org.jclouds.cloudfiles.blobstore;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -36,7 +37,6 @@ import org.jclouds.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
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.ObjectToBlob;
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.Supplier;
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
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,
ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -69,7 +70,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache,
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,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
this.enableCDNAndCache = enableCDNAndCache;
@ -81,7 +82,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container);
if (options.isPublicRead())
return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
return transform(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
@Override
public Boolean apply(Boolean input) {
@ -91,7 +92,7 @@ public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
return false;
}
}, service);
}, userExecutor);
return returnVal;
}
}

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.NoSuchElementException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
@ -41,12 +40,12 @@ import org.jclouds.compute.domain.ImageTemplate;
import org.jclouds.compute.domain.ImageTemplateBuilder;
import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.PredicateWithResult;
import org.jclouds.predicates.Retryables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* CloudServers implementation of {@link ImageExtension}
@ -62,7 +61,7 @@ public class CloudServersImageExtension implements ImageExtension {
protected Logger logger = Logger.NULL;
private final CloudServersClient client;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
private final PredicateWithResult<Integer, Image> imageAvailablePredicate;
@com.google.inject.Inject(optional = true)
@Named("IMAGE_MAX_WAIT")
@ -73,11 +72,11 @@ public class CloudServersImageExtension implements ImageExtension {
@Inject
public CloudServersImageExtension(CloudServersClient client,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
PredicateWithResult<Integer, Image> imageAvailablePredicate) {
this.client = checkNotNull(client);
this.executor = userThreads;
this.imageAvailablePredicate = imageAvailablePredicate;
this.client = checkNotNull(client, "client");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.imageAvailablePredicate = checkNotNull(imageAvailablePredicate, "imageAvailablePredicate");
}
@Override
@ -96,14 +95,14 @@ public class CloudServersImageExtension implements ImageExtension {
CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
final org.jclouds.cloudservers.domain.Image image = client.createImageFromServer(cloneTemplate.getName(),
Integer.parseInt(cloneTemplate.getSourceNodeId()));
return Futures.makeListenable(executor.submit(new Callable<Image>() {
return userExecutor.submit(new Callable<Image>() {
@Override
public Image call() throws Exception {
return Retryables.retryGettingResultOrFailing(imageAvailablePredicate, image.getId(), maxWait, waitPeriod,
TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: " + maxWait
+ " 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 org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Builder;
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;
/**
@ -89,7 +88,7 @@ public class CloudSigmaComputeServiceAdapter implements
private final Predicate<DriveInfo> driveNotClaimed;
private final String defaultVncPassword;
private final LoadingCache<String, DriveInfo> cache;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -98,13 +97,13 @@ public class CloudSigmaComputeServiceAdapter implements
@Inject
public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, Predicate<DriveInfo> driveNotClaimed,
@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.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!");
this.cache = checkNotNull(cache, "cache");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
@ -171,10 +170,10 @@ public class CloudSigmaComputeServiceAdapter implements
@Override
public Iterable<DriveInfo> listImages() {
return FluentIterable.from(transformParallel(client.listStandardDrives(),
new Function<String, Future<? extends DriveInfo>>() {
new Function<String, ListenableFuture<? extends DriveInfo>>() {
@Override
public Future<DriveInfo> apply(String input) {
public ListenableFuture<DriveInfo> apply(String input) {
try {
return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) {
@ -189,7 +188,7 @@ public class CloudSigmaComputeServiceAdapter implements
public String toString() {
return "seedDriveCache()";
}
}, executor, null, logger, "drives")).filter(PREINSTALLED_DISK);
}, userExecutor, null, logger, "drives")).filter(PREINSTALLED_DISK);
}
@SuppressWarnings("unchecked")

View File

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

View File

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

View File

@ -23,8 +23,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -38,6 +36,8 @@ import org.jclouds.ec2.options.DescribeImagesOptions;
import org.jclouds.logging.Logger;
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 final EC2AsyncClient async;
final ExecutorService executor;
final ListeningExecutorService userExecutor;
@Inject
public DescribeImagesParallel(EC2AsyncClient async, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
super();
public DescribeImagesParallel(EC2AsyncClient async, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.async = async;
this.executor = executor;
this.userExecutor = userExecutor;
}
@Override
@ -65,15 +64,11 @@ public class DescribeImagesParallel implements
Iterable<Entry<String, DescribeImagesOptions>> queries) {
return concat(transformParallel(
queries,
new Function<Entry<String, DescribeImagesOptions>, Future<? extends Set<? extends org.jclouds.ec2.domain.Image>>>() {
@Override
public Future<Set<? extends org.jclouds.ec2.domain.Image>> apply(
new Function<Entry<String, DescribeImagesOptions>, ListenableFuture<? extends Set<? extends org.jclouds.ec2.domain.Image>>>() {
public ListenableFuture<Set<? extends org.jclouds.ec2.domain.Image>> apply(
Entry<String, DescribeImagesOptions> from) {
return async.getAMIServices().describeImagesInRegion(from.getKey(), from.getValue());
}
}, executor, null, logger, "amis"));
}, userExecutor, 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.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
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.Maps;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
/**
* creates futures that correlate to
@ -129,7 +129,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
};
@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) {
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 java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Supplier;
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;
/**
@ -70,16 +70,16 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected final EC2AsyncClient client;
protected final Supplier<Set<String>> regions;
protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
protected final ExecutorService executor;
protected final ListeningExecutorService userExecutor;
@Inject
protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.client = checkNotNull(client, "client");
this.regions = checkNotNull(regions, "regions");
this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
@ -97,21 +97,14 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected Iterable<? extends RunningInstance> pollRunningInstances() {
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
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7126754
return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
public ListenableFuture<? extends Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
return client.getInstanceServices().describeInstancesInRegion(from);
}
}, executor, maxTime, logger, "reservations");
}, userExecutor, maxTime, logger, "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 java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Builder;
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;
/**
@ -82,7 +82,7 @@ public class ElasticStackComputeServiceAdapter implements
private final Map<String, WellKnownImage> preinstalledImages;
private final LoadingCache<String, DriveInfo> cache;
private final String defaultVncPassword;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -92,14 +92,14 @@ public class ElasticStackComputeServiceAdapter implements
public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate<DriveInfo> driveNotClaimed,
Map<String, WellKnownImage> preinstalledImages, LoadingCache<String, DriveInfo> cache,
@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.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages");
this.cache = checkNotNull(cache, "cache");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
checkArgument(defaultVncPassword.length() <= 8, "vnc passwords should be less that 8 characters!");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
@ -164,10 +164,10 @@ public class ElasticStackComputeServiceAdapter implements
@Override
public Iterable<DriveInfo> listImages() {
return FluentIterable.from(transformParallel(preinstalledImages.keySet(),
new Function<String, Future<? extends DriveInfo>>() {
new Function<String, ListenableFuture<? extends DriveInfo>>() {
@Override
public Future<? extends DriveInfo> apply(String input) {
public ListenableFuture<? extends DriveInfo> apply(String input) {
try {
return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) {
@ -183,7 +183,7 @@ public class ElasticStackComputeServiceAdapter implements
return "seedDriveCache()";
}
}, executor, null, logger, "drives")).filter(notNull());
}, userExecutor, null, logger, "drives")).filter(notNull());
}
@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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
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.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -104,7 +104,7 @@ public class NovaComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
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, KeyPair> keyPairCache,
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId,
@ -113,7 +113,7 @@ public class NovaComputeService extends BaseComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension);
persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.novaApi = checkNotNull(novaApi, "novaApi");
this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap");
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.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
@ -39,7 +38,6 @@ import org.jclouds.compute.domain.ImageTemplate;
import org.jclouds.compute.domain.ImageTemplateBuilder;
import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.Futures;
import org.jclouds.logging.Logger;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.Server;
@ -48,6 +46,7 @@ import org.jclouds.predicates.PredicateWithResult;
import org.jclouds.predicates.Retryables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* Nova implementation of {@link ImageExtension}
@ -63,7 +62,7 @@ public class NovaImageExtension implements ImageExtension {
protected Logger logger = Logger.NULL;
private final NovaApi novaApi;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@com.google.inject.Inject(optional = true)
@Named("IMAGE_MAX_WAIT")
private long maxWait = 3600;
@ -74,10 +73,10 @@ public class NovaImageExtension implements ImageExtension {
@Inject
public NovaImageExtension(NovaApi novaApi,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
PredicateWithResult<ZoneAndId, Image> imageReadyPredicate) {
this.novaApi = checkNotNull(novaApi);
this.executor = userThreads;
this.userExecutor = userExecutor;
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);
return Futures.makeListenable(executor.submit(new Callable<Image>() {
return userExecutor.submit(new Callable<Image>() {
@Override
public Image call() throws Exception {
return Retryables.retryGettingResultOrFailing(imageReadyPredicate, targetImageZoneAndId, maxWait,
waitPeriod, TimeUnit.SECONDS, "Image was not created within the time limit, Giving up! [Limit: "
+ maxWait + " secs.]");
}
}), executor);
});
}
@Override

View File

@ -26,8 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
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.ListNodesStrategy;
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.compute.functions.AllocateAndAddFloatingIpToNode;
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.collect.Multimap;
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,
GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode,
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaApi novaApi) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
@ -90,7 +90,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
}
@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) {
Template mutableTemplate = template.clone();
@ -149,14 +149,14 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
}
@Override
protected Future<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group,
protected ListenableFuture<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group,
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());
if (templateOptions.shouldAutoAssignFloatingIp()) {
return Futures.compose(future, createAndAddFloatingIpToNode, executor);
return Futures.transform(future, createAndAddFloatingIpToNode, userExecutor);
} else {
return future;
}

View File

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

View File

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

View File

@ -19,9 +19,9 @@
package org.jclouds.s3.blobstore;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions;
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.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
*
@ -91,14 +91,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
@Inject
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,
Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, AccessControlList> bucketAcls) {
super(context, blobUtils, service, defaultLocation, locations);
super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.async = checkNotNull(async, "async");
this.sync = checkNotNull(sync, "sync");
@ -117,12 +117,12 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(Set<BucketMetadata> from) {
return convertBucketsToStorageMetadata.apply(from);
}
}, service);
}, userExecutor);
}
/**
@ -156,14 +156,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
* bucket name
*/
@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) {
ListBucketOptions httpOptions = container2BucketListOptions.apply(options);
ListenableFuture<ListBucketResponse> returnVal = async.listBucket(container, httpOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, bucket2ResourceList,
service);
return (options.isDetailed()) ? Futures.compose(list,
fetchBlobMetadataProvider.get().setContainerName(container), service) : list;
ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, bucket2ResourceList,
userExecutor);
return (options.isDetailed()) ? transform(list,
fetchBlobMetadataProvider.get().setContainerName(container), userExecutor) : list;
}
/**
@ -196,14 +196,14 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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
public BlobMetadata apply(ObjectMetadata from) {
return object2BlobMd.apply(from);
}
}, service);
}, userExecutor);
}
/**
@ -217,7 +217,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
@Override
public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions 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.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -39,6 +37,8 @@ import org.jclouds.logging.Logger;
import org.jclouds.s3.domain.BucketMetadata;
import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@Singleton
public class BucketsToStorageMetadata implements
@ -47,11 +47,11 @@ public class BucketsToStorageMetadata implements
@Resource
protected Logger logger = Logger.NULL;
private final ExecutorService userExecutor;
private final ListeningExecutorService userExecutor;
private final BucketToResourceMetadata bucket2ResourceMd;
@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.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd");
}
@ -62,9 +62,9 @@ public class BucketsToStorageMetadata implements
// parallel as listing buckets is slow when looking up regions
Iterable<? extends StorageMetadata> buckets = FutureIterables
.<BucketMetadata, StorageMetadata> transformParallel(input,
new Function<BucketMetadata, Future<? extends StorageMetadata>>() {
new Function<BucketMetadata, ListenableFuture<? extends StorageMetadata>>() {
@Override
public Future<? extends StorageMetadata> apply(final BucketMetadata from) {
public ListenableFuture<? extends StorageMetadata> apply(final BucketMetadata from) {
return userExecutor.submit(new Callable<StorageMetadata>() {
@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.util.List;
import javax.inject.Inject;
import javax.inject.Named;
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.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.util.AWSUtils;
@ -40,6 +39,9 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.s3.S3ApiMetadata;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
/**
* @author Adrian Cole
*

View File

@ -23,6 +23,7 @@ import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.util.SaxUtils.currentOrNull;
import java.util.regex.Pattern;
import javax.inject.Inject;
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.ReturnTrueIf2xx;
import org.jclouds.http.options.GetOptions;
import com.google.common.reflect.Invokable;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.GeneratedHttpRequest;
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.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.reflect.Invokable;
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.http.HttpResponseException;
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.EmailAddressGrantee;
import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI;
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.util.Strings2;
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.util.concurrent.Futures.immediateFailedFuture;
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.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -44,7 +44,6 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.util.BlobStoreUtils;
import org.jclouds.concurrent.Futures;
import org.jclouds.date.DateService;
import org.jclouds.domain.Location;
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.Sets;
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.
@ -99,17 +99,17 @@ public class StubS3AsyncClient implements S3AsyncClient {
private final ResourceToBucketList resource2BucketList;
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs;
private final ConcurrentMap<String, Location> containerToLocation;
private final ExecutorService service;
private final ListeningExecutorService userExecutor;
@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,
ConcurrentMap<String, Location> containerToLocation, DateService dateService,
S3Object.Factory objectProvider, Blob.Factory blobProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
BlobToObjectMetadata blob2ObjectMetadata, BucketToContainerListOptions bucket2ContainerListOptions,
ResourceToBucketList resource2BucketList) {
this.service = service;
this.userExecutor = userExecutor;
this.containerToBlobs = containerToBlobs;
this.containerToLocation = containerToLocation;
this.blobStore = blobStore;
@ -146,7 +146,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
public ListenableFuture<ListBucketResponse> listBucket(final String name, ListBucketOptions... 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,
@ -274,16 +274,15 @@ public class StubS3AsyncClient implements S3AsyncClient {
public ListenableFuture<S3Object> getObject(final String bucketName, final String key, final GetOptions... 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) {
return Futures.compose(blobStore.blobMetadata(bucketName, key), new Function<BlobMetadata, ObjectMetadata>() {
@Override
return transform(blobStore.blobMetadata(bucketName, key), new Function<BlobMetadata, ObjectMetadata>() {
public ObjectMetadata apply(BlobMetadata from) {
return blob2ObjectMetadata.apply(from);
}
}, service);
}, userExecutor);
}
public ListenableFuture<? extends Set<BucketMetadata>> listOwnedBuckets() {

View File

@ -19,10 +19,10 @@
package org.jclouds.openstack.swift.blobstore;
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 java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions;
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.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
*
@ -86,7 +86,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
@Inject
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,
CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -94,7 +94,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations);
super(context, blobUtils, userExecutor, defaultLocation, locations);
this.sync = sync;
this.async = async;
this.container2ResourceMd = container2ResourceMd;
@ -113,13 +113,13 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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>>() {
public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply(
Set<ContainerMetadata> from) {
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
.apply(options);
ListenableFuture<PageSet<ObjectInfo>> returnVal = async.listObjects(container, httpOptions);
ListenableFuture<PageSet<? extends StorageMetadata>> list = Futures.compose(returnVal, container2ResourceList,
service);
return options.isDetailed() ? Futures.compose(list, fetchBlobMetadataProvider.get().setContainerName(container),
service) : list;
ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, container2ResourceList,
userExecutor);
return options.isDetailed() ? transform(list, fetchBlobMetadataProvider.get().setContainerName(container),
userExecutor) : list;
}
/**
@ -181,7 +181,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
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>() {
@Override
@ -189,7 +189,7 @@ public class SwiftAsyncBlobStore extends BaseAsyncBlobStore {
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) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
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;
import com.google.common.annotations.VisibleForTesting;
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 static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Named;
import java.util.Map;
import java.util.Queue;
import java.util.SortedMap;
@ -33,11 +13,32 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
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 {
@Resource
@ -74,17 +75,17 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@Named(Constants.PROPERTY_REQUEST_TIMEOUT)
protected Long maxTime;
private final ExecutorService ioWorkerExecutor;
private final ListeningExecutorService ioExecutor;
protected final SwiftAsyncBlobStore ablobstore;
protected final PayloadSlicer slicer;
@Inject
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.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();
}
}
}, ioWorkerExecutor);
}, ioExecutor);
futureParts.put(part, futureETag);
}
@Override
public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options, final BlobToObject blob2Object) {
return Futures.makeListenable(
ioWorkerExecutor.submit(new Callable<String>() {
return ioExecutor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
String key = blob.getMetadata().getName();
@ -235,7 +235,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get();
}
}
}), ioWorkerExecutor);
});
}
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.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.Futures.transform;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -39,7 +39,6 @@ import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
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.Sets;
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.
@ -76,16 +76,16 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
private final ResourceToObjectInfo blob2ObjectInfo;
private final ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions;
private final ResourceToObjectList resource2ObjectList;
private final ExecutorService service;
private final ListeningExecutorService userExecutor;
@Inject
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
LocalAsyncBlobStore blobStore,
SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo,
ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions,
ResourceToObjectList resource2ContainerList) {
this.service = service;
this.userExecutor = userExecutor;
this.blobStore = blobStore;
this.objectProvider = objectProvider;
this.httpGetOptionsConverter = httpGetOptionsConverter;
@ -127,11 +127,11 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
public ListenableFuture<SwiftObject> getObject(String container, String key, GetOptions... 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) {
return Futures.compose(blobStore.blobMetadata(container, key),
return transform(blobStore.blobMetadata(container, key),
new Function<BlobMetadata, MutableObjectInfoWithMetadata>() {
@Override
@ -140,7 +140,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
return blob2ObjectInfo.apply(from);
}
}, service);
}, userExecutor);
}
public ListenableFuture<? extends Set<ContainerMetadata>> listContainers(
@ -181,7 +181,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
public ListenableFuture<PageSet<ObjectInfo>> listObjects(String container,
org.jclouds.openstack.swift.options.ListContainerOptions... 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) {

View File

@ -21,9 +21,6 @@ package org.jclouds.vcloud.functions;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -49,27 +48,25 @@ public class CatalogItemsInCatalog implements Function<Catalog, Iterable<Catalog
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<CatalogItem> apply(Catalog from) {
return transformParallel(filter(from.values(), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) {
return input.getType().equals(VCloudMediaType.CATALOGITEM_XML);
}
}), new Function<ReferenceType, Future<? extends CatalogItem>>() {
@Override
public Future<CatalogItem> apply(ReferenceType from) {
}), new Function<ReferenceType, ListenableFuture<? extends CatalogItem>>() {
public ListenableFuture<CatalogItem> apply(ReferenceType from) {
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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -46,21 +45,20 @@ public class CatalogsInOrg implements Function<Org, Iterable<Catalog>> {
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<Catalog> apply(final Org org) {
return transformParallel(org.getCatalogs().values(), new Function<ReferenceType, Future<? extends Catalog>>() {
@Override
public Future<Catalog> apply(ReferenceType from) {
return transformParallel(org.getCatalogs().values(), new Function<ReferenceType, ListenableFuture<? extends Catalog>>() {
public ListenableFuture<Catalog> apply(ReferenceType from) {
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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -46,22 +45,21 @@ public class NetworksInOrg implements Function<Org, Iterable<OrgNetwork>> {
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<OrgNetwork> apply(final Org org) {
return transformParallel(org.getNetworks().values(), new Function<ReferenceType, Future<? extends OrgNetwork>>() {
@Override
public Future<? extends OrgNetwork> apply(ReferenceType from) {
return transformParallel(org.getNetworks().values(), new Function<ReferenceType, ListenableFuture<? extends OrgNetwork>>() {
public ListenableFuture<? extends OrgNetwork> apply(ReferenceType from) {
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 java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -48,12 +48,12 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<O
@Resource
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
/**
@ -63,22 +63,19 @@ public class OrgsForLocations implements Function<Iterable<Location>, Iterable<O
@Override
public Iterable<Org> apply(Iterable<Location> from) {
FluentIterable<URI> uris = FluentIterable.from(from).filter(new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE;
}
}).transform(new Function<Location, URI>() {
@Override
public URI apply(Location from) {
return URI.create(from.getParent().getId());
}
});
return transformParallel(uris, new Function<URI, Future<? extends Org>>() {
@Override
public Future<Org> apply(URI from) {
return transformParallel(uris, new Function<URI, ListenableFuture<? extends Org>>() {
public ListenableFuture<Org> apply(URI 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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -45,24 +44,21 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<Org>> {
@Resource
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<Org> apply(Iterable<String> from) {
return Iterables.filter(transformParallel(from, new Function<String, Future<? extends Org>>() {
@Override
public Future<Org> apply(String from) {
return Iterables.filter(transformParallel(from, new Function<String, ListenableFuture<? extends Org>>() {
public ListenableFuture<Org> apply(String from) {
return aclient.getOrgClient().findOrgNamed(from);
}
}, executor, null, logger, "organizations for names"), Predicates.notNull());
}, userExecutor, 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.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Predicate;
import com.google.common.base.Predicates;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -50,32 +49,26 @@ public class VAppTemplatesForCatalogItems implements Function<Iterable<CatalogIt
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
private Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, @Named(PROPERTY_USER_THREADS) ExecutorService executor) {
VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, @Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient;
this.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<VAppTemplate> apply(Iterable<CatalogItem> from) {
return filter(transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override
public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
}
}), new Function<CatalogItem, Future<? extends VAppTemplate>>() {
@Override
public Future<VAppTemplate> apply(CatalogItem from) {
}), new Function<CatalogItem, ListenableFuture<? extends VAppTemplate>>() {
public ListenableFuture<VAppTemplate> apply(CatalogItem from) {
return aclient.getVAppTemplateClient().getVAppTemplate(from.getEntity().getHref());
}
}, executor, null, logger, "vappTemplates in"), Predicates.notNull());
}, userExecutor, 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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
@ -36,6 +33,8 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -46,23 +45,21 @@ public class VDCsInOrg implements Function<Org, Iterable<VDC>> {
public Logger logger = Logger.NULL;
private final VCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<VDC> apply(final Org org) {
return transformParallel(org.getVDCs().values(), new Function<ReferenceType, Future<? extends VDC>>() {
@Override
public Future<? extends VDC> apply(ReferenceType from) {
return transformParallel(org.getVDCs().values(), new Function<ReferenceType, ListenableFuture<? extends VDC>>() {
public ListenableFuture<? extends VDC> apply(ReferenceType from) {
return aclient.getVDCClient().getVDC(from.getHref());
}
}, executor, null, logger, "vdcs in org " + org.getName());
}, userExecutor, 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.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -55,41 +55,34 @@ public class VAppTemplatesSupplier implements Supplier<Set<VAppTemplate>> {
private final Supplier<Map<String, Org>> orgMap;
private final Function<Org, Iterable<VAppTemplate>> imagesInOrg;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VAppTemplatesSupplier(Supplier<Map<String, Org>> orgMap,
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.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Set<VAppTemplate> get() {
Iterable<Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<? extends Iterable<VAppTemplate>> images = transformParallel(orgs,
new Function<Org, Future<? extends Iterable<VAppTemplate>>>() {
@Override
public Future<Iterable<VAppTemplate>> apply(final Org from) {
new Function<Org, ListenableFuture<? extends Iterable<VAppTemplate>>>() {
public ListenableFuture<Iterable<VAppTemplate>> apply(final Org from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<VAppTemplate>>() {
@Override
return userExecutor.submit(new Callable<Iterable<VAppTemplate>>() {
public Iterable<VAppTemplate> call() throws Exception {
return imagesInOrg.apply(from);
}
@Override
public String toString() {
return "imagesInOrg(" + from.getHref() + ")";
}
});
}
}, executor, null, logger, "images in " + orgs);
}, userExecutor, null, logger, "images in " + orgs);
return newLinkedHashSet(concat(images));
}
}

View File

@ -36,7 +36,6 @@ import java.io.IOException;
import java.util.Date;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutorService;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -80,6 +79,7 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* Implementation of {@link BaseAsyncBlobStore} which uses a pluggable
@ -103,13 +103,13 @@ public class LocalAsyncBlobStore extends BaseAsyncBlobStore {
@Inject
protected LocalAsyncBlobStore(BlobStoreContext context,
BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations,
ContentMetadataCodec contentMetadataCodec,
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
Factory blobFactory, LocalStorageStrategy storageStrategy) {
super(context, blobUtils, service, defaultLocation, locations);
super(context, blobUtils, userExecutor, defaultLocation, locations);
this.blobFactory = blobFactory;
this.contentMetadataCodec = contentMetadataCodec;
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.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -48,6 +47,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.Futures;
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 BlobUtils blobUtils;
protected final ExecutorService service;
protected final ListeningExecutorService userExecutor;
protected final Supplier<Location> defaultLocation;
protected final Supplier<Set<? extends Location>> locations;
@Inject
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) {
this.context = checkNotNull(context, "context");
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
this.service = checkNotNull(service, "service");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.locations = checkNotNull(locations, "locations");
}
@ -117,7 +117,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/
@Override
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 {
return blobUtils.countBlobs(containerName, options);
}
@ -126,7 +126,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
return "countBlobs(" + containerName + ")";
}
}), service);
});
}
/**
@ -149,7 +149,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/
@Override
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 {
blobUtils.clearContainer(containerName, options);
@ -160,7 +160,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
return "clearContainer(" + containerName + ")";
}
}), service);
});
}
/**
@ -171,7 +171,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/
@Override
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 {
blobUtils.deleteDirectory(containerName, directory);
@ -182,7 +182,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
return "deleteDirectory(" + containerName + "," + directory + ")";
}
}), service);
});
}
/**
@ -194,7 +194,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
* virtual path
*/
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 {
return blobUtils.directoryExists(containerName, directory);
@ -204,7 +204,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
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) {
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 {
blobUtils.createDirectory(containerName, directory);
return null;
@ -229,7 +228,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
return "createDirectory(" + containerName + "," + directory + ")";
}
}), service);
});
}
/**
@ -254,7 +253,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
*/
@Override
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 {
deletePathAndEnsureGone(container);
@ -265,7 +264,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
public String toString() {
return "deleteContainer(" + container + ")";
}
}), service);
});
}
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.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.TimeoutException;
import javax.annotation.Resource;
import javax.inject.Named;
@ -46,6 +44,8 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.logging.Logger;
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;
/**
@ -60,7 +60,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected Logger logger = Logger.NULL;
protected final BackoffLimitedRetryHandler retryHandler;
private final ExecutorService userExecutor;
private final ListeningExecutorService userExecutor;
protected final AsyncBlobStore connection;
/** Maximum duration in milliseconds of a request. */
@ -69,10 +69,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
protected Long maxTime = Long.MAX_VALUE;
@Inject
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
AsyncBlobStore connection,
BackoffLimitedRetryHandler retryHandler) {
DeleteAllKeysInList(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore connection, BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor;
this.connection = connection;
this.retryHandler = retryHandler;
@ -95,7 +93,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
for (int numErrors = 0; numErrors < maxErrors; ) {
// fetch partial directory listing
PageSet<? extends StorageMetadata> listing;
Future<PageSet<? extends StorageMetadata>> listFuture =
ListenableFuture<PageSet<? extends StorageMetadata>> listFuture =
connection.list(containerName, options);
try {
listing = listFuture.get(maxTime, TimeUnit.MILLISECONDS);
@ -141,7 +139,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
}
// remove blobs and now-empty subdirectories
Map<StorageMetadata, Future<?>> responses = Maps.newHashMap();
Map<StorageMetadata, ListenableFuture<?>> responses = Maps.newHashMap();
for (StorageMetadata md : listing) {
String fullPath = parentIsFolder(options, md) ? options.getDir() + "/"
+ md.getName() : md.getName();
@ -174,7 +172,7 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
continue;
} finally {
for (Future<?> future : responses.values()) {
for (ListenableFuture<?> future : responses.values()) {
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 org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
@ -43,6 +40,8 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
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;
/**
@ -55,7 +54,7 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
protected final BackoffLimitedRetryHandler retryHandler;
protected final AsyncBlobStore ablobstore;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL;
@ -69,7 +68,7 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
protected Long maxTime;
@Inject
FetchBlobMetadata(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, AsyncBlobStore ablobstore,
FetchBlobMetadata(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, AsyncBlobStore ablobstore,
BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor;
this.ablobstore = ablobstore;
@ -91,10 +90,10 @@ public class FetchBlobMetadata implements Function<PageSet<? extends StorageMeta
return input.getType() == StorageType.BLOB;
}
}), new Function<StorageMetadata, Future<? extends BlobMetadata>>() {
}), new Function<StorageMetadata, ListenableFuture<? extends BlobMetadata>>() {
@Override
public Future<BlobMetadata> apply(StorageMetadata from) {
public ListenableFuture<BlobMetadata> apply(StorageMetadata from) {
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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
@ -39,6 +36,8 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.logging.Logger;
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;
/**
@ -53,7 +52,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
protected final ListBlobsInContainer getAllBlobMetadata;
protected final BackoffLimitedRetryHandler retryHandler;
protected final AsyncBlobStore ablobstore;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL;
@ -65,7 +64,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
protected Long maxTime;
@Inject
GetAllBlobsInListAndRetryOnFailure(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
GetAllBlobsInListAndRetryOnFailure(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
ListBlobsInContainer getAllBlobMetadata, AsyncBlobStore ablobstore, BackoffLimitedRetryHandler retryHandler) {
this.userExecutor = userExecutor;
this.ablobstore = ablobstore;
@ -75,10 +74,10 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
public Iterable<Blob> execute(final String container, ListContainerOptions 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
public Future<Blob> apply(BlobMetadata from) {
public ListenableFuture<Blob> apply(BlobMetadata from) {
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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import javax.annotation.Resource;
@ -41,6 +39,8 @@ import org.jclouds.logging.Logger;
import com.google.common.collect.Maps;
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;
/**
@ -68,7 +68,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
private final AsyncBlobStore ablobstore;
private final BlobStore blobstore;
private final ExecutorService userExecutor;
private final ListeningExecutorService userExecutor;
@Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL;
@ -81,7 +81,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
@Inject
MarkersDeleteDirectoryStrategy(
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore ablobstore, BlobStore blobstore) {
this.userExecutor = userExecutor;
this.ablobstore = ablobstore;
@ -94,7 +94,7 @@ public class MarkersDeleteDirectoryStrategy implements DeleteDirectoryStrategy {
for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) {
names.add(directory + suffix);
}
Map<String, Future<?>> responses = Maps.newHashMap();
Map<String, ListenableFuture<?>> responses = Maps.newHashMap();
for (String name : names) {
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 java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import javax.annotation.Resource;
@ -39,6 +37,8 @@ import org.jclouds.blobstore.strategy.PutBlobsStrategy;
import org.jclouds.logging.Logger;
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;
/**
@ -49,7 +49,7 @@ import com.google.inject.Inject;
public class PutBlobsStrategyImpl implements PutBlobsStrategy {
private final AsyncBlobStore ablobstore;
private final ExecutorService userExecutor;
private final ListeningExecutorService userExecutor;
@Resource
@Named(BlobStoreConstants.BLOBSTORE_LOGGER)
protected Logger logger = Logger.NULL;
@ -61,7 +61,7 @@ public class PutBlobsStrategyImpl implements PutBlobsStrategy {
protected Long maxTime;
@Inject
PutBlobsStrategyImpl(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
PutBlobsStrategyImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
AsyncBlobStore ablobstore) {
this.userExecutor = userExecutor;
this.ablobstore = ablobstore;
@ -69,7 +69,7 @@ public class PutBlobsStrategyImpl implements PutBlobsStrategy {
@Override
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) {
responses.put(blob, ablobstore.putBlob(containerName, blob));
}

View File

@ -43,7 +43,6 @@ import java.util.Date;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
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.StorageMetadata;
import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.concurrent.Futures;
import org.jclouds.crypto.Crypto;
import org.jclouds.encryption.internal.JCECrypto;
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.Files;
import com.google.common.io.InputSupplier;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
/**
* @author Adrian Cole
@ -139,7 +139,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
final AtomicInteger blobCount = new AtomicInteger();
final String container = getContainerName();
try {
Map<Integer, Future<?>> responses = Maps.newHashMap();
Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
for (int i = 0; i < 10; i++) {
responses.put(i, this.exec.submit(new Callable<Void>() {
@ -179,10 +179,10 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
final String name = "constitution.txt";
uploadConstitution(container, name, expectedContentDisposition);
Map<Integer, Future<?>> responses = Maps.newHashMap();
Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
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>() {
@Override

View File

@ -32,7 +32,6 @@ import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
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.Sets;
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;
public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreContext> {
@ -106,7 +107,7 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
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
@ -116,7 +117,7 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
*/
@BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext")
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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
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.Predicate;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -85,13 +85,13 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
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) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension);
persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.cleanupOrphanKeys = cleanupOrphanKeys;
}

View File

@ -21,8 +21,6 @@ package org.jclouds.trmk.vcloud_0_8.compute.strategy;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.inject.Named;
@ -41,6 +39,8 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
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
@ -58,15 +58,15 @@ public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends Creat
ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise;
}
@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) {
assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: "
+ template.getLocation();

View File

@ -26,8 +26,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @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 Function<Org, Iterable<? extends Hardware>> sizesInOrg;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VCloudHardwareSupplier(Supplier<Map<String, ? extends Org>> orgMap,
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.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Set<? extends Hardware> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "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
public Future<Iterable<? extends Hardware>> apply(final Org from) {
public ListenableFuture<Iterable<? extends Hardware>> apply(final Org from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Hardware>>() {
return userExecutor.submit(new Callable<Iterable<? extends Hardware>>() {
@Override
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));
}
}

View File

@ -26,8 +26,6 @@ import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @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 Function<Org, Iterable<? extends Image>> imagesInOrg;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap,
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.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Set<? extends Image> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "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
public Future<Iterable<? extends Image>> apply(final Org from) {
public ListenableFuture<Iterable<? extends Image>> apply(final Org from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Image>>() {
return userExecutor.submit(new Callable<Iterable<? extends Image>>() {
@Override
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));
}
}

View File

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

View File

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

View File

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

View File

@ -23,8 +23,6 @@ import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Predicate;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -50,12 +50,12 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
@Resource
public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
/**
@ -64,28 +64,18 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
*/
@Override
public Iterable<? extends Org> apply(Iterable<? extends Location> from) {
return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE;
}
}), new Function<Location, URI>() {
@Override
public URI apply(Location from) {
return URI.create(from.getParent().getId());
}
})), new Function<URI, Future<? extends Org>>() {
@Override
public Future<? extends Org> apply(URI from) {
})), new Function<URI, ListenableFuture<? extends Org>>() {
public ListenableFuture<? extends Org> apply(URI from) {
return aclient.getOrg(from);
}
}, executor, null, logger, "organizations for uris");
}, userExecutor, 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 java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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 com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -43,23 +42,21 @@ public class OrgsForNames implements Function<Iterable<String>, Iterable<? exten
@Resource
public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@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.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<? extends Org> apply(Iterable<String> from) {
return transformParallel(from, new Function<String, Future<? extends Org>>() {
@Override
public Future<? extends Org> apply(String from) {
return transformParallel(from, new Function<String, ListenableFuture<? extends Org>>() {
public ListenableFuture<? extends Org> apply(String from) {
return aclient.findOrgNamed(from);
}
}, executor, null, logger, "organizations for names");
}, userExecutor, 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 org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -50,31 +49,26 @@ public class VAppTemplatesForCatalogItems implements
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VAppTemplatesForCatalogItems(TerremarkVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient;
this.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<? extends VAppTemplate> apply(Iterable<? extends CatalogItem> from) {
return transformParallel(filter(from, new Predicate<CatalogItem>() {
@Override
public boolean apply(CatalogItem input) {
return input.getEntity().getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
}
}), new Function<CatalogItem, Future<? extends VAppTemplate>>() {
@Override
public Future<? extends VAppTemplate> apply(CatalogItem from) {
}), new Function<CatalogItem, ListenableFuture<? extends VAppTemplate>>() {
public ListenableFuture<? extends VAppTemplate> apply(CatalogItem from) {
return aclient.getVAppTemplate(from.getEntity().getHref());
}
}, executor, null, logger, "vappTemplates in");
}, userExecutor, 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 org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
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.Predicate;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -51,31 +50,26 @@ public class VAppTemplatesForResourceEntities implements
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final TerremarkVCloudAsyncClient aclient;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
VAppTemplatesForResourceEntities(TerremarkVCloudAsyncClient aclient,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.aclient = aclient;
this.executor = executor;
this.userExecutor = userExecutor;
}
@Override
public Iterable<? extends VAppTemplate> apply(Iterable<? extends ReferenceType> from) {
return transformParallel(filter(checkNotNull(from, "named resources"), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) {
return input.getType().equals(TerremarkVCloudMediaType.VAPPTEMPLATE_XML);
}
}), new Function<ReferenceType, Future<? extends VAppTemplate>>() {
@Override
public Future<? extends VAppTemplate> apply(ReferenceType from) {
}), new Function<ReferenceType, ListenableFuture<? extends VAppTemplate>>() {
public ListenableFuture<? extends VAppTemplate> apply(ReferenceType from) {
return aclient.getVAppTemplate(from.getHref());
}
}, executor, null, logger, "vappTemplates in");
}, userExecutor, 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.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -36,6 +35,7 @@ import org.jclouds.compute.events.StatementOnNodeFailure;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.scriptbuilder.InitScript;
import com.google.common.annotations.VisibleForTesting;
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.primitives.Ints;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
@ -63,7 +64,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final ExecutorService userThreads;
private final ListeningExecutorService userExecutor;
private final EventBus eventBus;
private final SudoAwareInitManager commandRunner;
@ -75,19 +76,19 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
@Inject
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) {
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
notRunningAnymore = new LoopUntilTrueOrThrowCancellationException(new ExitStatusOfCommandGreaterThanZero(
commandRunner), properties.initStatusMaxPeriod, properties.initStatusInitialPeriod, this);
}
@VisibleForTesting
public BlockUntilInitScriptStatusIsZeroThenReturnOutput(ExecutorService userThreads, EventBus eventBus,
public BlockUntilInitScriptStatusIsZeroThenReturnOutput(ListeningExecutorService userExecutor, EventBus eventBus,
Predicate<String> notRunningAnymore, SudoAwareInitManager commandRunner) {
this.commandRunner = checkNotNull(commandRunner, "commandRunner");
this.userThreads = checkNotNull(userThreads, "userThreads");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.eventBus = checkNotNull(eventBus, "eventBus");
this.notRunningAnymore = checkNotNull(notRunningAnymore, "notRunningAnymore");
}
@ -136,7 +137,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
* place
*/
public BlockUntilInitScriptStatusIsZeroThenReturnOutput init() {
userThreads.submit(this);
userExecutor.submit(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.collect.Iterables.filter;
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.util.concurrent.Futures.immediateFuture;
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.Set;
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.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
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.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.extensions.ImageExtension;
import org.jclouds.compute.options.RunScriptOptions;
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.util.concurrent.Atomics;
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 PersistNodeCredentials persistNodeCredentials;
private final RunScriptOnNode.Factory runScriptOnNodeFactory;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
private final Optional<ImageExtension> imageExtension;
@Inject
@ -161,7 +159,7 @@ public class BaseComputeService implements ComputeService {
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
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) {
this.context = checkNotNull(context, "context");
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
@ -186,8 +184,8 @@ public class BaseComputeService implements ComputeService {
this.initAdminAccess = checkNotNull(initAdminAccess, "initAdminAccess");
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
this.persistNodeCredentials = checkNotNull(persistNodeCredentials, "persistNodeCredentials");
this.executor = checkNotNull(executor, "executor");
this.imageExtension = imageExtension;
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.imageExtension = checkNotNull(imageExtension, "imageExtension");
}
/**
@ -213,11 +211,11 @@ public class BaseComputeService implements ComputeService {
if (template.getOptions().getRunScript() != null)
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);
Map<?, Exception> executionExceptions;
try {
executionExceptions = awaitCompletion(responses, executor, null, logger, "createNodesInGroup(" + group + ")");
executionExceptions = awaitCompletion(responses, userExecutor, null, logger, "createNodesInGroup(" + group + ")");
} catch (TimeoutException te) {
throw propagate(te);
}
@ -257,29 +255,24 @@ public class BaseComputeService implements ComputeService {
@Override
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> destroying nodes matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(filter(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, Future<? extends NodeMetadata>>() {
Set<NodeMetadata> set = ImmutableSet.copyOf(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
new Function<NodeMetadata, ListenableFuture<? extends NodeMetadata>>() {
// TODO make an async interface instead of re-wrapping
@Override
public Future<NodeMetadata> apply(final NodeMetadata from) {
return executor.submit(new Callable<NodeMetadata>() {
@Nullable
@Override
public ListenableFuture<NodeMetadata> apply(final NodeMetadata from) {
return userExecutor.submit(new Callable<NodeMetadata>() {
public NodeMetadata call() throws Exception {
doDestroyNode(from.getId());
return from;
}
@Override
public String toString() {
return "destroyNode(" + from.getId() + ")";
}
});
}
}, executor, null, logger, "destroyNodesMatching(" + filter + ")"), notNull()));
}, userExecutor, null, logger, "destroyNodesMatching(" + filter + ")"));
logger.debug("<< destroyed(%d)", set.size());
cleanUpIncidentalResourcesOfDeadNodes(set);
@ -432,15 +425,15 @@ public class BaseComputeService implements ComputeService {
public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> rebooting nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() {
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
@Override
public Future<Void> apply(NodeMetadata from) {
public ListenableFuture<Void> apply(NodeMetadata from) {
rebootNode(from.getId());
return immediateFuture(null);
}
}, executor, null, logger, "rebootNodesMatching(" + filter + ")");
}, userExecutor, null, logger, "rebootNodesMatching(" + filter + ")");
logger.debug("<< rebooted");
}
@ -463,15 +456,15 @@ public class BaseComputeService implements ComputeService {
public void resumeNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> resuming nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() {
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
@Override
public Future<Void> apply(NodeMetadata from) {
public ListenableFuture<Void> apply(NodeMetadata from) {
resumeNode(from.getId());
return immediateFuture(null);
}
}, executor, null, logger, "resumeNodesMatching(" + filter + ")");
}, userExecutor, null, logger, "resumeNodesMatching(" + filter + ")");
logger.debug("<< resumed");
}
@ -494,15 +487,15 @@ public class BaseComputeService implements ComputeService {
public void suspendNodesMatching(Predicate<NodeMetadata> filter) {
logger.debug(">> suspending nodes matching(%s)", filter);
transformParallel(nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter),
new Function<NodeMetadata, Future<? extends Void>>() {
new Function<NodeMetadata, ListenableFuture<? extends Void>>() {
// TODO use native async
@Override
public Future<Void> apply(NodeMetadata from) {
public ListenableFuture<Void> apply(NodeMetadata from) {
suspendNode(from.getId());
return immediateFuture(null);
}
}, executor, null, logger, "suspendNodesMatching(" + filter + ")");
}, userExecutor, null, logger, "suspendNodesMatching(" + filter + ")");
logger.debug("<< suspended");
}
@ -543,7 +536,7 @@ public class BaseComputeService implements ComputeService {
Map<NodeMetadata, ExecResponse> goodNodes = 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();
initAdminAccess.visit(runScript);
@ -552,11 +545,11 @@ public class BaseComputeService implements ComputeService {
nodesMatchingFilterAndNotTerminatedExceptionIfNotFound(filter), runScript, options, badNodes);
if (Iterables.size(scriptRunners) > 0) {
for (RunScriptOnNode runner : scriptRunners) {
responses.put(runner.getNode(), executor.submit(new RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
responses.put(runner.getNode(), userExecutor.submit(new RunScriptOnNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
runner, goodNodes, badNodes)));
}
try {
exceptions = awaitCompletion(responses, executor, null, logger, "runScriptOnNodesMatching(" + filter + ")");
exceptions = awaitCompletion(responses, userExecutor, null, logger, "runScriptOnNodesMatching(" + filter + ")");
} catch (TimeoutException te) {
throw propagate(te);
}
@ -638,22 +631,18 @@ public class BaseComputeService implements ComputeService {
final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options);
ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options);
response.addListener(new Runnable() {
@Override
public void run() {
persistNodeCredentials.ifAdminAccess(runScript).apply(node1);
}
}, executor);
}, userExecutor);
return response;
}
private Iterable<? extends RunScriptOnNode> transformNodesIntoInitializedScriptRunners(
private Iterable<RunScriptOnNode> transformNodesIntoInitializedScriptRunners(
Iterable<? extends NodeMetadata> nodes, Statement script, RunScriptOptions options,
Map<NodeMetadata, Exception> badNodes) {
return filter(
transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes),
executor, null, logger, "initialize script runners"), notNull());
return filter(transformParallel(nodes, new TransformNodesIntoInitializedScriptRunners(script, options, badNodes),
userExecutor, null, logger, "initialize script runners"), notNull());
}
private Set<? extends NodeMetadata> detailsOnAllNodes() {
@ -690,7 +679,7 @@ public class BaseComputeService implements ComputeService {
}
private final class TransformNodesIntoInitializedScriptRunners implements
Function<NodeMetadata, Future<? extends RunScriptOnNode>> {
Function<NodeMetadata, ListenableFuture<? extends RunScriptOnNode>> {
private final Map<NodeMetadata, Exception> badNodes;
private final Statement script;
private final RunScriptOptions options;
@ -703,9 +692,9 @@ public class BaseComputeService implements ComputeService {
}
@Override
public Future<RunScriptOnNode> apply(NodeMetadata node) {
public ListenableFuture<RunScriptOnNode> apply(NodeMetadata node) {
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;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.inject.Named;
import javax.inject.Singleton;
@ -40,6 +39,7 @@ import org.jclouds.xml.XMLParser;
import com.google.common.base.Function;
import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject;
import com.google.inject.Injector;
@ -55,11 +55,11 @@ public class UtilsImpl extends org.jclouds.rest.internal.UtilsImpl implements Ut
@Inject
UtilsImpl(Injector injector, Json json, XMLParser xml, HttpClient simpleClient, HttpAsyncClient simpleAsyncClient,
Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, EventBus eventBus,
Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor, EventBus eventBus,
Map<String, Credentials> credentialStore, LoggerFactory loggerFactory,
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);
this.sshForNode = sshForNode;
}

View File

@ -20,7 +20,6 @@ package org.jclouds.compute.strategy;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata;
@ -28,6 +27,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.ImplementedBy;
/**
@ -37,6 +37,6 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class)
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);
}

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.Sets.newLinkedHashSet;
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
import static org.jclouds.concurrent.Futures.compose;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource;
@ -42,6 +39,7 @@ import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.GroupNamingConvention;
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.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
@ -95,7 +96,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
protected final CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy;
protected final ListNodesStrategy listNodesStrategy;
protected final GroupNamingConvention.Factory namingConvention;
protected final ExecutorService executor;
protected final ListeningExecutorService userExecutor;
protected final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
@Inject
@ -103,12 +104,12 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory) {
this.addNodeWithGroupStrategy = addNodeWithGroupStrategy;
this.listNodesStrategy = listNodesStrategy;
this.namingConvention = namingConvention;
this.executor = executor;
this.userExecutor = userExecutor;
this.customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory = customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
}
@ -117,13 +118,13 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
* simultaneously runs the nodes and applies options to them.
*/
@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<String, Future<Void>> responses = newLinkedHashMap();
Map<String, ListenableFuture<Void>> responses = newLinkedHashMap();
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,
badNodes, customizationResponses), executor));
badNodes, customizationResponses), userExecutor));
}
return responses;
}
@ -141,10 +142,10 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
*
* <pre>
* &#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) {
*
* 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;() {
*
* &#064;Override
@ -164,9 +165,9 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet implements CreateNo
* @param template user-specified template
* @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) {
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 java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.ImageBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
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.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableSet;
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 {
private final Supplier<Location> location;
private final ConcurrentMap<String, NodeMetadata> nodes;
private final ExecutorService ioThreads;
private final ListeningExecutorService ioExecutor;
private final Provider<Integer> idProvider;
private final String publicIpPrefix;
private final String privateIpPrefix;
@ -73,12 +73,12 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Inject
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("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
JustProvider locationSupplier, Map<OsFamily, Map<String, String>> osToVersionMap) {
this.nodes = nodes;
this.ioThreads=ioThreads;
this.ioExecutor = ioExecutor;
this.location = location;
this.idProvider = idProvider;
this.publicIpPrefix = publicIpPrefix;
@ -96,7 +96,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
if (millis == 0l)
setStateOnNode(status, node);
else
ioThreads.execute(new Runnable() {
ioExecutor.execute(new Runnable() {
@Override
public void run() {
@ -187,7 +187,7 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
return;
setStateOnNodeAfterDelay(Status.PENDING, node, 0);
setStateOnNodeAfterDelay(Status.TERMINATED, node, 50);
ioThreads.execute(new Runnable() {
ioExecutor.execute(new Runnable() {
@Override
public void run() {

View File

@ -22,8 +22,6 @@ import static com.google.common.collect.Maps.newLinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
@ -37,6 +35,8 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
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
public class ComputeUtils {
private final CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
public ComputeUtils(
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
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,
Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Map<NodeMetadata, Future<Void>> responses = newLinkedHashMap();
Map<NodeMetadata, ListenableFuture<Void>> responses = newLinkedHashMap();
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)));
}
return responses;

View File

@ -18,7 +18,6 @@
*/
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.checkState;
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.util.concurrent.Atomics.newReference;
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.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
import java.util.NoSuchElementException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@ -66,16 +65,16 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
private final SocketOpen socketTester;
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning;
private final ListeningExecutorService executor;
private final ListeningExecutorService userExecutor;
@Inject
@VisibleForTesting
ConcurrentOpenSocketFinder(SocketOpen socketTester,
@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.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
this.executor = listeningDecorator(checkNotNull(userThreads, "userThreads"));
this.userExecutor = listeningDecorator(checkNotNull(userExecutor, "userExecutor"));
}
@Override
@ -123,7 +122,7 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
Builder<ListenableFuture<?>> futures = ImmutableList.builder();
for (final HostAndPort socket : input) {
futures.add(executor.submit(new Runnable() {
futures.add(userExecutor.submit(new Runnable() {
@Override
public void run() {

View File

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

View File

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

View File

@ -30,7 +30,6 @@ import static org.testng.Assert.fail;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
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.ImmutableSet;
import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
@Test(singleThreaded = true)
public class ConcurrentOpenSocketFinderTest {
@ -67,24 +68,24 @@ public class ConcurrentOpenSocketFinderTest {
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning = alwaysTrue();
private final Predicate<AtomicReference<NodeMetadata>> nodeNotRunning = alwaysFalse();
private ExecutorService threadPool;
private ListeningExecutorService userExecutor;
@BeforeClass
public void setUp() {
threadPool = Executors.newCachedThreadPool();
userExecutor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
}
@AfterClass(alwaysRun = true)
public void tearDown() {
if (threadPool != null)
threadPool.shutdownNow();
if (userExecutor != null)
userExecutor.shutdownNow();
}
@Test
public void testRespectsTimeout() throws Exception {
final long timeoutMs = 1000;
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeRunning, threadPool);
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeRunning, userExecutor);
Stopwatch stopwatch = new Stopwatch();
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);
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.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);
assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22));
@ -131,7 +132,7 @@ public class ConcurrentOpenSocketFinderTest {
@Test
public void testAbortsWhenNodeNotRunning() throws Exception {
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeNotRunning, threadPool) {
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketAlwaysClosed, nodeNotRunning, userExecutor) {
@Override
protected <T> Predicate<T> retryPredicate(final Predicate<T> findOrBreak, long period, long timeoutValue,
TimeUnit timeUnits) {

View File

@ -24,7 +24,6 @@ import static org.jclouds.io.ByteSources.asByteSource;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import javax.inject.Named;
@ -48,6 +47,7 @@ import org.jclouds.io.Payloads;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Inject;
/**
@ -62,10 +62,10 @@ public class ApacheHCHttpCommandExecutorService extends BaseHttpCommandExecutorS
@Inject
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,
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.apacheHCUtils = new ApacheHCUtils(contentMetadataCodec);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,6 @@ package org.jclouds.abiquo.rest.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -40,6 +39,7 @@ import org.jclouds.rest.internal.UtilsImpl;
import org.jclouds.xml.XMLParser;
import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.inject.Injector;
import com.google.inject.Singleton;
@ -57,11 +57,11 @@ public class ExtendedUtils extends UtilsImpl implements Utils {
@Inject
public ExtendedUtils(final Injector injector, final Json json, final XMLParser xml, final HttpClient simpleApi,
final HttpAsyncClient simpleAsyncApi, final Crypto encryption, final DateService date,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userThreads,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) final ExecutorService ioThreads, final EventBus eventBus,
@Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) final ListeningExecutorService ioExecutor, final EventBus eventBus,
final Map<String, Credentials> credentialStore, final LoggerFactory loggerFactory,
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);
this.abiquoHttpClient = checkNotNull(abiquoHttpClient, "abiquoHttpClient");
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.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
@ -44,6 +41,8 @@ import com.abiquo.server.core.cloud.VirtualApplianceDto;
import com.abiquo.server.core.cloud.VirtualAppliancesDto;
import com.google.common.base.Function;
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.Singleton;
@ -58,7 +57,7 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
protected final ListVirtualDatacenters listVirtualDatacenters;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@ -69,7 +68,7 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
@Inject
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) {
this.context = checkNotNull(context, "context");
this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters");
@ -92,9 +91,9 @@ public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance>
private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final Iterable<VirtualDatacenter> vdcs) {
Iterable<VirtualAppliancesDto> vapps = transformParallel(vdcs,
new Function<VirtualDatacenter, Future<? extends VirtualAppliancesDto>>() {
new Function<VirtualDatacenter, ListenableFuture<? extends VirtualAppliancesDto>>() {
@Override
public Future<VirtualAppliancesDto> apply(final VirtualDatacenter input) {
public ListenableFuture<VirtualAppliancesDto> apply(final VirtualDatacenter input) {
return context.getAsyncApi().getCloudApi().listVirtualAppliances(input.unwrap());
}
}, 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 java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Predicate;
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.Singleton;
@ -58,7 +58,7 @@ import com.google.inject.Singleton;
public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacenter> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@ -69,7 +69,7 @@ public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacente
@Inject
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.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@ -103,9 +103,9 @@ public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacente
private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final List<Integer> ids) {
Iterable<VirtualDatacenterDto> vdcs = transformParallel(ids,
new Function<Integer, Future<? extends VirtualDatacenterDto>>() {
new Function<Integer, ListenableFuture<? extends VirtualDatacenterDto>>() {
@Override
public Future<VirtualDatacenterDto> apply(final Integer input) {
public ListenableFuture<VirtualDatacenterDto> apply(final Integer input) {
return context.getAsyncApi().getCloudApi().getVirtualDatacenter(input);
}
}, 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.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
@ -45,6 +42,8 @@ import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto;
import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto;
import com.google.common.base.Function;
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.Singleton;
@ -57,7 +56,7 @@ import com.google.inject.Singleton;
public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
protected final ListVirtualAppliances listVirtualAppliances;
@ -70,7 +69,7 @@ public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
@Inject
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) {
super();
this.context = checkNotNull(context, "context");
@ -99,9 +98,9 @@ public class ListVirtualMachines implements ListRootEntities<VirtualMachine> {
private Iterable<VirtualMachineWithNodeExtendedDto> listConcurrentVirtualMachines(
final Iterable<VirtualAppliance> vapps, final VirtualMachineOptions options) {
Iterable<VirtualMachinesWithNodeExtendedDto> vms = transformParallel(vapps,
new Function<VirtualAppliance, Future<? extends VirtualMachinesWithNodeExtendedDto>>() {
new Function<VirtualAppliance, ListenableFuture<? extends VirtualMachinesWithNodeExtendedDto>>() {
@Override
public Future<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) {
public ListenableFuture<VirtualMachinesWithNodeExtendedDto> apply(final VirtualAppliance input) {
return context.getAsyncApi().getCloudApi().listVirtualMachines(input.unwrap(), options);
}
}, 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.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
@ -45,6 +42,8 @@ import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto;
import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto;
import com.google.common.base.Function;
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.Singleton;
@ -57,7 +56,7 @@ import com.google.inject.Singleton;
public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineTemplate, Enterprise> {
protected final RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@ -68,7 +67,7 @@ public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineT
@Inject
ListVirtualMachineTemplates(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
@Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) {
super();
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
@ -92,9 +91,9 @@ public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineT
private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final Enterprise parent,
final Iterable<Datacenter> dcs) {
Iterable<VirtualMachineTemplatesDto> templates = transformParallel(dcs,
new Function<Datacenter, Future<? extends VirtualMachineTemplatesDto>>() {
new Function<Datacenter, ListenableFuture<? extends VirtualMachineTemplatesDto>>() {
@Override
public Future<VirtualMachineTemplatesDto> apply(final Datacenter input) {
public ListenableFuture<VirtualMachineTemplatesDto> apply(final Datacenter input) {
return context.getAsyncApi().getVirtualMachineTemplateApi()
.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.concurrent.FutureIterables.transformParallel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Named;
@ -47,6 +44,8 @@ import com.abiquo.server.core.infrastructure.RackDto;
import com.abiquo.server.core.infrastructure.RacksDto;
import com.google.common.base.Function;
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.Singleton;
@ -59,7 +58,7 @@ import com.google.inject.Singleton;
public class ListMachines implements ListRootEntities<Machine> {
protected RestContext<AbiquoApi, AbiquoAsyncApi> context;
protected final ExecutorService userExecutor;
protected final ListeningExecutorService userExecutor;
@Resource
protected Logger logger = Logger.NULL;
@ -70,7 +69,7 @@ public class ListMachines implements ListRootEntities<Machine> {
@Inject
ListMachines(final RestContext<AbiquoApi, AbiquoAsyncApi> context,
@Named(Constants.PROPERTY_USER_THREADS) final ExecutorService userExecutor) {
@Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) {
super();
this.context = checkNotNull(context, "context");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
@ -93,9 +92,9 @@ public class ListMachines implements ListRootEntities<Machine> {
}
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
public Future<RacksDto> apply(final Datacenter input) {
public ListenableFuture<RacksDto> apply(final Datacenter input) {
return context.getAsyncApi().getInfrastructureApi().listRacks(input.unwrap());
}
}, userExecutor, maxTime, logger, "getting racks");
@ -104,9 +103,9 @@ public class ListMachines implements ListRootEntities<Machine> {
}
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
public Future<MachinesDto> apply(final RackDto input) {
public ListenableFuture<MachinesDto> apply(final RackDto input) {
return context.getAsyncApi().getInfrastructureApi().listMachines(input);
}
}, 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.collect.Iterables.concat;
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 java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -34,7 +33,6 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.collect.PagedIterable;
import org.jclouds.concurrent.Futures;
import org.jclouds.elb.ELBAsyncApi;
import org.jclouds.elb.domain.LoadBalancer;
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.Supplier;
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 Function<LoadBalancerInRegion, LoadBalancerMetadata> converter;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
private final Supplier<Set<String>> regions;
@Inject
protected ELBListLoadBalancersStrategy(ELBAsyncApi aapi,
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.regions = checkNotNull(regions, "regions");
this.converter = checkNotNull(converter, "converter");
this.executor = checkNotNull(executor, "executor");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
}
@Override
public Iterable<LoadBalancerMetadata> listLoadBalancers() {
Iterable<LoadBalancerInRegion> loadBalancers = concat(transformParallel(regions.get(),
new Function<String, Future<? extends Iterable<LoadBalancerInRegion>>>() {
new Function<String, ListenableFuture<? extends Iterable<LoadBalancerInRegion>>>() {
@Override
public ListenableFuture<? extends Iterable<LoadBalancerInRegion>> apply(final String from) {
// TODO: ELB.listLoadBalancers
return Futures.compose(aapi.getLoadBalancerApiForRegion(from).list(),
return transform(aapi.getLoadBalancerApiForRegion(from).list(),
new Function<PagedIterable<LoadBalancer>, Iterable<LoadBalancerInRegion>>() {
@Override
@ -96,10 +95,10 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
});
}
}, executor);
}, userExecutor);
}
}, executor, null, logger, "loadbalancers"));
}, userExecutor, null, logger, "loadbalancers"));
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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
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.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -101,7 +101,7 @@ public class JoyentCloudComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
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,
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByDatacenterId,
GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension) {
@ -109,7 +109,7 @@ public class JoyentCloudComputeService extends BaseComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, executor, imageExtension);
persistNodeCredentials, timeouts, userExecutor, imageExtension);
this.novaApi = checkNotNull(novaApi, "novaApi");
this.keyCache = checkNotNull(keyCache, "keyCache");
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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject;
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.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,
GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
LoadingCache<DatacenterAndName, KeyAndPrivateKey> keyCache,
@Named(AUTOGENERATE_KEYS) boolean defaultToAutogenerateKeys) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.keyCache = checkNotNull(keyCache, "keyCache");
this.defaultToAutogenerateKeys = defaultToAutogenerateKeys;
}
@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) {
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 java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
@ -127,14 +126,12 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
@Inject
protected LoadingCache<Image, Master> mastersCache;
private final ExecutorService singleThreadExec = sameThreadExecutor();
private String masterName;
@Override
protected Iterable<Module> setupModules() {
return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule(
singleThreadExec, singleThreadExec));
sameThreadExecutor(), sameThreadExecutor()));
}
@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.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
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.Supplier;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -100,7 +100,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
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,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
@Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap,
@ -111,7 +111,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess,
persistNodeCredentials, timeouts, executor, client, credentialsMap, securityGroupMap, imageExtension,
persistNodeCredentials, timeouts, userExecutor, client, credentialsMap, securityGroupMap, imageExtension,
namingConvention, generateInstanceNames);
this.client = client;
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 java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Named;
import javax.inject.Singleton;
@ -44,6 +42,8 @@ import org.jclouds.location.Region;
import com.google.common.base.Function;
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;
/**
@ -59,9 +59,9 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Inject
protected AWSEC2ListNodesStrategy(AWSEC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
SpotInstanceRequestToAWSRunningInstance spotConverter) {
super(client, regions, runningInstanceToNodeMetadata, executor);
super(client, regions, runningInstanceToNodeMetadata, userExecutor);
this.client = checkNotNull(client, "client");
this.spotConverter = checkNotNull(spotConverter, "spotConverter");
}
@ -69,14 +69,13 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Override
protected Iterable<? extends RunningInstance> pollRunningInstances() {
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
public Future<? extends Set<SpotInstanceRequest>> apply(String from) {
return client.getSpotInstanceServices()
.describeSpotInstanceRequestsInRegion(from);
public ListenableFuture<? extends Set<SpotInstanceRequest>> apply(String from) {
return client.getSpotInstanceServices().describeSpotInstanceRequestsInRegion(from);
}
}, executor, maxTime, logger, "reservations")), spotConverter), notNull());
}, userExecutor, maxTime, logger, "reservations")), spotConverter), notNull());
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.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.Multimap;
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 CallForImages.Factory factory;
private final ExecutorService executor;
private final ListeningExecutorService userExecutor;
private final Supplier<Set<String>> regions;
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,
Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
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.regions = regions;
this.queries = queries;
this.clusterRegions = Splitter.on(',').split(clusterRegions);
this.cache = cache;
this.clusterComputeIds = clusterComputeIds;
this.executor = executor;
this.userExecutor = userExecutor;
}
@SuppressWarnings("unchecked")
@ -99,7 +99,7 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
String amiQuery = queries.get(PROPERTY_EC2_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;
try {
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) {
logger.debug(">> no %s specified, skipping image parsing", tag);
return Futures.<Iterable<Image>> immediateFuture(ImmutableSet.<Image> of());
} else {
return executor.submit(factory.parseImagesFromRegionsUsingFilter(regions, QueryStringToMultimap.INSTANCE
return userExecutor.submit(factory.parseImagesFromRegionsUsingFilter(regions, QueryStringToMultimap.INSTANCE
.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 java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.LoadingCache;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
*
@ -73,7 +73,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore {
@Inject
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,
Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
@ -81,7 +81,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
LoadingCache<String, AccessControlList> bucketAcls,
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,
object2BlobMd, fetchBlobMetadataProvider, bucketAcls);
this.multipartUploadStrategy = multipartUploadStrategy;

View File

@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
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.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;
@ -58,6 +56,7 @@ 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 {
@ -72,7 +71,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@VisibleForTesting
static final int DEFAULT_MAX_PERCENT_RETRIES = 10;
private final ExecutorService ioWorkerExecutor;
private final ListeningExecutorService ioExecutor;
@Inject(optional = true)
@Named("jclouds.mpu.parallel.degree")
@ -101,10 +100,10 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
@Inject
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.slicer = checkNotNull(slicer, "slicer");
this.ioWorkerExecutor = checkNotNull(ioWorkerExecutor, "ioWorkerExecutor");
this.ioExecutor = checkNotNull(ioExecutor, "ioExecutor");
}
protected void prepareUploadPart(final String container, final String key,
@ -149,14 +148,13 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
latch.countDown();
}
}
}, ioWorkerExecutor);
}, ioExecutor);
futureParts.put(part, futureETag);
}
@Override
public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options) {
return Futures.makeListenable(
ioWorkerExecutor.submit(new Callable<String>() {
return ioExecutor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
String key = blob.getMetadata().getName();
@ -250,7 +248,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
futureETag.get(maxTime,TimeUnit.SECONDS) : futureETag.get();
}
}
}), ioWorkerExecutor);
});
}
class Part {

View File

@ -19,10 +19,10 @@
package org.jclouds.azureblob.blobstore;
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 java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
@ -56,7 +56,6 @@ import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location;
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.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Adrian Cole
@ -81,14 +81,14 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
@Inject
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,
ContainerToResourceMetadata container2ResourceMd,
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd,
BlobToHttpGetOptions blob2ObjectGetOptions) {
super(context, blobUtils, service, defaultLocation, locations);
super(context, blobUtils, userExecutor, defaultLocation, locations);
this.async = checkNotNull(async, "async");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,
@ -106,8 +106,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
*/
@Override
public ListenableFuture<org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>> list() {
return Futures
.compose(
return transform(
async.listContainers(includeMetadata()),
new Function<BoundedSet<ContainerProperties>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() {
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),
from.getNextMarker());
}
}, service);
}, userExecutor);
}
/**
@ -152,7 +151,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) {
ListBlobsOptions azureOptions = blobStore2AzureContainerListOptions.apply(options);
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) {
GetOptions azureOptions = blob2ObjectGetOptions.apply(options);
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
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return Futures.compose(async.getBlobProperties(container, key), new Function<BlobProperties, BlobMetadata>() {
@Override
return transform(async.getBlobProperties(container, key), new Function<BlobProperties, BlobMetadata>() {
public BlobMetadata apply(BlobProperties from) {
return blob2BlobMd.apply(from);
}
}, service);
}, userExecutor);
}
@Override

View File

@ -29,8 +29,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
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.ImmutableSet;
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
@ -89,17 +89,17 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
private final GleSYSApi api;
private final GleSYSAsyncApi aapi;
private final ExecutorService userThreads;
private final ListeningExecutorService userExecutor;
private final Timeouts timeouts;
private final Supplier<Set<? extends Location>> locations;
@Inject
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) {
this.api = checkNotNull(api, "api");
this.aapi = checkNotNull(aapi, "aapi");
this.userThreads = checkNotNull(userThreads, "userThreads");
this.userExecutor = checkNotNull(userExecutor, "userExecutor");
this.timeouts = checkNotNull(timeouts, "timeouts");
this.locations = checkNotNull(locations, "locations");
}
@ -209,13 +209,11 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
@Override
public Iterable<ServerDetails> listNodes() {
return transformParallel(api.getServerApi().list(), new Function<Server, Future<? extends ServerDetails>>() {
@Override
public Future<ServerDetails> apply(Server from) {
return transformParallel(api.getServerApi().list(), new Function<Server, ListenableFuture<? extends ServerDetails>>() {
public ListenableFuture<ServerDetails> apply(Server from) {
return aapi.getServerApi().get(from.getId());
}
}, userThreads, null, logger, "server details");
}, userExecutor, null, logger, "server details");
}
@Override

View File

@ -23,7 +23,6 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_T
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
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.Predicate;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author Andrew Kennedy
@ -82,13 +82,13 @@ public class GoGridComputeService extends BaseComputeService {
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
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) {
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
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;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
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.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.blobstore.functions.EnableCDNAndCache;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
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.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
*
@ -61,7 +62,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
@Inject
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,
ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
@ -69,7 +70,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache,
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,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
this.enableAndCache = enableAndCache;
@ -81,7 +82,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container);
if (options.isPublicRead())
return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
return transform(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
@Override
public Boolean apply(Boolean input) {
@ -91,7 +92,7 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
return false;
}
}, service);
}, userExecutor);
return returnVal;
}
}