cleanup of module binding, clarity in toStrings, reduced wrapper depth for memoized sets

This commit is contained in:
Adrian Cole 2012-07-02 19:36:27 -07:00
parent 07240f3e77
commit fb98ce82f7
49 changed files with 749 additions and 592 deletions

View File

@ -48,10 +48,10 @@ import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.ApiVersion; import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -94,7 +94,7 @@ public class CloudLoadBalancersRestClientModule extends
@Singleton @Singleton
@Named(RackspaceConstants.PROPERTY_ACCOUNT_ID) @Named(RackspaceConstants.PROPERTY_ACCOUNT_ID)
protected Supplier<String> accountID(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) { protected Supplier<String> accountID(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return Suppliers.compose(new Function<URI, String>() { return Suppliers2.compose(new Function<URI, String>() {
@Override @Override
public String apply(URI arg0) { public String apply(URI arg0) {

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.cloudstack.compute.config; package org.jclouds.cloudstack.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map; import java.util.Map;
@ -26,7 +25,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -56,7 +54,6 @@ import org.jclouds.cloudstack.functions.GetFirewallRulesByVirtualMachine;
import org.jclouds.cloudstack.functions.GetIPForwardingRulesByVirtualMachine; import org.jclouds.cloudstack.functions.GetIPForwardingRulesByVirtualMachine;
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork; import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
import org.jclouds.cloudstack.functions.ZoneIdToZone; import org.jclouds.cloudstack.functions.ZoneIdToZone;
import org.jclouds.cloudstack.options.ListFirewallRulesOptions;
import org.jclouds.cloudstack.predicates.JobComplete; import org.jclouds.cloudstack.predicates.JobComplete;
import org.jclouds.cloudstack.suppliers.GetCurrentUser; import org.jclouds.cloudstack.suppliers.GetCurrentUser;
import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser; import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser;
@ -70,17 +67,16 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -127,14 +123,18 @@ public class CloudStackComputeServiceContextModule extends
@Memoized @Memoized
public Supplier<Map<String, String>> listOSCategories(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, public Supplier<Map<String, String>> listOSCategories(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final CloudStackClient client) { final CloudStackClient client) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
seconds, new Supplier<Map<String, String>>() { new Supplier<Map<String, String>>() {
@Override @Override
public Map<String, String> get() { public Map<String, String> get() {
GuestOSClient guestOSClient = client.getGuestOSClient(); GuestOSClient guestOSClient = client.getGuestOSClient();
return guestOSClient.listOSCategories(); return guestOSClient.listOSCategories();
} }
}); @Override
public String toString() {
return Objects.toStringHelper(client.getGuestOSClient()).add("method", "listOSCategories").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
@Provides @Provides
@ -142,8 +142,8 @@ public class CloudStackComputeServiceContextModule extends
@Memoized @Memoized
public Supplier<Map<String, OSType>> listOSTypes(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, public Supplier<Map<String, OSType>> listOSTypes(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final CloudStackClient client) { final CloudStackClient client) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, OSType>>(authException, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
seconds, new Supplier<Map<String, OSType>>() { new Supplier<Map<String, OSType>>() {
@Override @Override
public Map<String, OSType> get() { public Map<String, OSType> get() {
GuestOSClient guestOSClient = client.getGuestOSClient(); GuestOSClient guestOSClient = client.getGuestOSClient();
@ -155,7 +155,11 @@ public class CloudStackComputeServiceContextModule extends
} }
}); });
} }
}); @Override
public String toString() {
return Objects.toStringHelper(client.getGuestOSClient()).add("method", "listOSTypes").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
@Provides @Provides
@ -163,8 +167,8 @@ public class CloudStackComputeServiceContextModule extends
@Memoized @Memoized
public Supplier<Map<String, Network>> listNetworks(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, public Supplier<Map<String, Network>> listNetworks(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final NetworksForCurrentUser networksForCurrentUser) { final NetworksForCurrentUser networksForCurrentUser) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Network>>(authException, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, networksForCurrentUser,
seconds, networksForCurrentUser); seconds, TimeUnit.SECONDS);
} }
@Provides @Provides
@ -172,8 +176,8 @@ public class CloudStackComputeServiceContextModule extends
@Memoized @Memoized
public Supplier<User> getCurrentUser(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, public Supplier<User> getCurrentUser(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final GetCurrentUser getCurrentUser) { final GetCurrentUser getCurrentUser) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<User>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, getCurrentUser,
getCurrentUser); seconds, TimeUnit.SECONDS);
} }
@Provides @Provides

View File

@ -23,6 +23,7 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.net.URI; import java.net.URI;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
@ -47,11 +48,12 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -81,13 +83,17 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
@Singleton @Singleton
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections( protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends DeltacloudCollection>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(
authException, seconds, new Supplier<Set<? extends DeltacloudCollection>>() { authException, new Supplier<Set<? extends DeltacloudCollection>>() {
@Override @Override
public Set<? extends DeltacloudCollection> get() { public Set<? extends DeltacloudCollection> get() {
return client.getCollections(); return client.getCollections();
} }
}); @Override
public String toString() {
return Objects.toStringHelper(client).add("method", "getCollections").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
/** /**
@ -97,7 +103,7 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
@Provides @Provides
@Images @Images
protected Supplier<URI> provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) { protected Supplier<URI> provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("images"), collectionSupplier); return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("images"), collectionSupplier);
} }
public static class FindCollectionWithRelAndReturnHref implements Function<Set<? extends DeltacloudCollection>, URI> { public static class FindCollectionWithRelAndReturnHref implements Function<Set<? extends DeltacloudCollection>, URI> {
@ -128,24 +134,24 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
@Provides @Provides
@HardwareProfiles @HardwareProfiles
protected Supplier<URI> provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) { protected Supplier<URI> provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("hardware_profiles"), collectionSupplier); return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("hardware_profiles"), collectionSupplier);
} }
@Provides @Provides
@Instances @Instances
protected Supplier<URI> provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) { protected Supplier<URI> provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("instances"), collectionSupplier); return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instances"), collectionSupplier);
} }
@Provides @Provides
@Realms @Realms
protected Supplier<URI> provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) { protected Supplier<URI> provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("realms"), collectionSupplier); return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("realms"), collectionSupplier);
} }
@Provides @Provides
@InstanceStates @InstanceStates
protected Supplier<URI> provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) { protected Supplier<URI> provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("instance_states"), collectionSupplier); return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instance_states"), collectionSupplier);
} }
} }

View File

@ -26,8 +26,11 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneParserModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule; import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule;
import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata; import org.jclouds.rest.internal.BaseRestApiMetadata;
@ -85,7 +88,11 @@ public class KeystoneApiMetadata extends BaseRestApiMetadata {
.version("2.0") .version("2.0")
.defaultEndpoint("http://localhost:5000") .defaultEndpoint("http://localhost:5000")
.defaultProperties(KeystoneApiMetadata.defaultProperties()) .defaultProperties(KeystoneApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(KeystoneAdminURLModule.class)
.add(KeystoneParserModule.class)
.add(KeystoneRestClientModule.class).build());
} }
@Override @Override

View File

@ -35,12 +35,18 @@ import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.location.Provider; import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.RegionIdsSupplier; import org.jclouds.location.suppliers.RegionIdsSupplier;
import org.jclouds.location.suppliers.ZoneIdToURISupplier; import org.jclouds.location.suppliers.ZoneIdToURISupplier;
import org.jclouds.location.suppliers.ZoneIdsSupplier; import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.all.ZoneToProvider;
import org.jclouds.location.suppliers.derived.RegionIdsFromRegionIdToURIKeySet; import org.jclouds.location.suppliers.derived.RegionIdsFromRegionIdToURIKeySet;
import org.jclouds.location.suppliers.derived.ZoneIdsFromZoneIdToURIKeySet; import org.jclouds.location.suppliers.derived.ZoneIdsFromZoneIdToURIKeySet;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.location.suppliers.implicit.FirstZone;
import org.jclouds.openstack.keystone.v2_0.AuthenticationAsyncClient; import org.jclouds.openstack.keystone.v2_0.AuthenticationAsyncClient;
import org.jclouds.openstack.keystone.v2_0.AuthenticationClient; import org.jclouds.openstack.keystone.v2_0.AuthenticationClient;
import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.openstack.keystone.v2_0.domain.Access;
@ -62,8 +68,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.assistedinject.FactoryModuleBuilder; import com.google.inject.assistedinject.FactoryModuleBuilder;
/** /**
@ -71,25 +77,6 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class KeystoneAuthenticationModule extends AbstractModule { public class KeystoneAuthenticationModule extends AbstractModule {
private final Module locationModule;
public KeystoneAuthenticationModule() {
this(new RegionModule());
}
protected KeystoneAuthenticationModule(Module locationModule) {
this.locationModule = locationModule;
}
public static class KeystoneAuthenticationModuleForRegions extends KeystoneAuthenticationModule {
public KeystoneAuthenticationModuleForRegions() {
super(new RegionModule());
}
}
public static Module forRegions() {
return new KeystoneAuthenticationModuleForRegions();
}
public static class RegionModule extends AbstractModule { public static class RegionModule extends AbstractModule {
@Override @Override
@ -100,6 +87,8 @@ public class KeystoneAuthenticationModule extends AbstractModule {
RegionIdToAdminURIFromAccessForTypeAndVersion.class).build(RegionIdToAdminURISupplier.Factory.class)); RegionIdToAdminURIFromAccessForTypeAndVersion.class).build(RegionIdToAdminURISupplier.Factory.class));
// dynamically build the region list as opposed to from properties // dynamically build the region list as opposed to from properties
bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class); bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class);
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
} }
// supply the region to id map from keystone, based on the servicetype and api version in // supply the region to id map from keystone, based on the servicetype and api version in
@ -132,6 +121,8 @@ public class KeystoneAuthenticationModule extends AbstractModule {
ZoneIdToURIFromAccessForTypeAndVersion.class).build(ZoneIdToURISupplier.Factory.class)); ZoneIdToURIFromAccessForTypeAndVersion.class).build(ZoneIdToURISupplier.Factory.class));
// dynamically build the zone list as opposed to from properties // dynamically build the zone list as opposed to from properties
bind(ZoneIdsSupplier.class).to(ZoneIdsFromZoneIdToURIKeySet.class); bind(ZoneIdsSupplier.class).to(ZoneIdsFromZoneIdToURIKeySet.class);
bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(ZoneToProvider.class).in(Scopes.SINGLETON);
} }
// supply the zone to id map from keystone, based on the servicetype and api version in // supply the zone to id map from keystone, based on the servicetype and api version in
@ -146,21 +137,10 @@ public class KeystoneAuthenticationModule extends AbstractModule {
} }
public static class KeystoneAuthenticationModuleForZones extends KeystoneAuthenticationModule {
public KeystoneAuthenticationModuleForZones() {
super(new ZoneModule());
}
}
public static Module forZones() {
return new KeystoneAuthenticationModuleForZones();
}
@Override @Override
protected void configure() { protected void configure() {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class); bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
bindAuthenticationClient(); bindAuthenticationClient();
install(locationModule);
} }
protected void bindAuthenticationClient() { protected void bindAuthenticationClient() {

View File

@ -61,6 +61,7 @@ public class KeystoneParserModule extends AbstractModule {
* Treats [A,B,C] and {"values"=[A,B,C], "someotherstuff"=...} as the same Set * Treats [A,B,C] and {"values"=[A,B,C], "someotherstuff"=...} as the same Set
*/ */
public static class SetTypeAdapterFactory implements TypeAdapterFactory { public static class SetTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) { public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
Type type = typeToken.getType(); Type type = typeToken.getType();
if (typeToken.getRawType() != Set.class || !(type instanceof ParameterizedType)) { if (typeToken.getRawType() != Set.class || !(type instanceof ParameterizedType)) {
@ -69,7 +70,7 @@ public class KeystoneParserModule extends AbstractModule {
Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
TypeAdapter<?> elementAdapter = gson.getAdapter(TypeToken.get(elementType)); TypeAdapter<?> elementAdapter = gson.getAdapter(TypeToken.get(elementType));
return (TypeAdapter<T>) newSetAdapter(elementAdapter); return TypeAdapter.class.cast(newSetAdapter(elementAdapter));
} }
private <E> TypeAdapter<Set<E>> newSetAdapter(final TypeAdapter<E> elementAdapter) { private <E> TypeAdapter<Set<E>> newSetAdapter(final TypeAdapter<E> elementAdapter) {

View File

@ -67,15 +67,13 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
RestClientModule<S, A> { RestClientModule<S, A> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder() public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(ServiceClient.class, ServiceAsyncClient.class) .put(ServiceClient.class, ServiceAsyncClient.class).put(TokenClient.class, TokenAsyncClient.class)
.put(TokenClient.class, TokenAsyncClient.class) .put(UserClient.class, UserAsyncClient.class).put(TenantClient.class, TenantAsyncClient.class).build();
.put(UserClient.class, UserAsyncClient.class)
.put(TenantClient.class, TenantAsyncClient.class).build();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public KeystoneRestClientModule() { public KeystoneRestClientModule() {
super((TypeToken) TypeToken.of(KeystoneClient.class), (TypeToken) TypeToken.of(KeystoneAsyncClient.class), super(TypeToken.class.cast(TypeToken.of(KeystoneClient.class)), TypeToken.class.cast(TypeToken
DELEGATE_MAP); .of(KeystoneAsyncClient.class)), DELEGATE_MAP);
} }
protected KeystoneRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType, protected KeystoneRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
@ -83,18 +81,6 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
super(syncClientType, asyncClientType, sync2Async); super(syncClientType, asyncClientType, sync2Async);
} }
@Override
protected void configure() {
install(new KeystoneParserModule());
super.configure();
}
@Override
protected void installLocations() {
install(new KeystoneAuthenticationModule(new KeystoneAdminURLModule()));
super.installLocations();
}
public static class KeystoneAdminURLModule extends AbstractModule { public static class KeystoneAdminURLModule extends AbstractModule {
@Override @Override

View File

@ -31,7 +31,8 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForZones; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule; import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule; import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.ServiceType;
@ -100,7 +101,11 @@ public class NovaApiMetadata extends BaseRestApiMetadata {
.defaultEndpoint("http://localhost:5000") .defaultEndpoint("http://localhost:5000")
.defaultProperties(NovaApiMetadata.defaultProperties()) .defaultProperties(NovaApiMetadata.defaultProperties())
.view(TypeToken.of(ComputeServiceContext.class)) .view(TypeToken.of(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForZones.class, NovaRestClientModule.class, NovaComputeServiceContextModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(ZoneModule.class)
.add(NovaRestClientModule.class)
.add(NovaComputeServiceContextModule.class).build());
} }
@Override @Override

View File

@ -19,6 +19,7 @@
package org.jclouds.openstack.nova.v2_0.compute; package org.jclouds.openstack.nova.v2_0.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue; import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
@ -155,7 +156,9 @@ public class NovaComputeServiceAdapter implements
@Override @Override
public Iterable<ImageInZone> listImages() { public Iterable<ImageInZone> listImages() {
Builder<ImageInZone> builder = ImmutableSet.builder(); Builder<ImageInZone> builder = ImmutableSet.builder();
for (final String zoneId : zoneIds.get()) { Set<String> zones = zoneIds.get();
checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds);
for (final String zoneId : zones) {
Set<Image> images = novaClient.getImageClientForZone(zoneId).listImagesInDetail(); Set<Image> images = novaClient.getImageClientForZone(zoneId).listImagesInDetail();
if (images.size() == 0) { if (images.size() == 0) {
logger.debug("no images found in zone %s", zoneId); logger.debug("no images found in zone %s", zoneId);

View File

@ -72,13 +72,13 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAn
import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue; import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue;
import org.jclouds.predicates.PredicateWithResult; import org.jclouds.predicates.PredicateWithResult;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.util.Suppliers2;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -200,7 +200,7 @@ public class NovaComputeServiceContextModule extends
@Singleton @Singleton
protected Supplier<Map<String, Location>> createLocationIndexedById( protected Supplier<Map<String, Location>> createLocationIndexedById(
@Memoized Supplier<Set<? extends Location>> locations) { @Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() { return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override

View File

@ -33,6 +33,7 @@ import org.jclouds.openstack.nova.v2_0.domain.Image.Status;
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone; import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
/** /**
@ -63,4 +64,9 @@ public class ImageInZoneToImage implements Function<ImageInZone, Image> {
.userMetadata(image.getMetadata()).operatingSystem(imageToOs.apply(image)).description(image.getName()) .userMetadata(image.getMetadata()).operatingSystem(imageToOs.apply(image)).description(image.getName())
.location(location).status(toPortableImageStatus.get(image.getStatus())).build(); .location(location).status(toPortableImageStatus.get(image.getStatus())).build();
} }
@Override
public String toString() {
return Objects.toStringHelper(this).toString();
}
} }

View File

@ -29,10 +29,6 @@ import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.ZoneToProvider;
import org.jclouds.location.suppliers.implicit.FirstZone;
import org.jclouds.openstack.nova.v2_0.NovaAsyncClient; import org.jclouds.openstack.nova.v2_0.NovaAsyncClient;
import org.jclouds.openstack.nova.v2_0.NovaClient; import org.jclouds.openstack.nova.v2_0.NovaClient;
import org.jclouds.openstack.nova.v2_0.domain.Extension; import org.jclouds.openstack.nova.v2_0.domain.Extension;
@ -83,7 +79,6 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes;
/** /**
* Configures the Nova connection. * Configures the Nova connection.
@ -124,13 +119,6 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
super.configure(); super.configure();
} }
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(ZoneToProvider.class).in(Scopes.SINGLETON);
}
@Provides @Provides
@Singleton @Singleton
public LoadingCache<String, Set<Extension>> provideExtensionsByZone(final Provider<NovaClient> novaClient) { public LoadingCache<String, Set<Extension>> provideExtensionsByZone(final Provider<NovaClient> novaClient) {

View File

@ -34,7 +34,7 @@ import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.config.OpenStackAuthenticationModule; import org.jclouds.openstack.config.OpenStackAuthenticationModule;
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService; import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
@ -62,8 +62,8 @@ public class SwiftRestClientModule<S extends CommonSwiftClient, A extends Common
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public SwiftRestClientModule() { public SwiftRestClientModule() {
this((TypeToken) TypeToken.of(SwiftClient.class), (TypeToken) TypeToken.of(SwiftAsyncClient.class), ImmutableMap this(TypeToken.class.cast(TypeToken.of(SwiftClient.class)), TypeToken.class.cast(TypeToken
.<Class<?>, Class<?>> of()); .of(SwiftAsyncClient.class)), ImmutableMap.<Class<?>, Class<?>> of());
} }
protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType, protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
@ -80,7 +80,7 @@ public class SwiftRestClientModule<S extends CommonSwiftClient, A extends Common
} }
} }
public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModuleForRegions { public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModule {
@Provides @Provides
@Singleton @Singleton

View File

@ -31,6 +31,7 @@ import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction; import org.jclouds.functions.IdentityFunction;
import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.compute.functions.HardwareForVApp; import org.jclouds.vcloud.compute.functions.HardwareForVApp;
import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate; import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate;
import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
@ -51,7 +52,6 @@ import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -143,7 +143,7 @@ public class VCloudComputeServiceDependenciesModule extends AbstractModule {
@Singleton @Singleton
public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network, public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
final FenceMode defaultFenceMode) { final FenceMode defaultFenceMode) {
return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() { return Suppliers2.compose(new Function<ReferenceType, NetworkConfig>() {
@Override @Override
public NetworkConfig apply(ReferenceType input) { public NetworkConfig apply(ReferenceType input) {

View File

@ -26,6 +26,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
@ -34,7 +35,6 @@ import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfig
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/** /**
* *
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
@Override @Override
public Supplier<ReferenceType> apply(final String user) { public Supplier<ReferenceType> apply(final String user) {
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() { return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
@Override @Override
public ReferenceType apply(VCloudSession session) { public ReferenceType apply(VCloudSession session) {

View File

@ -27,6 +27,7 @@ import javax.inject.Singleton;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
@ -72,7 +73,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg); return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -80,7 +81,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg); return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -146,7 +147,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg); return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -161,7 +162,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) { @org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC); return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
} }
@Provides @Provides

View File

@ -21,7 +21,6 @@ package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.notNull; import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Suppliers.compose;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.getLast;
@ -35,8 +34,9 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -58,6 +58,7 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.ApiVersion; import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudToken; import org.jclouds.vcloud.VCloudToken;
@ -110,15 +111,15 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler; import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
@ -151,7 +152,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, final VCloudLoginClient login) { AtomicReference<AuthorizationException> authException, final VCloudLoginClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<VCloudSession>() { new Supplier<VCloudSession>() {
@Override @Override
@ -159,7 +160,11 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
return login.login(); return login.login();
} }
}); @Override
public String toString() {
return Objects.toStringHelper(login).add("method", "login").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
@Override @Override
@ -219,7 +224,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
@org.jclouds.vcloud.endpoints.VDC @org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, Org>> orgNameToOrgSuppier) { protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, Org>> orgNameToOrgSuppier) {
return compose(new Function<Map<String, Org>, Map<String, String>>() { return Suppliers2.compose(new Function<Map<String, Org>, Map<String, String>>() {
@Override @Override
public Map<String, String> apply(Map<String, Org> arg0) { public Map<String, String> apply(Map<String, Org> arg0) {
@ -239,15 +244,15 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
protected Supplier<Map<String, Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Map<String, Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) { AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Org>>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@Singleton @Singleton
@OrgList @OrgList
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) { protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
return Suppliers.compose(new Function<VCloudSession, URI>() { return Suppliers2.compose(new Function<VCloudSession, URI>() {
@Override @Override
public URI apply(VCloudSession arg0) { public URI apply(VCloudSession arg0) {
@ -318,7 +323,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Provides @Provides
@Singleton @Singleton
Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) { Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
return Suppliers.compose(new Function<VCloudSession, String>() { return Suppliers2.compose(new Function<VCloudSession, String>() {
@Override @Override
public String apply(VCloudSession input) { public String apply(VCloudSession input) {
@ -332,8 +337,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) { AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@ -341,8 +346,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
protected Supplier<Map<URI, VDC>> provideURIToVDC( protected Supplier<Map<URI, VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
URItoVDC supplier) { URItoVDC supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, VDC>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Singleton @Singleton
@ -411,7 +416,6 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> { private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
private final Supplier<VCloudSession> sessionSupplier; private final Supplier<VCloudSession> sessionSupplier;
@SuppressWarnings("unused")
@Inject @Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) { OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier; this.sessionSupplier = sessionSupplier;
@ -428,7 +432,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Singleton @Singleton
protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier, protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(new Function<ReferenceType, Org>() { return Suppliers2.compose(new Function<ReferenceType, Org>() {
@Override @Override
public Org apply(ReferenceType input) { public Org apply(ReferenceType input) {
@ -450,8 +454,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
protected Supplier<Map<String, Map<String, Catalog>>> provideOrgCatalogItemMapSupplierCache( protected Supplier<Map<String, Map<String, Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogSupplier supplier) { OrgCatalogSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Catalog>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@ -459,8 +463,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
protected Supplier<Map<String, Map<String, VDC>>> provideOrgVDCSupplierCache( protected Supplier<Map<String, Map<String, VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) { OrgVDCSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, VDC>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Singleton @Singleton
@ -533,8 +537,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
protected Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> provideOrgCatalogItemSupplierCache( protected Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogItemSupplier supplier) { OrgCatalogItemSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, CatalogItem>>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides

View File

@ -30,11 +30,11 @@ import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession; import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org; import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault; import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/** /**
* *
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
@Override @Override
public Supplier<ReferenceType> apply(final String user) { public Supplier<ReferenceType> apply(final String user) {
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() { return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
@Override @Override
public ReferenceType apply(VCloudSession session) { public ReferenceType apply(VCloudSession session) {

View File

@ -26,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import org.jclouds.trmk.vcloud_0_8.domain.Catalog; import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -69,7 +70,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg); return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -84,7 +85,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg); return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -121,7 +122,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg); return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -136,7 +137,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Singleton @Singleton
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) { @org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC); return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
} }
@Provides @Provides

View File

@ -32,8 +32,9 @@ import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCL
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
@ -81,14 +82,15 @@ import org.jclouds.trmk.vcloud_0_8.location.DefaultVDC;
import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier; import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier;
import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess; import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Maps;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
@ -141,7 +143,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC @org.jclouds.trmk.vcloud_0_8.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG( protected Supplier<Map<String, String>> provideVDCtoORG(
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSuppier) { Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSuppier) {
return Suppliers.compose( return Suppliers2.compose(
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() { new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() {
@Override @Override
@ -163,15 +165,15 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> provideOrgMapCache( protected Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> provideOrgMapCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgMapSupplier supplier) { OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@Singleton @Singleton
@OrgList @OrgList
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) { protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
return Suppliers.compose(new Function<VCloudSession, URI>() { return Suppliers2.compose(new Function<VCloudSession, URI>() {
@Override @Override
public URI apply(VCloudSession arg0) { public URI apply(VCloudSession arg0) {
@ -250,8 +252,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
@Singleton @Singleton
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) { AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@ -259,8 +261,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> provideURIToVDC( protected Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
URItoVDC supplier) { URItoVDC supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Singleton @Singleton
@ -333,7 +335,6 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> { private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
private final Supplier<VCloudSession> sessionSupplier; private final Supplier<VCloudSession> sessionSupplier;
@SuppressWarnings("unused")
@Inject @Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) { OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier; this.sessionSupplier = sessionSupplier;
@ -351,7 +352,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg( protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg(
final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier, final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return Suppliers.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() { return Suppliers2.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
@Override @Override
public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) { public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) {
@ -373,8 +374,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache( protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogSupplier supplier) { OrgCatalogSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Provides @Provides
@ -382,8 +383,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> provideOrgVDCSupplierCache( protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) { OrgVDCSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Singleton @Singleton
@ -460,8 +461,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache( protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgCatalogItemSupplier supplier) { OrgCatalogItemSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
/** /**
@ -479,7 +480,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
@Singleton @Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, final TerremarkVCloudLoginClient login) { AtomicReference<AuthorizationException> authException, final TerremarkVCloudLoginClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<VCloudSession>() { new Supplier<VCloudSession>() {
@Override @Override
@ -487,7 +488,11 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
return login.login(); return login.login();
} }
}); @Override
public String toString() {
return Objects.toStringHelper(login).add("method", "login").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
@Singleton @Singleton
@ -541,8 +546,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache( protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgNameToKeysListSupplier supplier) { OrgNameToKeysListSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>( return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
authException, seconds, supplier); TimeUnit.SECONDS);
} }
@Singleton @Singleton

View File

@ -26,6 +26,7 @@ import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
@ -61,11 +62,11 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -209,7 +210,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) { protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) {
return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() { return Suppliers2.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
@Override @Override
public Map<String, ? extends Image> apply(Set<? extends Image> from) { public Map<String, ? extends Image> apply(Set<? extends Image> from) {
@ -244,13 +245,8 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
protected Supplier<Set<? extends Image>> supplyImageCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Set<? extends Image>> supplyImageCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier) { final Supplier<Set<? extends Image>> imageSupplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Image>>(authException, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, imageSupplier, seconds,
seconds, new Supplier<Set<? extends Image>>() { TimeUnit.SECONDS);
@Override
public Set<? extends Image> get() {
return imageSupplier.get();
}
});
} }
/** /**
@ -264,7 +260,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) { protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() { return Suppliers2.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
@Override @Override
public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) { public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
@ -286,13 +282,8 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Memoized @Memoized
protected Supplier<Set<? extends Hardware>> supplySizeCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Set<? extends Hardware>> supplySizeCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Hardware>> hardwareSupplier) { final Supplier<Set<? extends Hardware>> hardwareSupplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, hardwareSupplier,
seconds, new Supplier<Set<? extends Hardware>>() { seconds, TimeUnit.SECONDS);
@Override
public Set<? extends Hardware> get() {
return hardwareSupplier.get();
}
});
} }
@Provides @Provides

View File

@ -48,6 +48,7 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.location.suppliers.LocationsSupplier; import org.jclouds.location.suppliers.LocationsSupplier;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -88,6 +89,11 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
Iterable<L> locations = filter(adapter.listLocations(), notNull()); Iterable<L> locations = filter(adapter.listLocations(), notNull());
return ImmutableSet.<Location> copyOf(transform(locations, transformer)); return ImmutableSet.<Location> copyOf(transform(locations, transformer));
} }
@Override
public String toString() {
return Objects.toStringHelper(adapter).add("method", "listLocations").toString();
}
}; };
} }
} }
@ -103,6 +109,11 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
return adapter.listHardwareProfiles(); return adapter.listHardwareProfiles();
} }
@Override
public String toString() {
return Objects.toStringHelper(adapter).add("method", "listHardwareProfiles").toString();
}
}, transformer); }, transformer);
} }
@ -117,6 +128,11 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
return filter(adapter.listImages(), notNull()); return filter(adapter.listImages(), notNull());
} }
@Override
public String toString() {
return Objects.toStringHelper(adapter).add("method", "listImages").toString();
}
}, compose(addDefaultCredentialsToImage, transformer)); }, compose(addDefaultCredentialsToImage, transformer));
} }
@ -139,7 +155,7 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
@Override @Override
public String toString() { public String toString() {
return "addDefaultCredentialsToImage()"; return Objects.toStringHelper(this).add("credsForImage", credsForImage).toString();
} }
} }

View File

@ -33,6 +33,8 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -67,4 +69,9 @@ public class ReturnCredentialsBoundToImage implements PopulateDefaultLoginCreden
return LoginCredentials.builder().user("root").build(); return LoginCredentials.builder().user("root").build();
} }
} }
@Override
public String toString() {
return Objects.toStringHelper(this).toString();
}
} }

View File

@ -20,20 +20,23 @@ package org.jclouds.collect;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.notNull; import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import java.io.Serializable;
import java.util.Set; import java.util.Set;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.FluentIterable;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> { public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>>, Serializable {
/** The serialVersionUID */
private static final long serialVersionUID = -8747953419394840218L;
private final Supplier<Iterable<F>> backingSupplier; private final Supplier<Iterable<F>> backingSupplier;
private final Function<F, T> converter; private final Function<F, T> converter;
@ -44,7 +47,33 @@ public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>>
@Override @Override
public Set<? extends T> get() { public Set<? extends T> get() {
return ImmutableSet.copyOf(filter(transform(filter(backingSupplier.get(), notNull()), converter), notNull())); Iterable<F> original = backingSupplier.get();
return FluentIterable.from(original)
.filter(notNull())
.transform(converter)
.filter(notNull())
.toImmutableSet();
} }
@Override
public int hashCode() {
return Objects.hashCode(backingSupplier, converter);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TransformingSetSupplier<?, ?> that = TransformingSetSupplier.class.cast(obj);
return Objects.equal(backingSupplier, that.backingSupplier) && Objects.equal(converter, that.converter);
}
@Override
public String toString() {
return Objects.toStringHelper(this).add("backingSupplier", backingSupplier).add("converter", converter).toString();
}
} }

View File

@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
@ -51,12 +52,12 @@ import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.functions.ImplicitOptionalConverter; import org.jclouds.rest.functions.ImplicitOptionalConverter;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -81,7 +82,8 @@ public class LocationModule extends AbstractModule {
protected Supplier<Map<String, Supplier<Set<String>>>> isoCodesSupplier( protected Supplier<Map<String, Supplier<Set<String>>>> isoCodesSupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
LocationIdToIso3166CodesSupplier uncached) { LocationIdToIso3166CodesSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@ -89,14 +91,16 @@ public class LocationModule extends AbstractModule {
@Provider @Provider
protected Supplier<URI> provideProvider(AtomicReference<AuthorizationException> authException, protected Supplier<URI> provideProvider(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ProviderURISupplier uncached) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, ProviderURISupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@Singleton @Singleton
protected Supplier<Location> implicitLocationSupplier(AtomicReference<AuthorizationException> authException, protected Supplier<Location> implicitLocationSupplier(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitLocationSupplier uncached) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitLocationSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@ -106,7 +110,8 @@ public class LocationModule extends AbstractModule {
protected Supplier<Set<? extends Location>> memoizedLocationsSupplier( protected Supplier<Set<? extends Location>> memoizedLocationsSupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
LocationsSupplier uncached) { LocationsSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@ -114,8 +119,8 @@ public class LocationModule extends AbstractModule {
@Region @Region
protected Supplier<Set<String>> regionIdsSupplier(AtomicReference<AuthorizationException> authException, protected Supplier<Set<String>> regionIdsSupplier(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, RegionIdFilter filter, RegionIdsSupplier uncached) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, RegionIdFilter filter, RegionIdsSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
Suppliers.compose(new FilterStrings(filter), uncached)); Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
} }
@Provides @Provides
@ -124,8 +129,8 @@ public class LocationModule extends AbstractModule {
protected Supplier<Set<String>> zoneIdsSupplier( protected Supplier<Set<String>> zoneIdsSupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
ZoneIdFilter filter, ZoneIdsSupplier uncached) { ZoneIdFilter filter, ZoneIdsSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
Suppliers.compose(new FilterStrings(filter), uncached)); Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
} }
static class FilterStrings implements Function<Set<String>, Set<String>>{ static class FilterStrings implements Function<Set<String>, Set<String>>{
@ -149,7 +154,8 @@ public class LocationModule extends AbstractModule {
protected Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier( protected Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
RegionIdToURISupplier uncached) { RegionIdToURISupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@ -157,7 +163,8 @@ public class LocationModule extends AbstractModule {
@Region @Region
protected Supplier<String> implicitRegionIdSupplier(AtomicReference<AuthorizationException> authException, protected Supplier<String> implicitRegionIdSupplier(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitRegionIdSupplier uncached) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitRegionIdSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@ -167,7 +174,8 @@ public class LocationModule extends AbstractModule {
protected Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier( protected Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
RegionIdToZoneIdsSupplier uncached) { RegionIdToZoneIdsSupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
@Provides @Provides
@ -176,6 +184,7 @@ public class LocationModule extends AbstractModule {
protected Supplier<Map<String, Supplier<URI>>> zoneIdToURISupplier( protected Supplier<Map<String, Supplier<URI>>> zoneIdToURISupplier(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
ZoneIdToURISupplier uncached) { ZoneIdToURISupplier uncached) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached); return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
TimeUnit.SECONDS);
} }
} }

View File

@ -18,15 +18,24 @@
*/ */
package org.jclouds.rest.suppliers; package org.jclouds.rest.suppliers;
import static org.jclouds.util.Suppliers2.memoizeWithExpirationAfterWrite; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
import java.io.Serializable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import com.google.common.base.Objects;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ForwardingObject;
import com.google.common.util.concurrent.UncheckedExecutionException;
/** /**
* This will retry the supplier if it encounters a timeout exception, but not if it encounters an * This will retry the supplier if it encounters a timeout exception, but not if it encounters an
@ -41,31 +50,110 @@ import com.google.common.base.Supplier;
* it is called again for each provider method that depends on it. To short-circuit this, we * it is called again for each provider method that depends on it. To short-circuit this, we
* remember the last exception trusting that guice is single-threaded. * remember the last exception trusting that guice is single-threaded.
* *
* Note this implementation is folded into the same class, vs being decorated as stacktraces are
* exceptionally long and difficult to grok otherwise. We use {@link LoadingCache} to deal with
* concurrency issues related to the supplier.
*
* @author Adrian Cole * @author Adrian Cole
*/ */
public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> implements Supplier<T> { public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> extends ForwardingObject implements
private final Supplier<T> delegate; Supplier<T>, Serializable {
private final long seconds;
/** The serialVersionUID */
private static final long serialVersionUID = 7626769175726919353L;
static class NullValueException extends RuntimeException {
/** The serialVersionUID */
private static final long serialVersionUID = 5064521423206078374L;
public static <T> MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> create(
AtomicReference<AuthorizationException> authException, long seconds, Supplier<T> delegate) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>(authException, seconds, delegate);
} }
public MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier( static class SetAndThrowAuthorizationExceptionSupplierBackedLoader<V> extends CacheLoader<String, V> implements
AtomicReference<AuthorizationException> authException, long seconds, Supplier<T> delegate) { Serializable {
this.delegate = memoizeWithExpirationAfterWrite(new RetryOnTimeOutExceptionSupplier<T>( /** The serialVersionUID */
new SetAndThrowAuthorizationExceptionSupplier<T>(delegate, authException)), seconds, TimeUnit.SECONDS); private static final long serialVersionUID = -6129510622181946809L;
this.seconds = seconds;
private final Supplier<V> delegate;
private final AtomicReference<AuthorizationException> authException;
public SetAndThrowAuthorizationExceptionSupplierBackedLoader(Supplier<V> delegate,
AtomicReference<AuthorizationException> authException) {
this.delegate = checkNotNull(delegate, "delegate");
this.authException = checkNotNull(authException, "authException");
}
@Override
public V load(String key) {
if (authException.get() != null)
throw authException.get();
try {
V value = delegate.get();
if (value == null)
throw new NullValueException();
return value;
} catch (Exception e) {
AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class);
if (aex != null) {
authException.set(aex);
throw aex;
}
throw propagate(e);
}
}
@Override
public String toString() {
return Objects.toStringHelper(this).add("delegate", delegate).toString();
}
}
private final Supplier<T> delegate;
private final long duration;
private final TimeUnit unit;
private final LoadingCache<String, T> cache;
public static <T> MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> create(
AtomicReference<AuthorizationException> authException, Supplier<T> delegate, long duration, TimeUnit unit) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>(authException, delegate, duration,
unit);
}
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(AtomicReference<AuthorizationException> authException,
Supplier<T> delegate, long duration, TimeUnit unit) {
this.delegate = delegate;
this.duration = duration;
this.unit = unit;
this.cache = CacheBuilder.newBuilder().expireAfterWrite(duration, unit)
.build(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<T>(delegate, authException));
}
@Override
protected Supplier<T> delegate() {
return delegate;
} }
@Override @Override
public T get() { public T get() {
return delegate.get(); try {
T returnVal = cache.get("FOO");
return returnVal;
} catch (UncheckedExecutionException e) {
NullValueException nullV = getFirstThrowableOfType(e, NullValueException.class);
if (nullV != null) {
return null;
}
throw propagate(e.getCause());
} catch (ExecutionException e) {
throw propagate(e.getCause());
}
} }
@Override @Override
public String toString() { public String toString() {
return "memoizeWithExpiration(" + delegate + ", seconds=" + seconds + ")"; return Objects.toStringHelper(this).add("delegate", delegate).add("duration", duration).add("unit", unit)
.toString();
} }
} }

View File

@ -24,16 +24,12 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ForwardingObject;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.io.OutputSupplier; import com.google.common.io.OutputSupplier;
@ -44,7 +40,7 @@ import com.google.common.io.OutputSupplier;
public class Suppliers2 { public class Suppliers2 {
public static <K, V> Supplier<V> getLastValueInMap(Supplier<Map<K, Supplier<V>>> input) { public static <K, V> Supplier<V> getLastValueInMap(Supplier<Map<K, Supplier<V>>> input) {
return Suppliers.compose(new Function<Map<K, Supplier<V>>, V>() { return Suppliers2.compose(new Function<Map<K, Supplier<V>>, V>() {
@Override @Override
public V apply(Map<K, Supplier<V>> input) { public V apply(Map<K, Supplier<V>> input) {
@ -86,63 +82,35 @@ public class Suppliers2 {
}; };
} }
/** // only here until guava compose gives a toString!
* same as {@link Supplier.memoizeWithExpiration} except that the expiration ticker starts after // http://code.google.com/p/guava-libraries/issues/detail?id=1052
* write vs after call to {@code get}. public static <F, T> Supplier<T> compose(Function<? super F, T> function, Supplier<F> supplier) {
* Preconditions.checkNotNull(function);
* @see Supplier.memoizeWithExpiration Preconditions.checkNotNull(supplier);
*/ return new SupplierComposition<F, T>(function, supplier);
public static <T> Supplier<T> memoizeWithExpirationAfterWrite(Supplier<T> delegate, long duration, TimeUnit unit) {
return new ExpireAfterWriteSupplier<T>(delegate, duration, unit);
} }
static class ExpireAfterWriteSupplier<T> extends ForwardingObject implements Supplier<T>, Serializable { private static class SupplierComposition<F, T> implements Supplier<T>, Serializable {
private final Supplier<T> delegate; /** The serialVersionUID */
private final long duration; private static final long serialVersionUID = 1023509665531743802L;
private final TimeUnit unit;
private final LoadingCache<Object, T> cache;
public ExpireAfterWriteSupplier(Supplier<T> delegate, long duration, TimeUnit unit) { final Function<? super F, T> function;
this.delegate = delegate; final Supplier<F> supplier;
this.duration = duration;
this.unit = unit;
cache = CacheBuilder.newBuilder().expireAfterWrite(duration, unit).build(CacheLoader.from(delegate));
}
@Override SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
protected Supplier<T> delegate() { this.function = function;
return delegate; this.supplier = supplier;
} }
@Override @Override
public T get() { public T get() {
return cache.getUnchecked("FOO"); return function.apply(supplier.get());
}
private static final long serialVersionUID = 0;
@Override
public int hashCode() {
return Objects.hashCode(delegate, duration, unit);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ExpireAfterWriteSupplier<?> that = ExpireAfterWriteSupplier.class.cast(obj);
return Objects.equal(delegate, that.delegate) && Objects.equal(duration, that.duration);
} }
@Override @Override
public String toString() { public String toString() {
return Objects.toStringHelper(this).add("delegate", delegate).add("duration", duration).add("unit", unit) return Objects.toStringHelper(this).add("function", function).add("supplier", supplier).toString();
.toString();
} }
} }
} }

View File

@ -0,0 +1,300 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.rest.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertSame;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.SetAndThrowAuthorizationExceptionSupplierBackedLoader;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/**
*
* @author Adrian Cole
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(groups = "unit", testName = "MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest")
public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest {
@Test
public void testLoaderNormal() {
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
assertEquals(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(Suppliers.ofInstance("foo"),
authException).load("KEY"), "foo");
assertEquals(authException.get(), null);
}
@Test(expectedExceptions = AuthorizationException.class)
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionType() {
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
try {
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
@Override
public String get() {
throw new AuthorizationException();
}
}, authException).load("KEY");
} finally {
assertEquals(authException.get().getClass(), AuthorizationException.class);
}
}
@Test(expectedExceptions = AuthorizationException.class)
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() {
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
try {
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
@Override
public String get() {
throw new RuntimeException(new ExecutionException(new AuthorizationException()));
}
}, authException).load("KEY");
} finally {
assertEquals(authException.get().getClass(), AuthorizationException.class);
}
}
@Test(expectedExceptions = RuntimeException.class)
public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() {
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
try {
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
@Override
public String get() {
throw new RuntimeException(new IllegalArgumentException("foo"));
}
}, authException).load("KEY");
} finally {
assertEquals(authException.get().getClass(), RuntimeException.class);
}
}
@Test
public void testMemoizeKeepsValueForFullDurationWhenDelegateCallIsSlow() {
final long SLEEP_TIME = 250;
final long EXPIRATION_TIME = 200;
Supplier<Integer> slowSupplier = new CountingSupplier() {
private static final long serialVersionUID = 1L;
@Override
public Integer get() {
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return super.get();
}
};
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
new AtomicReference<AuthorizationException>(), slowSupplier, EXPIRATION_TIME, TimeUnit.MILLISECONDS);
assertEquals(memoizedSupplier.get(), (Integer) 10);
assertEquals(memoizedSupplier.get(), (Integer) 10);
}
// =================================
//
// TODO Everything below this point is taken from SuppliersTest, to test our version of the
// Suppliers2.memoizeWithExpiration
// It should be deleted when we can switch back to using the google
// Supplier.memoizeWithExpiration.
private static class CountingSupplier implements Supplier<Integer>, Serializable {
private static final long serialVersionUID = 0L;
transient int calls = 0;
@Override
public Integer get() {
calls++;
return calls * 10;
}
}
@Test
public void testMemoizeWithExpiration() throws InterruptedException {
CountingSupplier countingSupplier = new CountingSupplier();
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
new AtomicReference<AuthorizationException>(), countingSupplier, 75, TimeUnit.MILLISECONDS);
checkExpiration(countingSupplier, memoizedSupplier);
}
@Test
public void testMemoizeWithExpirationSerialized() throws InterruptedException {
CountingSupplier countingSupplier = new CountingSupplier();
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
new AtomicReference<AuthorizationException>(), countingSupplier, 75, TimeUnit.MILLISECONDS);
// Calls to the original memoized supplier shouldn't affect its copy.
memoizedSupplier.get();
Supplier<Integer> copy = reserialize(memoizedSupplier);
memoizedSupplier.get();
CountingSupplier countingCopy = (CountingSupplier) ((MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier) copy)
.delegate();
checkExpiration(countingCopy, copy);
}
private void checkExpiration(CountingSupplier countingSupplier, Supplier<Integer> memoizedSupplier)
throws InterruptedException {
// the underlying supplier hasn't executed yet
assertEquals(0, countingSupplier.calls);
assertEquals(10, (int) memoizedSupplier.get());
// now it has
assertEquals(1, countingSupplier.calls);
assertEquals(10, (int) memoizedSupplier.get());
// it still should only have executed once due to memoization
assertEquals(1, countingSupplier.calls);
Thread.sleep(150);
assertEquals(20, (int) memoizedSupplier.get());
// old value expired
assertEquals(2, countingSupplier.calls);
assertEquals(20, (int) memoizedSupplier.get());
// it still should only have executed twice due to memoization
assertEquals(2, countingSupplier.calls);
}
@Test
public void testExpiringMemoizedSupplierThreadSafe() throws Throwable {
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer = new Function<Supplier<Boolean>, Supplier<Boolean>>() {
@Override
public Supplier<Boolean> apply(Supplier<Boolean> supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
new AtomicReference<AuthorizationException>(), supplier, Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
};
supplierThreadSafe(memoizer);
}
private void supplierThreadSafe(Function<Supplier<Boolean>, Supplier<Boolean>> memoizer) throws Throwable {
final AtomicInteger count = new AtomicInteger(0);
final AtomicReference<Throwable> thrown = new AtomicReference<Throwable>(null);
final int numThreads = 3;
final Thread[] threads = new Thread[numThreads];
final long timeout = TimeUnit.SECONDS.toNanos(60);
final Supplier<Boolean> supplier = new Supplier<Boolean>() {
boolean isWaiting(Thread thread) {
switch (thread.getState()) {
case BLOCKED:
case WAITING:
case TIMED_WAITING:
return true;
default:
return false;
}
}
int waitingThreads() {
int waitingThreads = 0;
for (Thread thread : threads) {
if (isWaiting(thread)) {
waitingThreads++;
}
}
return waitingThreads;
}
@Override
public Boolean get() {
// Check that this method is called exactly once, by the first
// thread to synchronize.
long t0 = System.nanoTime();
while (waitingThreads() != numThreads - 1) {
if (System.nanoTime() - t0 > timeout) {
thrown.set(new TimeoutException("timed out waiting for other threads to block"
+ " synchronizing on supplier"));
break;
}
Thread.yield();
}
count.getAndIncrement();
return Boolean.TRUE;
}
};
final Supplier<Boolean> memoizedSupplier = memoizer.apply(supplier);
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread() {
@Override
public void run() {
assertSame(Boolean.TRUE, memoizedSupplier.get());
}
};
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
if (thrown.get() != null) {
throw thrown.get();
}
assertEquals(1, count.get());
}
// Taken from com.google.common.testing.SerializableTester
private static <T> T reserialize(T object) {
checkNotNull(object);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -30,11 +30,10 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
/** /**
* Tests behavior of {@code SetAndThrowAuthorizationExceptionSupplier}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit") @Test(groups = "unit", testName = "MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest")
public class SetAndThrowAuthorizationExceptionSupplierTest { public class SetAndThrowAuthorizationExceptionSupplierTest {
@Test @Test
public void testNormal() { public void testNormal() {

View File

@ -56,199 +56,4 @@ public class Suppliers2Test {
assertEquals(Suppliers2.ofInstanceFunction().apply("foo").get(), "foo"); assertEquals(Suppliers2.ofInstanceFunction().apply("foo").get(), "foo");
} }
@Test
public void testMemoizeKeepsValueForFullDurationWhenDelegateCallIsSlow() {
final long SLEEP_TIME = 250;
final long EXPIRATION_TIME = 200;
Supplier<Integer> slowSupplier = new CountingSupplier() {
private static final long serialVersionUID = 1L;
@Override public Integer get() {
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return super.get();
}
};
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
slowSupplier, EXPIRATION_TIME, TimeUnit.MILLISECONDS);
assertEquals(memoizedSupplier.get(), (Integer)10);
assertEquals(memoizedSupplier.get(), (Integer)10);
}
// =================================
//
// TODO Everything below this point is taken from SuppliersTest, to test our version of the Suppliers2.memoizeWithExpiration
// It should be deleted when we can switch back to using the google Supplier.memoizeWithExpiration.
private static class CountingSupplier implements Supplier<Integer>, Serializable {
private static final long serialVersionUID = 0L;
transient int calls = 0;
@Override
public Integer get() {
calls++;
return calls * 10;
}
}
@Test
public void testMemoizeWithExpiration() throws InterruptedException {
CountingSupplier countingSupplier = new CountingSupplier();
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
countingSupplier, 75, TimeUnit.MILLISECONDS);
checkExpiration(countingSupplier, memoizedSupplier);
}
@Test
public void testMemoizeWithExpirationSerialized()
throws InterruptedException {
CountingSupplier countingSupplier = new CountingSupplier();
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
countingSupplier, 75, TimeUnit.MILLISECONDS);
// Calls to the original memoized supplier shouldn't affect its copy.
memoizedSupplier.get();
Supplier<Integer> copy = reserialize(memoizedSupplier);
memoizedSupplier.get();
CountingSupplier countingCopy = (CountingSupplier)
((Suppliers2.ExpireAfterWriteSupplier<Integer>) copy).delegate();
checkExpiration(countingCopy, copy);
}
private void checkExpiration(
CountingSupplier countingSupplier, Supplier<Integer> memoizedSupplier)
throws InterruptedException {
// the underlying supplier hasn't executed yet
assertEquals(0, countingSupplier.calls);
assertEquals(10, (int) memoizedSupplier.get());
// now it has
assertEquals(1, countingSupplier.calls);
assertEquals(10, (int) memoizedSupplier.get());
// it still should only have executed once due to memoization
assertEquals(1, countingSupplier.calls);
Thread.sleep(150);
assertEquals(20, (int) memoizedSupplier.get());
// old value expired
assertEquals(2, countingSupplier.calls);
assertEquals(20, (int) memoizedSupplier.get());
// it still should only have executed twice due to memoization
assertEquals(2, countingSupplier.calls);
}
@Test
public void testExpiringMemoizedSupplierThreadSafe() throws Throwable {
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer =
new Function<Supplier<Boolean>, Supplier<Boolean>>() {
@Override public Supplier<Boolean> apply(Supplier<Boolean> supplier) {
return Suppliers2.memoizeWithExpirationAfterWrite(
supplier, Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
};
testSupplierThreadSafe(memoizer);
}
public void testSupplierThreadSafe(
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer)
throws Throwable {
final AtomicInteger count = new AtomicInteger(0);
final AtomicReference<Throwable> thrown =
new AtomicReference<Throwable>(null);
final int numThreads = 3;
final Thread[] threads = new Thread[numThreads];
final long timeout = TimeUnit.SECONDS.toNanos(60);
final Supplier<Boolean> supplier = new Supplier<Boolean>() {
boolean isWaiting(Thread thread) {
switch (thread.getState()) {
case BLOCKED:
case WAITING:
case TIMED_WAITING:
return true;
default:
return false;
}
}
int waitingThreads() {
int waitingThreads = 0;
for (Thread thread : threads) {
if (isWaiting(thread)) {
waitingThreads++;
}
}
return waitingThreads;
}
@Override
public Boolean get() {
// Check that this method is called exactly once, by the first
// thread to synchronize.
long t0 = System.nanoTime();
while (waitingThreads() != numThreads - 1) {
if (System.nanoTime() - t0 > timeout) {
thrown.set(new TimeoutException(
"timed out waiting for other threads to block" +
" synchronizing on supplier"));
break;
}
Thread.yield();
}
count.getAndIncrement();
return Boolean.TRUE;
}
};
final Supplier<Boolean> memoizedSupplier = memoizer.apply(supplier);
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread() {
@Override public void run() {
assertSame(Boolean.TRUE, memoizedSupplier.get());
}
};
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
if (thrown.get() != null) {
throw thrown.get();
}
assertEquals(1, count.get());
}
// Taken from com.google.common.testing.SerializableTester
@SuppressWarnings("unchecked")
private static <T> T reserialize(T object) {
checkNotNull(object);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(
new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
} }

View File

@ -56,11 +56,11 @@ import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter; import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter; import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
import org.jclouds.util.Iterables2; import org.jclouds.util.Iterables2;
import org.jclouds.util.Suppliers2;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -134,7 +134,7 @@ public class SDCComputeServiceContextModule extends
@Singleton @Singleton
protected Supplier<Map<String, Location>> createLocationIndexedById( protected Supplier<Map<String, Location>> createLocationIndexedById(
@Memoized Supplier<Set<? extends Location>> locations) { @Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() { return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
@Override @Override
public Map<String, Location> apply(Set<? extends Location> arg0) { public Map<String, Location> apply(Set<? extends Location> arg0) {

View File

@ -36,6 +36,7 @@ import org.jclouds.location.Provider;
import org.jclouds.nodepool.Backend; import org.jclouds.nodepool.Backend;
import org.jclouds.rest.annotations.ApiVersion; import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.annotations.BuildVersion; import org.jclouds.rest.annotations.BuildVersion;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -117,7 +118,7 @@ public class BindBackendComputeService extends BindJcloudsModules {
@Backend @Backend
@Exposed @Exposed
protected Supplier<Template> makeBackendTemplate(@Backend Supplier<ComputeService> compute) { protected Supplier<Template> makeBackendTemplate(@Backend Supplier<ComputeService> compute) {
return Suppliers.memoize(Suppliers.compose(new Function<ComputeService, Template>() { return Suppliers.memoize(Suppliers2.compose(new Function<ComputeService, Template>() {
@Override @Override
public Template apply(ComputeService input) { public Template apply(ComputeService input) {

View File

@ -32,6 +32,7 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.filesystem.reference.FilesystemConstants; import org.jclouds.filesystem.reference.FilesystemConstants;
import org.jclouds.lifecycle.Closer; import org.jclouds.lifecycle.Closer;
import org.jclouds.nodepool.Backend; import org.jclouds.nodepool.Backend;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -51,7 +52,7 @@ public class BindInputStreamToFilesystemBlobStore extends BindJcloudsModules {
@Exposed @Exposed
protected Supplier<Map<String, InputStream>> provideInputStreamMapFromBlobStore(Supplier<BlobStoreContext> in, protected Supplier<Map<String, InputStream>> provideInputStreamMapFromBlobStore(Supplier<BlobStoreContext> in,
@Named(NodePoolProperties.METADATA_CONTAINER) final String container) { @Named(NodePoolProperties.METADATA_CONTAINER) final String container) {
return Suppliers.memoize(Suppliers.compose(new Function<BlobStoreContext, Map<String, InputStream>>() { return Suppliers.memoize(Suppliers2.compose(new Function<BlobStoreContext, Map<String, InputStream>>() {
@Override @Override
public Map<String, InputStream> apply(BlobStoreContext input) { public Map<String, InputStream> apply(BlobStoreContext input) {

View File

@ -27,8 +27,9 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.glance.v1_0.config.GlanceRestClientModule; import org.jclouds.openstack.glance.v1_0.config.GlanceRestClientModule;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata; import org.jclouds.rest.internal.BaseRestApiMetadata;
@ -86,7 +87,10 @@ public class GlanceApiMetadata extends BaseRestApiMetadata {
.version("1.0") .version("1.0")
.defaultEndpoint("http://localhost:5000") .defaultEndpoint("http://localhost:5000")
.defaultProperties(GlanceApiMetadata.defaultProperties()) .defaultProperties(GlanceApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, GlanceRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(RegionModule.class)
.add(GlanceRestClientModule.class).build());
} }
@Override @Override

View File

@ -26,10 +26,6 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.glance.v1_0.GlanceAsyncClient; import org.jclouds.openstack.glance.v1_0.GlanceAsyncClient;
import org.jclouds.openstack.glance.v1_0.GlanceClient; import org.jclouds.openstack.glance.v1_0.GlanceClient;
import org.jclouds.openstack.glance.v1_0.features.ImageAsyncClient; import org.jclouds.openstack.glance.v1_0.features.ImageAsyncClient;
@ -39,7 +35,6 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/** /**
* Configures the Glance connection. * Configures the Glance connection.
@ -63,13 +58,6 @@ public class GlanceRestClientModule extends RestClientModule<GlanceClient, Glanc
super.configure(); super.configure();
} }
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override @Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GlanceErrorHandler.class); bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GlanceErrorHandler.class);

View File

@ -26,8 +26,9 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
import org.jclouds.openstack.quantum.v1_0.config.QuantumRestClientModule; import org.jclouds.openstack.quantum.v1_0.config.QuantumRestClientModule;
import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -85,7 +86,10 @@ public class QuantumApiMetadata extends BaseRestApiMetadata {
.version("1.0") .version("1.0")
.defaultEndpoint("http://localhost:5000") .defaultEndpoint("http://localhost:5000")
.defaultProperties(QuantumApiMetadata.defaultProperties()) .defaultProperties(QuantumApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, QuantumRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(RegionModule.class)
.add(QuantumRestClientModule.class).build());
} }
@Override @Override

View File

@ -26,10 +26,6 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.quantum.v1_0.QuantumAsyncClient; import org.jclouds.openstack.quantum.v1_0.QuantumAsyncClient;
import org.jclouds.openstack.quantum.v1_0.QuantumClient; import org.jclouds.openstack.quantum.v1_0.QuantumClient;
import org.jclouds.openstack.quantum.v1_0.features.NetworkAsyncClient; import org.jclouds.openstack.quantum.v1_0.features.NetworkAsyncClient;
@ -41,7 +37,6 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/** /**
* Configures the Quantum connection. * Configures the Quantum connection.
@ -66,13 +61,6 @@ public class QuantumRestClientModule extends RestClientModule<QuantumClient, Qua
super.configure(); super.configure();
} }
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override @Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(QuantumErrorHandler.class); bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(QuantumErrorHandler.class);

View File

@ -26,8 +26,9 @@ import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
import org.jclouds.openstack.swift.v1.config.SwiftRestClientModule; import org.jclouds.openstack.swift.v1.config.SwiftRestClientModule;
import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -86,7 +87,10 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
.version("1.0") .version("1.0")
.defaultEndpoint("http://localhost:5000") .defaultEndpoint("http://localhost:5000")
.defaultProperties(SwiftApiMetadata.defaultProperties()) .defaultProperties(SwiftApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, SwiftRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(RegionModule.class)
.add(SwiftRestClientModule.class).build());
} }
@Override @Override

View File

@ -26,10 +26,6 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.swift.v1.SwiftAsyncClient; import org.jclouds.openstack.swift.v1.SwiftAsyncClient;
import org.jclouds.openstack.swift.v1.SwiftClient; import org.jclouds.openstack.swift.v1.SwiftClient;
import org.jclouds.openstack.swift.v1.features.AccountAsyncClient; import org.jclouds.openstack.swift.v1.features.AccountAsyncClient;
@ -43,7 +39,6 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/** /**
* Configures the Swift connection. * Configures the Swift connection.
@ -69,13 +64,6 @@ public class SwiftRestClientModule extends RestClientModule<SwiftClient, SwiftAs
super.configure(); super.configure();
} }
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override @Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SwiftErrorHandler.class); bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SwiftErrorHandler.class);

View File

@ -28,8 +28,11 @@ import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.KeystoneApiMetadata; import org.jclouds.openstack.keystone.v2_0.KeystoneApiMetadata;
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient; import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
import org.jclouds.openstack.keystone.v2_0.KeystoneClient; import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneParserModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes; import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityRestClientModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -85,7 +88,11 @@ public class CloudIdentityApiMetadata extends KeystoneApiMetadata {
.defaultProperties(CloudIdentityApiMetadata.defaultProperties()) .defaultProperties(CloudIdentityApiMetadata.defaultProperties())
.context(CONTEXT_TOKEN) .context(CONTEXT_TOKEN)
.documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/")) .documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/"))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudIdentityRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(CloudIdentityAuthenticationModule.class)
.add(KeystoneAdminURLModule.class)
.add(KeystoneParserModule.class)
.add(KeystoneRestClientModule.class).build());
} }
@Override @Override

View File

@ -37,7 +37,6 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Scopes; import com.google.inject.Scopes;
/** /**
@ -46,34 +45,6 @@ import com.google.inject.Scopes;
*/ */
public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationModule { public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationModule {
public CloudIdentityAuthenticationModule() {
this(new RegionModule());
}
protected CloudIdentityAuthenticationModule(Module locationModule) {
super(locationModule);
}
public static class CloudIdentityAuthenticationModuleForRegions extends CloudIdentityAuthenticationModule {
public CloudIdentityAuthenticationModuleForRegions() {
super(new RegionModule());
}
}
public static Module forRegions() {
return new CloudIdentityAuthenticationModuleForRegions();
}
public static class CloudIdentityAuthenticationModuleForZones extends CloudIdentityAuthenticationModule {
public CloudIdentityAuthenticationModuleForZones() {
super(new ZoneModule());
}
}
public static Module forZones() {
return new CloudIdentityAuthenticationModuleForZones();
}
@Override @Override
protected void bindAuthenticationClient() { protected void bindAuthenticationClient() {
// AuthenticationClient is used directly for filters and retry handlers, so let's bind it // AuthenticationClient is used directly for filters and retry handlers, so let's bind it

View File

@ -1,25 +0,0 @@
package org.jclouds.rackspace.cloudidentity.v2_0.config;
import org.jclouds.location.config.LocationModule;
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
/**
* Configures the Keystone connection.
*
* @author Adam Lowe
*/
@ConfiguresRestClient
public class CloudIdentityRestClientModule extends KeystoneRestClientModule<KeystoneClient, KeystoneAsyncClient> {
@Override
protected void installLocations() {
// TODO: select this from KeystoneProperties.VERSION; note you select from
// a guice provided property, so it will have to come from somewhere else, maybe we move
// this to the the ContextBuilder
install(CloudIdentityAuthenticationModule.forRegions());
install(new LocationModule());
}
}

View File

@ -23,11 +23,12 @@ import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CRED
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
import org.jclouds.openstack.nova.v2_0.NovaApiMetadata; import org.jclouds.openstack.nova.v2_0.NovaApiMetadata;
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule; import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.internal.BaseProviderMetadata; import org.jclouds.providers.internal.BaseProviderMetadata;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule.CloudIdentityAuthenticationModuleForZones; import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes; import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
import org.jclouds.rackspace.cloudservers.us.config.CloudServersUSComputeServiceContextModule; import org.jclouds.rackspace.cloudservers.us.config.CloudServersUSComputeServiceContextModule;
@ -77,7 +78,11 @@ public class CloudServersUSProviderMetadata extends BaseProviderMetadata {
.credentialName("API Key") .credentialName("API Key")
.version("2") .version("2")
.documentation(URI.create("http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_preface.html#webhelp-currentid")) .documentation(URI.create("http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_preface.html#webhelp-currentid"))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudIdentityAuthenticationModuleForZones.class, NovaRestClientModule.class, CloudServersUSComputeServiceContextModule.class)) .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(CloudIdentityAuthenticationModule.class)
.add(ZoneModule.class)
.add(NovaRestClientModule.class)
.add(CloudServersUSComputeServiceContextModule.class).build())
.build()) .build())
.homepage(URI.create("http://www.rackspace.com/cloud/nextgen")) .homepage(URI.create("http://www.rackspace.com/cloud/nextgen"))
.console(URI.create("https://mycloud.rackspace.com")) .console(URI.create("https://mycloud.rackspace.com"))

View File

@ -27,6 +27,7 @@ import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIME
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -62,11 +63,12 @@ import org.jclouds.savvis.vpdc.internal.VCloudToken;
import org.jclouds.savvis.vpdc.location.FirstNetwork; import org.jclouds.savvis.vpdc.location.FirstNetwork;
import org.jclouds.savvis.vpdc.predicates.TaskSuccess; import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -91,7 +93,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Provides @Provides
@Singleton @Singleton
protected Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) { protected Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
return Suppliers.compose(new Function<VCloudSession, String>() { return Suppliers2.compose(new Function<VCloudSession, String>() {
@Override @Override
public String apply(VCloudSession input) { public String apply(VCloudSession input) {
@ -106,7 +108,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Singleton @Singleton
protected Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> provideOrgs(Supplier<VCloudSession> cache, protected Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> provideOrgs(Supplier<VCloudSession> cache,
@Identity final String user) { @Identity final String user) {
return Suppliers.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() { return Suppliers2.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() {
@Override @Override
public Set<org.jclouds.savvis.vpdc.domain.Resource> apply(VCloudSession input) { public Set<org.jclouds.savvis.vpdc.domain.Resource> apply(VCloudSession input) {
@ -122,7 +124,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Singleton @Singleton
protected Supplier<String> provideDefaultOrgId( protected Supplier<String> provideDefaultOrgId(
@org.jclouds.savvis.vpdc.internal.Org Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> orgs) { @org.jclouds.savvis.vpdc.internal.Org Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> orgs) {
return Suppliers.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() { return Suppliers2.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() {
@Override @Override
public String apply(Set<org.jclouds.savvis.vpdc.domain.Resource> input) { public String apply(Set<org.jclouds.savvis.vpdc.domain.Resource> input) {
@ -163,15 +165,18 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Singleton @Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final LoginClient login) { final LoginClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<VCloudSession>() { new Supplier<VCloudSession>() {
@Override @Override
public VCloudSession get() { public VCloudSession get() {
return login.login(); return login.login();
} }
@Override
}); public String toString() {
return Objects.toStringHelper(login).add("method", "login").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
@Override @Override

View File

@ -40,6 +40,7 @@ import org.jclouds.rest.RestContext;
import org.jclouds.rest.config.BinderUtils; import org.jclouds.rest.config.BinderUtils;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.util.Suppliers2;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
import org.jclouds.vcloud.director.v1_5.annotations.Login; import org.jclouds.vcloud.director.v1_5.annotations.Login;
@ -93,7 +94,6 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -187,7 +187,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
@Login @Login
protected Supplier<URI> loginUrl(@Provider Supplier<URI> provider) { protected Supplier<URI> loginUrl(@Provider Supplier<URI> provider) {
// TODO: technically, we should implement version client, but this will work // TODO: technically, we should implement version client, but this will work
return Suppliers.compose(new Function<URI, URI>() { return Suppliers2.compose(new Function<URI, URI>() {
@Override @Override
public URI apply(URI arg0) { public URI apply(URI arg0) {
@ -199,7 +199,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
@Provides @Provides
protected Supplier<Session> currentSession(Supplier<SessionWithToken> in) { protected Supplier<Session> currentSession(Supplier<SessionWithToken> in) {
return Suppliers.compose(new Function<SessionWithToken, Session>() { return Suppliers2.compose(new Function<SessionWithToken, Session>() {
@Override @Override
public Session apply(SessionWithToken arg0) { public Session apply(SessionWithToken arg0) {
@ -214,7 +214,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
@Singleton @Singleton
@org.jclouds.vcloud.director.v1_5.annotations.Session @org.jclouds.vcloud.director.v1_5.annotations.Session
protected Supplier<String> sessionToken(Supplier<SessionWithToken> in) { protected Supplier<String> sessionToken(Supplier<SessionWithToken> in) {
return Suppliers.compose(new Function<SessionWithToken, String>() { return Suppliers2.compose(new Function<SessionWithToken, String>() {
@Override @Override
public String apply(SessionWithToken arg0) { public String apply(SessionWithToken arg0) {

View File

@ -30,7 +30,8 @@ import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.hpcloud.compute.config.HPCloudComputeServiceContextModule; import org.jclouds.hpcloud.compute.config.HPCloudComputeServiceContextModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForZones; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
import org.jclouds.openstack.nova.v2_0.NovaApiMetadata; import org.jclouds.openstack.nova.v2_0.NovaApiMetadata;
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule; import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.ProviderMetadata;
@ -87,7 +88,11 @@ public class HPCloudComputeProviderMetadata extends BaseProviderMetadata {
.apiMetadata(new NovaApiMetadata().toBuilder() .apiMetadata(new NovaApiMetadata().toBuilder()
.identityName("yourTenantName:yourAccessKey") .identityName("yourTenantName:yourAccessKey")
.credentialName("secretKey") .credentialName("secretKey")
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForZones.class,NovaRestClientModule.class, HPCloudComputeServiceContextModule.class)) .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneAuthenticationModule.class)
.add(ZoneModule.class)
.add(NovaRestClientModule.class)
.add(HPCloudComputeServiceContextModule.class).build())
.build()) .build())
.homepage(URI.create("http://hpcloud.com")) .homepage(URI.create("http://hpcloud.com"))
.console(URI.create("https://manage.hpcloud.com/compute")) .console(URI.create("https://manage.hpcloud.com/compute"))

View File

@ -29,6 +29,7 @@ import org.jclouds.apis.ApiMetadata;
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule; import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule; import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.SwiftApiMetadata; import org.jclouds.openstack.swift.SwiftApiMetadata;
@ -89,7 +90,11 @@ public class HPCloudObjectStorageApiMetadata extends SwiftApiMetadata {
.documentation(URI.create("https://build.hpcloud.com/object-storage/api")) .documentation(URI.create("https://build.hpcloud.com/object-storage/api"))
.defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties()) .defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties())
.context(CONTEXT_TOKEN) .context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, HPCloudObjectStorageRestClientModule.class, HPCloudObjectStorageBlobStoreContextModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(KeystoneStorageEndpointModule.class)
.add(RegionModule.class)
.add(HPCloudObjectStorageRestClientModule.class)
.add(HPCloudObjectStorageBlobStoreContextModule.class).build());
} }
@Override @Override

View File

@ -31,11 +31,7 @@ import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient;
import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient;
import org.jclouds.hpcloud.services.HPExtensionCDN; import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.hpcloud.services.HPExtensionServiceType; import org.jclouds.hpcloud.services.HPExtensionServiceType;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.config.SwiftRestClientModule; import org.jclouds.openstack.swift.config.SwiftRestClientModule;
@ -68,13 +64,6 @@ public class HPCloudObjectStorageRestClientModule extends
bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON); bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON);
} }
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Provides @Provides
@Singleton @Singleton
@HPExtensionCDN @HPExtensionCDN

View File

@ -25,6 +25,7 @@ import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME; import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME;
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES; import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
@ -54,6 +55,7 @@ import org.jclouds.softlayer.features.AccountClient;
import org.jclouds.softlayer.features.ProductPackageClient; import org.jclouds.softlayer.features.ProductPackageClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -95,7 +97,7 @@ public class SoftLayerComputeServiceContextModule extends
public Supplier<ProductPackage> getProductPackage(AtomicReference<AuthorizationException> authException, public Supplier<ProductPackage> getProductPackage(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerClient client, @Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerClient client,
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) { @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<ProductPackage>(authException, seconds, return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
new Supplier<ProductPackage>() { new Supplier<ProductPackage>() {
@Override @Override
public ProductPackage get() { public ProductPackage get() {
@ -104,7 +106,13 @@ public class SoftLayerComputeServiceContextModule extends
ProductPackage p = find(accountClient.getActivePackages(), named(virtualGuestPackageName)); ProductPackage p = find(accountClient.getActivePackages(), named(virtualGuestPackageName));
return productPackageClient.getProductPackage(p.getId()); return productPackageClient.getProductPackage(p.getId());
} }
});
@Override
public String toString() {
return Objects.toStringHelper(client).add("method", "accountClient.getActivePackages")
.add("method", "productPackageClient.getProductPackage").toString();
}
}, seconds, TimeUnit.SECONDS);
} }
// TODO: check the prices really do exist // TODO: check the prices really do exist