Issue 763: set image cache expiry using PROPERTY_SESSION_INTERVAL

This commit is contained in:
Aled Sage 2011-12-07 00:37:44 +00:00 committed by Adrian Cole
parent a45e16ebb3
commit 741773f9ab
3 changed files with 10 additions and 8 deletions

View File

@ -19,7 +19,6 @@
package org.jclouds.ec2.compute.config; package org.jclouds.ec2.compute.config;
import static com.google.common.collect.Iterables.toArray; import static com.google.common.collect.Iterables.toArray;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -37,7 +36,6 @@ import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.functions.RegionAndIdToImage; import org.jclouds.ec2.compute.functions.RegionAndIdToImage;
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier; import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -69,7 +67,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
@Provides @Provides
@Singleton @Singleton
protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache( protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) { final RegionAndNameToImageSupplier supplier) {
return supplier; return supplier;
} }

View File

@ -18,7 +18,12 @@
*/ */
package org.jclouds.ec2.compute.suppliers; package org.jclouds.ec2.compute.suppliers;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
@ -38,8 +43,9 @@ public class RegionAndNameToImageSupplier implements Supplier<Cache<RegionAndNam
private final Cache<RegionAndName, Image> cache; private final Cache<RegionAndName, Image> cache;
@Inject @Inject
protected RegionAndNameToImageSupplier(CacheLoader<RegionAndName, Image> regionAndIdToImage) { protected RegionAndNameToImageSupplier(CacheLoader<RegionAndName, Image> regionAndIdToImage,
cache = CacheBuilder.newBuilder().build(regionAndIdToImage); @Named(PROPERTY_SESSION_INTERVAL) long expirationSecs) {
cache = CacheBuilder.newBuilder().expireAfterWrite(expirationSecs, TimeUnit.SECONDS).build(regionAndIdToImage);
} }
@Override @Override

View File

@ -18,13 +18,11 @@
*/ */
package org.jclouds.aws.ec2.compute.config; package org.jclouds.aws.ec2.compute.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX; import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.AWSEC2PropertiesBuilder; import org.jclouds.aws.ec2.AWSEC2PropertiesBuilder;
@ -131,7 +129,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext
@Provides @Provides
@Singleton @Singleton
protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache( protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) { final RegionAndNameToImageSupplier supplier) {
return supplier; return supplier;
} }