diff --git a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index f5e9fd05ef..ef434dcd72 100644 --- a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -45,7 +45,7 @@ import org.jclouds.util.CredentialUtils; import com.google.common.base.CaseFormat; import com.google.common.base.Splitter; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; import com.google.inject.Provider; @@ -55,7 +55,7 @@ import com.google.inject.Provider; */ public class ComputeTask extends Task { - private final Cache computeMap; + private final LoadingCache computeMap; private String provider; private String actions; private NodeElement nodeElement; @@ -71,7 +71,7 @@ public class ComputeTask extends Task { } }; - public ComputeTask(@Nullable Cache computeMap) { + public ComputeTask(@Nullable LoadingCache computeMap) { this.computeMap = computeMap != null ? computeMap : buildComputeMap(projectProvider); } diff --git a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 06022ad5a2..1c538eff7e 100644 --- a/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -43,7 +43,7 @@ import org.jclouds.tools.ant.logging.config.AntLoggingModule; import com.google.common.base.Charsets; import com.google.common.base.Splitter; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableSet; @@ -67,7 +67,7 @@ public class ComputeTaskUtils { * allows access to the ant project to retrieve default properties needed for compute * providers. */ - static Cache buildComputeMap(final Provider projectProvider) { + static LoadingCache buildComputeMap(final Provider projectProvider) { return CacheBuilder.newBuilder().build(new CacheLoader() { @SuppressWarnings("unchecked") diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java index 64303d6ad0..18c1b084be 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosAsyncBlobStore.java @@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.atmos.options.PutOptions.Builder.publicRead; import java.net.URI; -import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -64,6 +63,8 @@ import org.jclouds.http.options.GetOptions; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.ListenableFuture; /** @@ -81,7 +82,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { private final Crypto crypto; private final BlobToHttpGetOptions blob2ObjectGetOptions; private final Provider fetchBlobMetadataProvider; - private final Map isPublic; + private final LoadingCache isPublic; @Inject AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, @@ -91,7 +92,7 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { BlobStoreListOptionsToListOptions container2ContainerListOptions, DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider, - Map isPublic) { + LoadingCache isPublic) { super(context, blobUtils, service, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); @@ -238,10 +239,10 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore { public ListenableFuture putBlob(final String container, final Blob blob) { final org.jclouds.atmos.options.PutOptions options = new org.jclouds.atmos.options.PutOptions(); try { - if (isPublic.get(container + "/")) + if (isPublic.getUnchecked(container + "/")) options.publicRead(); - } catch (NullPointerException e) { - // MapMaker + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted } return Futures.makeListenable(service.submit(new Callable() { diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java index 1fd1deef69..4ba8c4b63b 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobStore.java @@ -21,7 +21,6 @@ package org.jclouds.atmos.blobstore; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.atmos.options.PutOptions.Builder.publicRead; -import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -54,6 +53,8 @@ import org.jclouds.domain.Location; import org.jclouds.http.options.GetOptions; import com.google.common.base.Supplier; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * @author Adrian Cole @@ -69,7 +70,7 @@ public class AtmosBlobStore extends BaseBlobStore { private final Crypto crypto; private final BlobToHttpGetOptions blob2ObjectGetOptions; private final Provider fetchBlobMetadataProvider; - private final Map isPublic; + private final LoadingCache isPublic; @Inject AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @@ -78,7 +79,7 @@ public class AtmosBlobStore extends BaseBlobStore { BlobStoreListOptionsToListOptions container2ContainerListOptions, DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto, BlobToHttpGetOptions blob2ObjectGetOptions, Provider fetchBlobMetadataProvider, - Map isPublic) { + LoadingCache isPublic) { super(context, blobUtils, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); @@ -212,10 +213,10 @@ public class AtmosBlobStore extends BaseBlobStore { public String putBlob(final String container, final Blob blob) { final org.jclouds.atmos.options.PutOptions options = new org.jclouds.atmos.options.PutOptions(); try { - if (isPublic.get(container + "/")) + if (isPublic.getUnchecked(container + "/")) options.publicRead(); - } catch (NullPointerException e) { - // MapMaker + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted } return AtmosUtils.putBlob(sync, crypto, blob2Object, container, blob, options); } diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreContextModule.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreContextModule.java index 8f05d08a08..017d1a8ebe 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreContextModule.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/config/AtmosBlobStoreContextModule.java @@ -18,7 +18,6 @@ */ package org.jclouds.atmos.blobstore.config; -import java.util.Map; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; @@ -39,8 +38,9 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.location.config.JustProviderLocationModule; -import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Scopes; @@ -68,16 +68,18 @@ public class AtmosBlobStoreContextModule extends AbstractModule { @Provides @Singleton - protected Map isPublic(final AtmosClient client) { - return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function() { - public Boolean apply(String directory) { - return client.isPublic(directory); - } + protected LoadingCache isPublic(final AtmosClient client) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader() { @Override public String toString() { return "isPublic()"; } + + @Override + public Boolean load(String arg0) throws Exception { + return client.isPublic(arg0); + } }); } } diff --git a/apis/byon/src/main/java/org/jclouds/byon/config/BYONComputeServiceContextModule.java b/apis/byon/src/main/java/org/jclouds/byon/config/BYONComputeServiceContextModule.java index 7bff8b097d..fc1707c043 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/config/BYONComputeServiceContextModule.java +++ b/apis/byon/src/main/java/org/jclouds/byon/config/BYONComputeServiceContextModule.java @@ -34,7 +34,7 @@ import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -53,7 +53,7 @@ public class BYONComputeServiceContextModule extends @Provides @Singleton - Supplier provideApi(Supplier> in) { + Supplier provideApi(Supplier> in) { return in; } diff --git a/apis/byon/src/main/java/org/jclouds/byon/config/CacheNodeStoreModule.java b/apis/byon/src/main/java/org/jclouds/byon/config/CacheNodeStoreModule.java index 7e33379cec..12ea397d3e 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/config/CacheNodeStoreModule.java +++ b/apis/byon/src/main/java/org/jclouds/byon/config/CacheNodeStoreModule.java @@ -28,7 +28,7 @@ import com.google.common.annotations.Beta; import com.google.common.base.Functions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.inject.AbstractModule; @@ -41,9 +41,9 @@ import com.google.inject.TypeLiteral; @ConfiguresNodeStore @Beta public class CacheNodeStoreModule extends AbstractModule { - private final Cache backing; + private final LoadingCache backing; - public CacheNodeStoreModule(Cache backing) { + public CacheNodeStoreModule(LoadingCache backing) { this.backing = checkNotNull(backing, "backing"); } @@ -55,10 +55,10 @@ public class CacheNodeStoreModule extends AbstractModule { @Override protected void configure() { - bind(new TypeLiteral>() { + bind(new TypeLiteral>() { }).toInstance(backing); - bind(new TypeLiteral>>() { - }).toInstance(Suppliers.> ofInstance(backing)); + bind(new TypeLiteral>>() { + }).toInstance(Suppliers.> ofInstance(backing)); } } \ No newline at end of file diff --git a/apis/byon/src/main/java/org/jclouds/byon/config/ConfiguresNodeStore.java b/apis/byon/src/main/java/org/jclouds/byon/config/ConfiguresNodeStore.java index 319cf76fcd..6962269c76 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/config/ConfiguresNodeStore.java +++ b/apis/byon/src/main/java/org/jclouds/byon/config/ConfiguresNodeStore.java @@ -27,7 +27,7 @@ import java.lang.annotation.Target; import com.google.common.annotations.Beta; /** - * designates the module configures a {@code Cache} + * designates the module configures a {@code LoadingCache} * * @author Adrian Cole * diff --git a/apis/byon/src/main/java/org/jclouds/byon/config/YamlNodeStoreModule.java b/apis/byon/src/main/java/org/jclouds/byon/config/YamlNodeStoreModule.java index cd902170fc..3f61d70927 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/config/YamlNodeStoreModule.java +++ b/apis/byon/src/main/java/org/jclouds/byon/config/YamlNodeStoreModule.java @@ -38,7 +38,7 @@ import com.google.common.annotations.Beta; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.io.InputSupplier; @@ -67,9 +67,9 @@ public class YamlNodeStoreModule extends AbstractModule { @Override protected void configure() { - bind(new TypeLiteral>>() { + bind(new TypeLiteral>>() { }).to(NodesParsedFromSupplier.class); - bind(new TypeLiteral>>() { + bind(new TypeLiteral>>() { }).to(NodesFromYamlStream.class); bind(new TypeLiteral>() { }).toInstance(org.jclouds.byon.domain.YamlNode.yamlNodeToInputStream); @@ -103,7 +103,7 @@ public class YamlNodeStoreModule extends AbstractModule { @Provides @Singleton - protected Cache provideNodeStore(Map backing, Function yamlSerializer, + protected LoadingCache provideNodeStore(Map backing, Function yamlSerializer, Function yamlDeserializer) { return CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(new TransformingMap(backing, yamlDeserializer, yamlSerializer)))); } diff --git a/apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYamlStream.java b/apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYamlStream.java index 880457d349..9505b7f1c2 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYamlStream.java +++ b/apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYamlStream.java @@ -35,7 +35,7 @@ import org.yaml.snakeyaml.constructor.Constructor; import com.google.common.base.Function; import com.google.common.base.Functions; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Iterables; @@ -69,7 +69,7 @@ import com.google.common.collect.Maps; * @author Adrian Cole */ @Singleton -public class NodesFromYamlStream implements Function> { +public class NodesFromYamlStream implements Function> { /** * Type-safe config class for YAML @@ -80,7 +80,7 @@ public class NodesFromYamlStream implements Function apply(InputStream source) { + public LoadingCache apply(InputStream source) { Constructor constructor = new Constructor(Config.class); @@ -105,7 +105,7 @@ public class NodesFromYamlStream implements Function cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); + LoadingCache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); for (String node : backingMap.keySet()) cache.getUnchecked(node); return cache; diff --git a/apis/byon/src/main/java/org/jclouds/byon/internal/BYONComputeServiceAdapter.java b/apis/byon/src/main/java/org/jclouds/byon/internal/BYONComputeServiceAdapter.java index 3793aa6482..5a8d676804 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/internal/BYONComputeServiceAdapter.java +++ b/apis/byon/src/main/java/org/jclouds/byon/internal/BYONComputeServiceAdapter.java @@ -40,7 +40,7 @@ import org.jclouds.location.suppliers.JustProvider; import com.google.common.base.Function; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; @@ -52,12 +52,12 @@ import com.google.common.util.concurrent.UncheckedExecutionException; */ @Singleton public class BYONComputeServiceAdapter implements JCloudsNativeComputeServiceAdapter { - private final Supplier> nodes; + private final Supplier> nodes; private final NodeToNodeMetadata converter; private final JustProvider locationSupplier; @Inject - public BYONComputeServiceAdapter(Supplier> nodes, NodeToNodeMetadata converter, + public BYONComputeServiceAdapter(Supplier> nodes, NodeToNodeMetadata converter, JustProvider locationSupplier) { this.nodes = checkNotNull(nodes, "nodes"); this.converter = checkNotNull(converter, "converter"); diff --git a/apis/byon/src/main/java/org/jclouds/byon/suppliers/NodesParsedFromSupplier.java b/apis/byon/src/main/java/org/jclouds/byon/suppliers/NodesParsedFromSupplier.java index 0cbf0e532a..2570aaef85 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/suppliers/NodesParsedFromSupplier.java +++ b/apis/byon/src/main/java/org/jclouds/byon/suppliers/NodesParsedFromSupplier.java @@ -33,29 +33,29 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; /** * * @author Adrian Cole */ @Singleton -public class NodesParsedFromSupplier implements Supplier> { +public class NodesParsedFromSupplier implements Supplier> { @Resource protected Logger logger = Logger.NULL; private final Supplier supplier; - private final Function> parser; + private final Function> parser; @Inject - NodesParsedFromSupplier(@Provider Supplier supplier, Function> parser) { + NodesParsedFromSupplier(@Provider Supplier supplier, Function> parser) { this.supplier = checkNotNull(supplier, "supplier"); this.parser = checkNotNull(parser, "parser"); } @Override - public Cache get() { - Cache nodes = parser.apply(supplier.get()); + public LoadingCache get() { + LoadingCache nodes = parser.apply(supplier.get()); checkState(nodes != null && nodes.size() > 0, "no nodes parsed from supplier: %s", supplier); return nodes; } diff --git a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java index e284a62484..2a86fb13d0 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/BYONComputeServiceTest.java @@ -36,7 +36,7 @@ import org.jclouds.domain.LoginCredentials; import org.testng.annotations.Test; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -79,7 +79,7 @@ public class BYONComputeServiceTest { assertEquals(context.getProviderSpecificContext().getEndpoint(), URI.create(endpoint)); @SuppressWarnings("unchecked") - Supplier> supplier = (Supplier>) context.getProviderSpecificContext() + Supplier> supplier = (Supplier>) context.getProviderSpecificContext() .getApi(); assertEquals(supplier.get().size(), context.getComputeService().listNodes().size()); @@ -107,7 +107,7 @@ public class BYONComputeServiceTest { assertEquals(context.getProviderSpecificContext().getEndpoint(), URI.create(endpoint)); @SuppressWarnings("unchecked") - Supplier> supplier = (Supplier>) context.getProviderSpecificContext() + Supplier> supplier = (Supplier>) context.getProviderSpecificContext() .getApi(); assertEquals(supplier.get().size(), context.getComputeService().listNodes().size()); diff --git a/apis/byon/src/test/java/org/jclouds/byon/config/CacheNodeStoreModuleTest.java b/apis/byon/src/test/java/org/jclouds/byon/config/CacheNodeStoreModuleTest.java index af64f18645..a59d08a051 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/config/CacheNodeStoreModuleTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/config/CacheNodeStoreModuleTest.java @@ -32,7 +32,7 @@ import org.testng.annotations.Test; import com.google.common.base.Functions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Maps; @@ -70,9 +70,9 @@ public class CacheNodeStoreModuleTest { Map map = Maps.newConcurrentMap(); Injector injector = createInjectorWithProvidedMap(map); - assertEquals(injector.getInstance(Key.get(new TypeLiteral>() { + assertEquals(injector.getInstance(Key.get(new TypeLiteral>() { })).asMap(), map); - Cache store = getStore(injector); + LoadingCache store = getStore(injector); for (int i = 0; i < 10; i++) check(map, store, "test" + i, "instance1" + i, "instancename" + i); @@ -92,7 +92,7 @@ public class CacheNodeStoreModuleTest { public void testProvidedCacheConsistentAcrossMultipleInjectors() throws IOException { Map map = Maps.newConcurrentMap(); - Cache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(map))); + LoadingCache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(map))); put(map, getStore(createInjectorWithProvidedCache(cache)), "test", "instance1", "instancename"); checkConsistent(map, getStore(createInjectorWithProvidedCache(cache)), "test", "instance1", "instancename"); @@ -101,8 +101,8 @@ public class CacheNodeStoreModuleTest { } - private Cache getStore(Injector injector) { - return injector.getInstance(Key.get(new TypeLiteral>() { + private LoadingCache getStore(Injector injector) { + return injector.getInstance(Key.get(new TypeLiteral>() { })); } @@ -118,7 +118,7 @@ public class CacheNodeStoreModuleTest { }); } - private Injector createInjectorWithProvidedCache(Cache cache) { + private Injector createInjectorWithProvidedCache(LoadingCache cache) { return Guice.createInjector(new CacheNodeStoreModule(cache), new AbstractModule() { @Override @@ -130,14 +130,14 @@ public class CacheNodeStoreModuleTest { }); } - private void check(Map map, Cache store, String key, String id, String name) + private void check(Map map, LoadingCache store, String key, String id, String name) throws IOException { put(map, store, key, id, name); checkConsistent(map, store, key, id, name); remove(map, store, key); } - private void remove(Map map, Cache store, String key) { + private void remove(Map map, LoadingCache store, String key) { store.invalidate(key); assertEquals(store.size(), 0); map.remove(key); @@ -151,7 +151,7 @@ public class CacheNodeStoreModuleTest { assertEquals(map.get(key), null); } - private void checkConsistent(Map map, Cache store, String key, String id, String name) + private void checkConsistent(Map map, LoadingCache store, String key, String id, String name) throws IOException { assertEquals(map.size(), 1); if (store.size() == 0) @@ -162,7 +162,7 @@ public class CacheNodeStoreModuleTest { assertEquals(store.getUnchecked(key), Node.builder().id(id).name(name).build()); } - private void put(Map map, Cache store, String key, String id, String name) { + private void put(Map map, LoadingCache store, String key, String id, String name) { assertEquals(store.size(), 0); assertEquals(map.size(), 0); map.put(key, Node.builder().id(id).name(name).build()); diff --git a/apis/byon/src/test/java/org/jclouds/byon/config/YamlNodeStoreModuleTest.java b/apis/byon/src/test/java/org/jclouds/byon/config/YamlNodeStoreModuleTest.java index 97e285f8dc..dc7acbc993 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/config/YamlNodeStoreModuleTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/config/YamlNodeStoreModuleTest.java @@ -36,7 +36,7 @@ import org.yaml.snakeyaml.Yaml; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.io.InputSupplier; import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.inject.AbstractModule; @@ -85,7 +85,7 @@ public class YamlNodeStoreModuleTest { Injector injector = createInjectorWithProvidedMap(map); assertEquals(injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("yaml"))), map); - Cache store = getStore(injector); + LoadingCache store = getStore(injector); for (int i = 0; i < 10; i++) check(map, store, "test" + i, "instance1" + i, "instancename" + i); @@ -114,8 +114,8 @@ public class YamlNodeStoreModuleTest { } - protected Cache getStore(Injector injector) { - return injector.getInstance(Key.get(new TypeLiteral>() { + protected LoadingCache getStore(Injector injector) { + return injector.getInstance(Key.get(new TypeLiteral>() { })); } @@ -148,14 +148,14 @@ public class YamlNodeStoreModuleTest { }); } - protected void check(Map map, Cache store, String key, String id, String name) + protected void check(Map map, LoadingCache store, String key, String id, String name) throws IOException { put(map, store, key, id, name); checkConsistent(map, store, key, id, name); remove(map, store, key); } - protected void remove(Map map, Cache store, String key) { + protected void remove(Map map, LoadingCache store, String key) { store.invalidate(key); assertEquals(store.size(), 0); map.remove(key); @@ -169,7 +169,7 @@ public class YamlNodeStoreModuleTest { assertEquals(map.get(key), null); } - protected void checkConsistent(Map map, Cache store, String key, String id, + protected void checkConsistent(Map map, LoadingCache store, String key, String id, String name) throws IOException { assertEquals(map.size(), 1); if (store.size() == 0) @@ -187,7 +187,7 @@ public class YamlNodeStoreModuleTest { assertEquals(Strings2.toStringAndClose(map.get(key)), String.format("id: %s\nname: %s\n", id, name)); } - protected void put(Map map, Cache store, String key, String id, String name) { + protected void put(Map map, LoadingCache store, String key, String id, String name) { assertEquals(store.size(), 0); assertEquals(map.size(), 0); map.put(key, new ByteArrayInputStream(String.format("id: %s\nname: %s\n", id, name).getBytes())); diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java index b0420e07da..c9b64d196a 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/config/CloudFilesBlobStoreContextModule.java @@ -19,7 +19,6 @@ package org.jclouds.cloudfiles.blobstore.config; import java.net.URI; -import java.util.Map; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; @@ -34,8 +33,9 @@ import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; -import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.inject.Provides; /** @@ -46,9 +46,10 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul @Provides @Singleton - protected Map cdnContainer(final CloudFilesClient client) { - return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function() { - public URI apply(String container) { + protected LoadingCache cdnContainer(final CloudFilesClient client) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader() { + @Override + public URI load(String container) { ContainerCDNMetadata md = client.getCDNMetadata(container); return md != null ? md.getCDNUri() : null; } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/EnableCDNAndCache.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/EnableCDNAndCache.java index 4cc8bdae4e..74a490b80c 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/EnableCDNAndCache.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/EnableCDNAndCache.java @@ -19,7 +19,6 @@ package org.jclouds.cloudfiles.blobstore.functions; import java.net.URI; -import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; @@ -27,6 +26,7 @@ import javax.inject.Singleton; import org.jclouds.cloudfiles.CloudFilesClient; import com.google.common.base.Function; +import com.google.common.cache.LoadingCache; /** * @@ -34,11 +34,11 @@ import com.google.common.base.Function; */ @Singleton public class EnableCDNAndCache implements Function { - private final Map cdnContainer; + private final LoadingCache cdnContainer; private final CloudFilesClient sync; @Inject - public EnableCDNAndCache(CloudFilesClient sync, Map cdnContainer) { + public EnableCDNAndCache(CloudFilesClient sync, LoadingCache cdnContainer) { this.sync = sync; this.cdnContainer = cdnContainer; } diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java index f5375b25ad..d7c7f5d0e6 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java @@ -19,7 +19,6 @@ package org.jclouds.cloudfiles.blobstore.functions; import java.net.URI; -import java.util.Map; import javax.inject.Inject; import javax.inject.Provider; @@ -29,17 +28,19 @@ import javax.ws.rs.core.UriBuilder; import org.jclouds.openstack.swift.domain.ObjectInfo; import com.google.common.base.Function; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * @author Adrian Cole */ @Singleton public class PublicUriForObjectInfo implements Function { - private final Map cdnContainer; + private final LoadingCache cdnContainer; private final Provider uriBuilders; @Inject - public PublicUriForObjectInfo(Map cdnContainer, Provider uriBuilders) { + public PublicUriForObjectInfo(LoadingCache cdnContainer, Provider uriBuilders) { this.cdnContainer = cdnContainer; this.uriBuilders = uriBuilders; } @@ -48,10 +49,10 @@ public class PublicUriForObjectInfo implements Function { if (from == null) return null; try { - return uriBuilders.get().uri(cdnContainer.get(from.getContainer())).path(from.getName()).replaceQuery("") + return uriBuilders.get().uri(cdnContainer.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("") .build(); - } catch (NullPointerException e) { - // MapMaker constructed maps are not allowed to return null; + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted from cache loader return null; } } diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java index 1784adeaa3..4221058ece 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java @@ -58,7 +58,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -86,7 +86,7 @@ public class CloudSigmaComputeServiceAdapter implements private final Predicate driveNotClaimed; private final JustProvider locationSupplier; private final String defaultVncPassword; - private final Cache cache; + private final LoadingCache cache; private final ExecutorService executor; @Resource @@ -96,7 +96,7 @@ public class CloudSigmaComputeServiceAdapter implements @Inject public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, Predicate driveNotClaimed, JustProvider locationSupplier, @Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, - Cache cache, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + LoadingCache cache, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.client = checkNotNull(client, "client"); this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed"); this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier"); diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java index 7438373f54..730ec4f3a3 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/config/CloudSigmaComputeServiceContextModule.java @@ -56,7 +56,7 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.inject.Injector; @@ -108,7 +108,7 @@ public class CloudSigmaComputeServiceContextModule @Provides @Singleton - protected Cache cache(GetDrive getDrive) { + protected LoadingCache cache(GetDrive getDrive) { return CacheBuilder.newBuilder().build(getDrive); } diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java index 4e7ca2bbcb..4c433c92c4 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/functions/ServerInfoToNodeMetadata.java @@ -49,7 +49,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -114,10 +114,10 @@ public class ServerInfoToNodeMetadata implements Function cache; + private final LoadingCache cache; @Inject - public DeviceToVolume(Cache cache) { + public DeviceToVolume(LoadingCache cache) { this.cache = checkNotNull(cache, "cache"); } @@ -149,10 +149,10 @@ public class ServerInfoToNodeMetadata implements Function cache; + private final LoadingCache cache; @Inject - public GetImageIdFromServer(Cache cache) { + public GetImageIdFromServer(LoadingCache cache) { this.cache = cache; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java index daf3ef54ae..8869ef3c4d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java @@ -67,7 +67,7 @@ import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExc import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Maps; @@ -173,7 +173,7 @@ public class CloudStackComputeServiceContextModule @Provides @Singleton - protected Cache> getIPForwardingRulesByVirtualMachine( + protected LoadingCache> getIPForwardingRulesByVirtualMachine( CacheLoader> getIPForwardingRules) { return CacheBuilder.newBuilder().build(getIPForwardingRules); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java index 1ad575afbd..8650847b91 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java @@ -48,7 +48,7 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.UncheckedExecutionException; @@ -74,13 +74,13 @@ public class VirtualMachineToNodeMetadata implements Function> getIPForwardingRulesByVirtualMachine; + private final LoadingCache> getIPForwardingRulesByVirtualMachine; @Inject VirtualMachineToNodeMetadata(FindLocationForVirtualMachine findLocationForVirtualMachine, FindHardwareForVirtualMachine findHardwareForVirtualMachine, FindImageForVirtualMachine findImageForVirtualMachine, - Cache> getIPForwardingRulesByVirtualMachine) { + LoadingCache> getIPForwardingRulesByVirtualMachine) { this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine"); this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine"); this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine"); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java index db878e39fc..b9cfdab79e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java @@ -61,7 +61,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Sets; @@ -86,7 +86,7 @@ public class CloudStackComputeServiceAdapter implements private final BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult; private final Factory staticNATVMInNetwork; private final CreatePortForwardingRulesForIP setupPortForwardingRulesForIP; - private final Cache> vmToRules; + private final LoadingCache> vmToRules; private final Map credentialStore; @Inject @@ -94,7 +94,7 @@ public class CloudStackComputeServiceAdapter implements @Memoized Supplier> networkSupplier, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult, StaticNATVirtualMachineInNetwork.Factory staticNATVMInNetwork, - CreatePortForwardingRulesForIP setupPortForwardingRulesForIP, Cache> vmToRules, + CreatePortForwardingRulesForIP setupPortForwardingRulesForIP, LoadingCache> vmToRules, Map credentialStore) { this.client = checkNotNull(client, "client"); this.jobComplete = checkNotNull(jobComplete, "jobComplete"); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java index 8259bed029..9bfccf51ea 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java @@ -36,7 +36,7 @@ import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; @@ -54,12 +54,12 @@ public class CreatePortForwardingRulesForIP { private final CloudStackClient client; private final BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult; - private final Cache> getIPForwardingRulesByVirtualMachine; + private final LoadingCache> getIPForwardingRulesByVirtualMachine; @Inject public CreatePortForwardingRulesForIP(CloudStackClient client, BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult, - Cache> getIPForwardingRulesByVirtualMachine) { + LoadingCache> getIPForwardingRulesByVirtualMachine) { this.client = checkNotNull(client, "client"); this.blockUntilJobCompletesAndReturnResult = checkNotNull(blockUntilJobCompletesAndReturnResult, "blockUntilJobCompletesAndReturnResult"); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 22b0fe803d..027be867b3 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -67,7 +67,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -119,7 +119,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien @SuppressWarnings("unused") @Provides @Singleton - protected Cache> getIPForwardingRuleByVirtualMachine( + protected LoadingCache> getIPForwardingRuleByVirtualMachine( GetIPForwardingRulesByVirtualMachine getIPForwardingRule) { return CacheBuilder.newBuilder().build(getIPForwardingRule); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java index aa11418e94..75941d3472 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/EC2ComputeService.java @@ -69,7 +69,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableMultimap.Builder; @@ -81,7 +81,7 @@ import com.google.common.collect.ImmutableMultimap.Builder; public class EC2ComputeService extends BaseComputeService { private final EC2Client ec2Client; private final ConcurrentMap credentialsMap; - private final Cache securityGroupMap; + private final LoadingCache securityGroupMap; @Inject protected EC2ComputeService(ComputeServiceContext context, Map credentialStore, @@ -98,7 +98,7 @@ public class EC2ComputeService extends BaseComputeService { RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client, - ConcurrentMap credentialsMap, @Named("SECURITY") Cache securityGroupMap) { + ConcurrentMap credentialsMap, @Named("SECURITY") LoadingCache securityGroupMap) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended, diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java index 3aefb36979..60993118ac 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -44,7 +44,7 @@ import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; @@ -81,7 +81,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod @Override protected Supplier> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, final Supplier> imageSupplier, Injector injector) { - final Supplier> cache = injector.getInstance(Key.get(new TypeLiteral>>() {})); + final Supplier> cache = injector.getInstance(Key.get(new TypeLiteral>>() {})); return new Supplier>() { @Override public Set get() { @@ -92,7 +92,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod @Provides @Singleton - protected Supplier> provideRegionAndNameToImageSupplierCache( + protected Supplier> provideRegionAndNameToImageSupplierCache( final RegionAndNameToImageSupplier supplier) { return supplier; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java index 290e651912..9affea186c 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceDependenciesModule.java @@ -59,7 +59,7 @@ import org.jclouds.rest.internal.RestContextImpl; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -128,7 +128,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule { @Provides @Singleton - protected Cache credentialsMap(CacheLoader in) { + protected LoadingCache credentialsMap(CacheLoader in) { return CacheBuilder.newBuilder().build(in); } @@ -141,7 +141,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule { @Provides @Singleton @Named("SECURITY") - protected Cache securityGroupMap(CacheLoader in) { + protected LoadingCache securityGroupMap(CacheLoader in) { return CacheBuilder.newBuilder().build(in); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java index 951a38d4f9..9d906d9bce 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/CredentialsForInstance.java @@ -34,7 +34,7 @@ import org.jclouds.ec2.domain.RunningInstance; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheLoader; /** @@ -44,11 +44,11 @@ import com.google.common.cache.CacheLoader; @Singleton public class CredentialsForInstance extends CacheLoader { private final ConcurrentMap credentialsMap; - private final Supplier> imageMap; + private final Supplier> imageMap; @Inject CredentialsForInstance(ConcurrentMap credentialsMap, - Supplier> imageMap) { + Supplier> imageMap) { this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.imageMap = imageMap; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 1487a88dad..90d1422c07 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -57,7 +57,8 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -75,13 +76,13 @@ public class RunningInstanceToNodeMetadata implements Function> locations; protected final Supplier> hardware; - protected final Supplier> imageMap; + protected final Supplier> imageMap; protected final Map credentialStore; protected final Map instanceToNodeState; @Inject protected RunningInstanceToNodeMetadata(Map instanceToNodeState, - Map credentialStore, Supplier> imageMap, + Map credentialStore, Supplier> imageMap, @Memoized Supplier> locations, @Memoized Supplier> hardware) { this.locations = checkNotNull(locations, "locations"); this.hardware = checkNotNull(hardware, "hardware"); @@ -133,7 +134,7 @@ public class RunningInstanceToNodeMetadata implements Function> lazyImageCache; + private final Supplier> lazyImageCache; @Inject protected EC2TemplateBuilderImpl(@Memoized Supplier> locations, @Memoized Supplier> images, @Memoized Supplier> sizes, Supplier defaultLocation, @Named("DEFAULT") Provider optionsProvider, - @Named("DEFAULT") Provider defaultTemplateProvider, Supplier> imageMap) { + @Named("DEFAULT") Provider defaultTemplateProvider, Supplier> imageMap) { super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider); this.lazyImageCache = imageMap; } @@ -80,7 +81,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl { throw new NoSuchElementException(String.format("imageId(%s/%s) not found", key.getRegion(), key.getName())); } throw new NoSuchElementException(String.format("could not get imageId(%s/%s)", key.getRegion(), key.getName())); - } catch (NullPointerException nex) { + } catch (CacheLoader.InvalidCacheLoadException nex) { throw new NoSuchElementException(String.format("imageId(%s/%s) not found", key.getRegion(), key.getName())); } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java index 1b7ecb4874..534c26d595 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -44,7 +44,7 @@ import org.jclouds.javax.annotation.Nullable; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -59,14 +59,14 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions { @VisibleForTesting public final ConcurrentMap credentialsMap; @VisibleForTesting - public final Cache securityGroupMap; + public final LoadingCache securityGroupMap; @VisibleForTesting public final Provider optionsProvider; @Inject public CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions(Function makeKeyPair, ConcurrentMap credentialsMap, - @Named("SECURITY") Cache securityGroupMap, + @Named("SECURITY") LoadingCache securityGroupMap, Provider optionsProvider) { this.makeKeyPair = checkNotNull(makeKeyPair, "makeKeyPair"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java index ae1e6f408e..edb3c54139 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java @@ -52,7 +52,7 @@ import org.jclouds.logging.Logger; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; @@ -78,7 +78,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen @VisibleForTesting final ComputeUtils utils; final InstancePresent instancePresent; - final Cache instanceToCredentials; + final LoadingCache instanceToCredentials; final Map credentialStore; final Provider templateBuilderProvider; @@ -88,7 +88,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen Provider templateBuilderProvider, CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, InstancePresent instancePresent, Function runningInstanceToNodeMetadata, - Cache instanceToCredentials, Map credentialStore, + LoadingCache instanceToCredentials, Map credentialStore, ComputeUtils utils) { this.client = checkNotNull(client, "client"); this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider"); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2ImageSupplier.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2ImageSupplier.java index 2cd9a5d2de..a84520dfa5 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2ImageSupplier.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2ImageSupplier.java @@ -45,7 +45,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; @@ -65,11 +65,11 @@ public class EC2ImageSupplier implements Supplier> { private final DescribeImagesParallel describer; private final String[] amiOwners; private final EC2ImageParser parser; - private final Supplier> cache; + private final Supplier> cache; @Inject protected EC2ImageSupplier(@Region Set regions, DescribeImagesParallel describer, - @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier> cache, + @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier> cache, EC2ImageParser parser) { this.regions = regions; this.describer = describer; diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java index 4f10c5d4e1..d9f53b8532 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java @@ -30,7 +30,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.ec2.compute.domain.RegionAndName; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -39,8 +39,8 @@ import com.google.common.cache.CacheLoader; * @author Adrian Cole */ @Singleton -public class RegionAndNameToImageSupplier implements Supplier> { - private final Cache cache; +public class RegionAndNameToImageSupplier implements Supplier> { + private final LoadingCache cache; @Inject protected RegionAndNameToImageSupplier(CacheLoader regionAndIdToImage, @@ -49,7 +49,7 @@ public class RegionAndNameToImageSupplier implements Supplier get() { + public LoadingCache get() { return cache; } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java index 0c765f3f3d..b41d83a452 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java @@ -63,7 +63,7 @@ import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -169,7 +169,7 @@ public class EC2TemplateBuilderTest { new RegionAndName(image.getLocation().getId(), image.getProviderId()), image); // weird compilation error means have to declare extra generics for call to build() - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818 - Supplier> imageCache = Suppliers.> ofInstance( + Supplier> imageCache = Suppliers.> ofInstance( CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(imageMap)))); Template template = newTemplateBuilder(images, imageCache).imageId("us-east-1/cc-image").build(); @@ -197,14 +197,14 @@ public class EC2TemplateBuilderTest { // weird compilation error means have to cast this - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818 @SuppressWarnings("unchecked") ImmutableMap imageMap = (ImmutableMap) ImagesToRegionAndIdMap.imagesToMap(images.get()); - Supplier> imageCache = Suppliers.> ofInstance( + Supplier> imageCache = Suppliers.> ofInstance( CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(imageMap)))); return newTemplateBuilder(images, imageCache); } @SuppressWarnings("unchecked") - private TemplateBuilder newTemplateBuilder(Supplier> images, Supplier> imageCache) { + private TemplateBuilder newTemplateBuilder(Supplier> images, Supplier> imageCache) { Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); TemplateOptions defaultOptions = createMock(TemplateOptions.class); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index 127f716aca..03987761c4 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -47,7 +47,7 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -201,7 +201,7 @@ public class RunningInstanceToNodeMetadataTest { return null; } }; - Cache instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction); + LoadingCache instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small32().build()), ImmutableSet .of(provider), ImmutableMap. of(), @@ -235,13 +235,13 @@ public class RunningInstanceToNodeMetadataTest { return ImagesToRegionAndIdMap.imagesToMap(images).get(from); } }; - Cache instanceToImage = CacheBuilder.newBuilder().build(getRealImage); + LoadingCache instanceToImage = CacheBuilder.newBuilder().build(getRealImage); return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage); } private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final ImmutableSet locations, Map credentialStore, - Map instanceToNodeState, Cache instanceToImage) { + Map instanceToNodeState, LoadingCache instanceToImage) { Supplier> locationSupplier = new Supplier>() { @Override @@ -259,7 +259,7 @@ public class RunningInstanceToNodeMetadataTest { }; RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(instanceToNodeState, credentialStore, - Suppliers.> ofInstance(instanceToImage), locationSupplier, + Suppliers.> ofInstance(instanceToImage), locationSupplier, hardwareSupplier); return parser; } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImplTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImplTest.java index 0b1593402f..f17f70e913 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImplTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/EC2TemplateBuilderImplTest.java @@ -49,7 +49,7 @@ import org.testng.annotations.Test; import com.google.common.base.Functions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableSet; @@ -73,7 +73,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { @Memoized Supplier> sizes, Location defaultLocation, Provider optionsProvider, Provider templateBuilderProvider) { - Cache imageMap; + LoadingCache imageMap; if (knownImage != null) { final RegionAndName knownRegionAndName = new RegionAndName(knownImage.getLocation().getId(), knownImage.getProviderId()); @@ -91,7 +91,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { } return new EC2TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(defaultLocation), - optionsProvider, templateBuilderProvider, Suppliers.>ofInstance(imageMap)); + optionsProvider, templateBuilderProvider, Suppliers.>ofInstance(imageMap)); } @SuppressWarnings("unchecked") diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 8a56084c02..2d7b3b5440 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -48,7 +48,7 @@ import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; @@ -558,7 +558,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest { private CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions setupStrategy() { Function makeKeyPair = createMock(Function.class); ConcurrentMap credentialsMap = createMock(ConcurrentMap.class); - Cache securityGroupMap = createMock(Cache.class); + LoadingCache securityGroupMap = createMock(LoadingCache.class); return new CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions(makeKeyPair, credentialsMap, securityGroupMap, OPTIONS_PROVIDER); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java index 66a32a1b08..6f5d3e889e 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java @@ -51,7 +51,7 @@ import org.jclouds.ec2.options.RunInstancesOptions; import org.jclouds.ec2.services.InstanceClient; import org.testng.annotations.Test; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; @@ -222,7 +222,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest { CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class); InstancePresent instancePresent = createMock(InstancePresent.class); RunningInstanceToNodeMetadata runningInstanceToNodeMetadata = createMock(RunningInstanceToNodeMetadata.class); - Cache instanceToCredentials = createMock(Cache.class); + LoadingCache instanceToCredentials = createMock(LoadingCache.class); Map credentialStore = createMock(Map.class); ComputeUtils utils = createMock(ComputeUtils.class); return new EC2CreateNodesInGroupThenAddToSet(client, Providers. of(template), diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java index 4625aaaf1e..baed7f0880 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/BaseEC2AsyncClientTest.java @@ -46,7 +46,7 @@ import org.jclouds.rest.RestContextSpec; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -68,7 +68,7 @@ public abstract class BaseEC2AsyncClientTest extends RestClientTest { @Provides @Singleton - Cache provide(){ + LoadingCache provide(){ return CacheBuilder.newBuilder().build(new CacheLoader() { @Override diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java index 0bcccf6065..28bc3ebe73 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -61,7 +61,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -79,7 +79,7 @@ public class ElasticStackComputeServiceAdapter implements private final ElasticStackClient client; private final Predicate driveNotClaimed; private final Map preinstalledImages; - private final Cache cache; + private final LoadingCache cache; private final JustProvider locationSupplier; private final String defaultVncPassword; private final ExecutorService executor; @@ -90,7 +90,7 @@ public class ElasticStackComputeServiceAdapter implements @Inject public ElasticStackComputeServiceAdapter(ElasticStackClient client, Predicate driveNotClaimed, - JustProvider locationSupplier, Map preinstalledImages, Cache cache, + JustProvider locationSupplier, Map preinstalledImages, LoadingCache cache, @Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.client = checkNotNull(client, "client"); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java index 2cdf9c2825..cfac4f105a 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/config/ElasticStackComputeServiceContextModule.java @@ -59,7 +59,7 @@ import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Maps; @@ -106,7 +106,7 @@ public class ElasticStackComputeServiceContextModule @Provides @Singleton - protected Cache cache(GetDrive getDrive) { + protected LoadingCache cache(GetDrive getDrive) { return CacheBuilder.newBuilder().build(getDrive); } diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java index d868ff90ed..3c4b243f3c 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/functions/ServerInfoToNodeMetadata.java @@ -49,7 +49,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -114,10 +114,10 @@ public class ServerInfoToNodeMetadata implements Function cache; + private final LoadingCache cache; @Inject - public DeviceToVolume(Cache cache) { + public DeviceToVolume(LoadingCache cache) { this.cache = checkNotNull(cache, "cache"); } @@ -149,10 +149,10 @@ public class ServerInfoToNodeMetadata implements Function cache; + private final LoadingCache cache; @Inject - public GetImageIdFromServer(Cache cache) { + public GetImageIdFromServer(LoadingCache cache) { this.cache = cache; } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java index 0d82ffa894..156730b851 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java @@ -24,12 +24,11 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentSkipListMap; +import javax.annotation.Nullable; + import com.google.common.base.Functions; import com.google.common.base.Predicate; import com.google.common.collect.Lists; -import sun.awt.image.ImageWatched; - -import javax.annotation.Nullable; /** * @author Dmitri Babaev diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java index 29b7124c63..28121c3f5f 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3AsyncBlobStore.java @@ -20,7 +20,6 @@ package org.jclouds.s3.blobstore; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -56,12 +55,12 @@ import org.jclouds.s3.blobstore.functions.ContainerToBucketListOptions; import org.jclouds.s3.blobstore.functions.ObjectToBlob; import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.s3.domain.AccessControlList; -import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; -import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.domain.BucketMetadata; import org.jclouds.s3.domain.CannedAccessPolicy; import org.jclouds.s3.domain.ListBucketResponse; import org.jclouds.s3.domain.ObjectMetadata; +import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; +import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.options.ListBucketOptions; import org.jclouds.s3.options.PutBucketOptions; import org.jclouds.s3.options.PutObjectOptions; @@ -69,6 +68,8 @@ import org.jclouds.s3.util.S3Utils; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.ListenableFuture; @@ -89,7 +90,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { private final BlobToObject blob2Object; private final ObjectToBlobMetadata object2BlobMd; private final Provider fetchBlobMetadataProvider; - private final Map bucketAcls; + private final LoadingCache bucketAcls; @Inject protected S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, @@ -98,7 +99,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, - Provider fetchBlobMetadataProvider, Map bucketAcls) { + Provider fetchBlobMetadataProvider, LoadingCache bucketAcls) { super(context, blobUtils, service, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.async = checkNotNull(async, "async"); @@ -233,11 +234,11 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore { public ListenableFuture putBlob(String container, Blob blob) { PutObjectOptions options = new PutObjectOptions(); try { - AccessControlList acl = bucketAcls.get(container); - if (acl != null && acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ)) + AccessControlList acl = bucketAcls.getUnchecked(container); + if (acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ)) options.withAcl(CannedAccessPolicy.PUBLIC_READ); - } catch (NullPointerException e) { - // MapMaker + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted from cache loader } return async.putObject(container, blob2Object.apply(blob), options); } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java index e10a9b113a..b8e16a00d5 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java @@ -20,7 +20,6 @@ package org.jclouds.s3.blobstore; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -51,10 +50,10 @@ import org.jclouds.s3.blobstore.functions.ContainerToBucketListOptions; import org.jclouds.s3.blobstore.functions.ObjectToBlob; import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.s3.domain.AccessControlList; -import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; -import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.domain.BucketMetadata; import org.jclouds.s3.domain.CannedAccessPolicy; +import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; +import org.jclouds.s3.domain.AccessControlList.Permission; import org.jclouds.s3.options.ListBucketOptions; import org.jclouds.s3.options.PutBucketOptions; import org.jclouds.s3.options.PutObjectOptions; @@ -63,6 +62,8 @@ import org.jclouds.util.Assertions; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; /** @@ -80,7 +81,7 @@ public class S3BlobStore extends BaseBlobStore { private final ObjectToBlobMetadata object2BlobMd; private final BlobToHttpGetOptions blob2ObjectGetOptions; private final Provider fetchBlobMetadataProvider; - private final Map bucketAcls; + private final LoadingCache bucketAcls; @Inject protected S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @@ -88,7 +89,7 @@ public class S3BlobStore extends BaseBlobStore { BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, - Provider fetchBlobMetadataProvider, Map bucketAcls) { + Provider fetchBlobMetadataProvider, LoadingCache bucketAcls) { super(context, blobUtils, defaultLocation, locations); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.sync = checkNotNull(sync, "sync"); @@ -233,11 +234,11 @@ public class S3BlobStore extends BaseBlobStore { public String putBlob(String container, Blob blob) { PutObjectOptions options = new PutObjectOptions(); try { - AccessControlList acl = bucketAcls.get(container); + AccessControlList acl = bucketAcls.getUnchecked(container); if (acl != null && acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ)) options.withAcl(CannedAccessPolicy.PUBLIC_READ); - } catch (NullPointerException e) { - // MapMaker + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted from cache loader } return sync.putObject(container, blob2Object.apply(blob), options); } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java index 5462314f0f..c38c47a3df 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java @@ -18,7 +18,6 @@ */ package org.jclouds.s3.blobstore.config; -import java.util.Map; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; @@ -42,7 +41,9 @@ import org.jclouds.s3.domain.AccessControlList; import org.jclouds.s3.domain.BucketMetadata; import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Scopes; @@ -79,10 +80,11 @@ public class S3BlobStoreContextModule extends AbstractModule { @Provides @Singleton - protected Map bucketAcls(final S3Client client) { - return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap( - new Function() { - public AccessControlList apply(String bucketName) { + protected LoadingCache bucketAcls(final S3Client client) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build( + new CacheLoader() { + @Override + public AccessControlList load(String bucketName) { return client.getBucketACL(bucketName); } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/functions/ObjectToBlobMetadata.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/functions/ObjectToBlobMetadata.java index 693490385c..3fe757a005 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/functions/ObjectToBlobMetadata.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/functions/ObjectToBlobMetadata.java @@ -18,8 +18,6 @@ */ package org.jclouds.s3.blobstore.functions; -import java.util.Map; - import javax.inject.Inject; import javax.inject.Singleton; @@ -34,6 +32,8 @@ import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI; import org.jclouds.s3.domain.AccessControlList.Permission; import com.google.common.base.Function; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * @author Adrian Cole @@ -41,11 +41,11 @@ import com.google.common.base.Function; @Singleton public class ObjectToBlobMetadata implements Function { private final IfDirectoryReturnNameStrategy ifDirectoryReturnName; - private final Map bucketAcls; + private final LoadingCache bucketAcls; @Inject public ObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName, - Map bucketAcls) { + LoadingCache bucketAcls) { this.ifDirectoryReturnName = ifDirectoryReturnName; this.bucketAcls = bucketAcls; } @@ -56,11 +56,11 @@ public class ObjectToBlobMetadata implements Function com.google.guava guava - 10.0.1 + 11.0-rc1 diff --git a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java index 6eb6b68ae9..288cbf8c75 100644 --- a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java +++ b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java @@ -32,14 +32,12 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; import org.jclouds.concurrent.Timeout; import org.jclouds.internal.ClassMethodArgs; import org.jclouds.rest.annotations.Delegate; import org.jclouds.util.Throwables2; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.util.concurrent.ListenableFuture; @@ -50,12 +48,11 @@ import com.google.inject.ProvisionException; * * @author Adrian Cole */ -@SuppressWarnings("deprecation") public class SyncProxy implements InvocationHandler { @SuppressWarnings("unchecked") public static T proxy(Class clazz, Object async, - @Named("sync") Cache delegateMap, + @Named("sync") LoadingCache delegateMap, Map, Class> sync2Async, Map timeouts) throws IllegalArgumentException, SecurityException, NoSuchMethodException { return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, @@ -67,13 +64,13 @@ public class SyncProxy implements InvocationHandler { private final Map methodMap; private final Map syncMethodMap; private final Map timeoutMap; - private final Cache delegateMap; + private final LoadingCache delegateMap; private final Map, Class> sync2Async; - private static final Set objectMethods = ImmutableSet.of(Object.class.getMethods()); + private static final Set objectMethods = ImmutableSet.copyOf(Object.class.getMethods()); @Inject private SyncProxy(Class declaring, Object async, - @Named("sync") Cache delegateMap, Map, + @Named("sync") LoadingCache delegateMap, Map, Class> sync2Async, final Map timeouts) throws SecurityException, NoSuchMethodException { this.delegateMap = delegateMap; diff --git a/core/src/main/java/org/jclouds/json/internal/EnumTypeAdapterThatReturnsFromValue.java b/core/src/main/java/org/jclouds/json/internal/EnumTypeAdapterThatReturnsFromValue.java index fc77d3a73f..46ca2ffcc8 100644 --- a/core/src/main/java/org/jclouds/json/internal/EnumTypeAdapterThatReturnsFromValue.java +++ b/core/src/main/java/org/jclouds/json/internal/EnumTypeAdapterThatReturnsFromValue.java @@ -22,7 +22,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.concurrent.ExecutionException; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.gson.JsonDeserializationContext; @@ -56,7 +56,7 @@ public class EnumTypeAdapterThatReturnsFromValue> implements J } } - private final static Cache, Method> classToConvert = CacheBuilder.newBuilder() + private final static LoadingCache, Method> classToConvert = CacheBuilder.newBuilder() .build(new CacheLoader, Method>() { @Override diff --git a/core/src/main/java/org/jclouds/rest/config/ClientProvider.java b/core/src/main/java/org/jclouds/rest/config/ClientProvider.java index b89a3897b9..c8275155b3 100644 --- a/core/src/main/java/org/jclouds/rest/config/ClientProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/ClientProvider.java @@ -27,7 +27,7 @@ import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.internal.ClassMethodArgs; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Provider; @@ -59,8 +59,8 @@ public class ClientProvider implements Provider { @Singleton public S get() { A client = (A) injector.getInstance(Key.get(asyncClientType)); - Cache delegateMap = injector.getInstance(Key.get( - new TypeLiteral>() { + LoadingCache delegateMap = injector.getInstance(Key.get( + new TypeLiteral>() { }, Names.named("sync"))); try { return (S) SyncProxy.proxy(syncClientType, client, delegateMap, sync2Async, diff --git a/core/src/main/java/org/jclouds/rest/config/CreateClientForCaller.java b/core/src/main/java/org/jclouds/rest/config/CreateClientForCaller.java index 761ed6cb44..211eacce80 100644 --- a/core/src/main/java/org/jclouds/rest/config/CreateClientForCaller.java +++ b/core/src/main/java/org/jclouds/rest/config/CreateClientForCaller.java @@ -35,7 +35,7 @@ import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.internal.ClassMethodArgs; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheLoader; /** @@ -48,13 +48,13 @@ import com.google.common.cache.CacheLoader; public class CreateClientForCaller extends CacheLoader { @Inject Injector injector; - private final Cache asyncMap; - private final Provider> delegateMap; + private final LoadingCache asyncMap; + private final Provider> delegateMap; Map, Class> sync2Async; @Inject - CreateClientForCaller(@Named("async") Cache asyncMap, - @Named("sync") Provider> delegateMap) { + CreateClientForCaller(@Named("async") LoadingCache asyncMap, + @Named("sync") Provider> delegateMap) { this.asyncMap = asyncMap; this.delegateMap = delegateMap; } diff --git a/core/src/main/java/org/jclouds/rest/config/RestClientModule.java b/core/src/main/java/org/jclouds/rest/config/RestClientModule.java index 87e77f1e12..3041976d5f 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestClientModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestClientModule.java @@ -29,7 +29,7 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; @@ -125,7 +125,7 @@ public class RestClientModule extends AbstractModule { @Provides @Singleton @Named("sync") - Cache provideSyncDelegateMap( + LoadingCache provideSyncDelegateMap( CreateClientForCaller createClientForCaller) { createClientForCaller.sync2Async = delegates; return CacheBuilder.newBuilder().build(createClientForCaller); diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index d582a53f81..85b38690d4 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -40,7 +40,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.SeedAnnotationCache; import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -77,14 +77,14 @@ public class RestModule extends AbstractModule { @Provides @Singleton - protected Cache, Boolean> seedAnnotationCache(SeedAnnotationCache seedAnnotationCache) { + protected LoadingCache, Boolean> seedAnnotationCache(SeedAnnotationCache seedAnnotationCache) { return CacheBuilder.newBuilder().build(seedAnnotationCache); } @Provides @Singleton @Named("async") - Cache provideAsyncDelegateMap(CreateAsyncClientForCaller createAsyncClientForCaller) { + LoadingCache provideAsyncDelegateMap(CreateAsyncClientForCaller createAsyncClientForCaller) { return CacheBuilder.newBuilder().build(createAsyncClientForCaller); } @@ -108,8 +108,8 @@ public class RestModule extends AbstractModule { // cannot use child injectors due to the super coarse guice lock on // Singleton util.setCaller(from); - Cache delegateMap = injector.getInstance(Key.get( - new TypeLiteral>() { + LoadingCache delegateMap = injector.getInstance(Key.get( + new TypeLiteral>() { }, Names.named("async"))); AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector, factory, util, typeLiteral, delegateMap); injector.injectMembers(proxy); diff --git a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java index d7a3b74731..199f82fd53 100644 --- a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java +++ b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java @@ -48,7 +48,7 @@ import org.jclouds.util.Throwables2; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.Futures; @@ -76,12 +76,12 @@ public class AsyncRestClientProxy implements InvocationHandler { @Resource protected Logger logger = Logger.NULL; - private final Cache delegateMap; + private final LoadingCache delegateMap; @SuppressWarnings("unchecked") @Inject public AsyncRestClientProxy(Injector injector, Factory factory, RestAnnotationProcessor util, - TypeLiteral typeLiteral, @Named("async") Cache delegateMap) { + TypeLiteral typeLiteral, @Named("async") LoadingCache delegateMap) { this.injector = injector; this.annotationProcessor = util; this.declaring = (Class) typeLiteral.getRawType(); diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 1fc970da04..40346b5ce6 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -142,7 +142,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableList; @@ -174,24 +174,24 @@ public class RestAnnotationProcessor { private final Class declaring; // TODO replace with Table object - static final Cache>> methodToIndexOfParamToBinderParamAnnotation = createMethodToIndexOfParamToAnnotation(BinderParam.class); - static final Cache>> methodToIndexOfParamToWrapWithAnnotation = createMethodToIndexOfParamToAnnotation(WrapWith.class); - static final Cache>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class); - static final Cache>> methodToIndexOfParamToEndpointAnnotations = createMethodToIndexOfParamToAnnotation(Endpoint.class); - static final Cache>> methodToIndexOfParamToEndpointParamAnnotations = createMethodToIndexOfParamToAnnotation(EndpointParam.class); - static final Cache>> methodToIndexOfParamToMatrixParamAnnotations = createMethodToIndexOfParamToAnnotation(MatrixParam.class); - static final Cache>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class); - static final Cache>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class); - static final Cache>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class); - static final Cache>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(PayloadParam.class); - static final Cache>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class); - static final Cache>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class); + static final LoadingCache>> methodToIndexOfParamToBinderParamAnnotation = createMethodToIndexOfParamToAnnotation(BinderParam.class); + static final LoadingCache>> methodToIndexOfParamToWrapWithAnnotation = createMethodToIndexOfParamToAnnotation(WrapWith.class); + static final LoadingCache>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class); + static final LoadingCache>> methodToIndexOfParamToEndpointAnnotations = createMethodToIndexOfParamToAnnotation(Endpoint.class); + static final LoadingCache>> methodToIndexOfParamToEndpointParamAnnotations = createMethodToIndexOfParamToAnnotation(EndpointParam.class); + static final LoadingCache>> methodToIndexOfParamToMatrixParamAnnotations = createMethodToIndexOfParamToAnnotation(MatrixParam.class); + static final LoadingCache>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class); + static final LoadingCache>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class); + static final LoadingCache>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class); + static final LoadingCache>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(PayloadParam.class); + static final LoadingCache>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class); + static final LoadingCache>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class); static final Map delegationMap = newHashMap(); - static Cache>> createMethodToIndexOfParamToAnnotation( + static LoadingCache>> createMethodToIndexOfParamToAnnotation( final Class annotation) { - return CacheBuilder.newBuilder().build(new CacheLoader>>() { - public Cache> load(Method method) { + return CacheBuilder.newBuilder().build(new CacheLoader>>() { + public LoadingCache> load(Method method) { return CacheBuilder.newBuilder().build(CacheLoader.from(new GetAnnotationsForMethodParameterIndex(method, annotation))); } }); @@ -229,7 +229,7 @@ public class RestAnnotationProcessor { }; - static final Cache> methodToIndexesOfOptions = CacheBuilder.newBuilder().build( + static final LoadingCache> methodToIndexesOfOptions = CacheBuilder.newBuilder().build( new CacheLoader>() { @Override public Set load(Method method) { @@ -246,7 +246,7 @@ public class RestAnnotationProcessor { private final ParseSax.Factory parserFactory; private final HttpUtils utils; private final Provider uriBuilderProvider; - private final Cache, Boolean> seedAnnotationCache; + private final LoadingCache, Boolean> seedAnnotationCache; private final String apiVersion; private char[] skips; @@ -308,7 +308,7 @@ public class RestAnnotationProcessor { @SuppressWarnings("unchecked") @Inject - public RestAnnotationProcessor(Injector injector, Cache, Boolean> seedAnnotationCache, + public RestAnnotationProcessor(Injector injector, LoadingCache, Boolean> seedAnnotationCache, @Named(Constants.PROPERTY_API_VERSION) String apiVersion, ParseSax.Factory parserFactory, HttpUtils utils, TypeLiteral typeLiteral) throws ExecutionException { this.declaring = (Class) typeLiteral.getRawType(); @@ -1010,7 +1010,7 @@ public class RestAnnotationProcessor { } public static Map> indexWithOnlyOneAnnotation(Method method, String description, - Cache>> toRefine) throws ExecutionException { + LoadingCache>> toRefine) throws ExecutionException { Map> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine); if (indexToPayloadAnnotation.size() > 1) { throw new IllegalStateException(String.format( @@ -1021,7 +1021,7 @@ public class RestAnnotationProcessor { } private static Map> indexWithAtLeastOneAnnotation(Method method, - Cache>> toRefine) throws ExecutionException { + LoadingCache>> toRefine) throws ExecutionException { Map> indexToPayloadAnnotation = filterValues(toRefine.get(method).asMap(), new Predicate>() { public boolean apply(Set input) { @@ -1061,7 +1061,7 @@ public class RestAnnotationProcessor { final Object... args) throws ExecutionException { Multimap headers = LinkedHashMultimap.create(); addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues); - Cache> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method); + LoadingCache> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method); for (Entry> entry : indexToHeaderParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { String value = args[entry.getKey()].toString(); @@ -1128,7 +1128,7 @@ public class RestAnnotationProcessor { List getParts(Method method, Object[] args, Iterable> iterable) throws ExecutionException { List parts = newLinkedList(); - Cache> indexToPartParam = methodToIndexOfParamToPartParamAnnotations.get(method); + LoadingCache> indexToPartParam = methodToIndexOfParamToPartParamAnnotations.get(method); for (Entry> entry : indexToPartParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { PartParam param = (PartParam) key; @@ -1168,9 +1168,9 @@ public class RestAnnotationProcessor { private Multimap getPathParamKeyValues(Method method, Object... args) throws ExecutionException { Multimap pathParamValues = LinkedHashMultimap.create(); - Cache> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.get(method); + LoadingCache> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.get(method); - Cache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); + LoadingCache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); for (Entry> entry : indexToPathParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); @@ -1205,9 +1205,9 @@ public class RestAnnotationProcessor { private Multimap getMatrixParamKeyValues(Method method, Object... args) throws ExecutionException { Multimap matrixParamValues = LinkedHashMultimap.create(); - Cache> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations.get(method); + LoadingCache> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations.get(method); - Cache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); + LoadingCache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); for (Entry> entry : indexToMatrixParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); @@ -1234,9 +1234,9 @@ public class RestAnnotationProcessor { private Multimap getFormParamKeyValues(Method method, Object... args) throws ExecutionException { Multimap formParamValues = LinkedHashMultimap.create(); - Cache> indexToFormParam = methodToIndexOfParamToFormParamAnnotations.get(method); + LoadingCache> indexToFormParam = methodToIndexOfParamToFormParamAnnotations.get(method); - Cache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); + LoadingCache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); for (Entry> entry : indexToFormParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); @@ -1265,9 +1265,9 @@ public class RestAnnotationProcessor { private Multimap getQueryParamKeyValues(Method method, Object... args) throws ExecutionException { Multimap queryParamValues = LinkedHashMultimap.create(); - Cache> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations.get(method); + LoadingCache> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations.get(method); - Cache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); + LoadingCache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); for (Entry> entry : indexToQueryParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); @@ -1294,8 +1294,8 @@ public class RestAnnotationProcessor { private Map buildPostParams(Method method, Object... args) throws ExecutionException { Map postParams = newHashMap(); - Cache> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method); - Cache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); + LoadingCache> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method); + LoadingCache> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method); for (Entry> entry : indexToPathParam.asMap().entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); diff --git a/core/src/main/java/org/jclouds/util/Patterns.java b/core/src/main/java/org/jclouds/util/Patterns.java index c293e0d85d..b0b5052934 100644 --- a/core/src/main/java/org/jclouds/util/Patterns.java +++ b/core/src/main/java/org/jclouds/util/Patterns.java @@ -23,7 +23,7 @@ import java.net.URLEncoder; import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -50,7 +50,7 @@ public class Patterns { public static final Pattern TRAILING_SLASHES = Pattern.compile("[/]*$"); public static final Pattern REST_CONTEXT_BUILDER = Pattern.compile("(.*ContextBuilder)<([^,]+), ?([^>]+)>"); - public final static Cache CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder() + public final static LoadingCache CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder() . build(new CacheLoader() { @Override public Pattern load(Character plain) throws ExecutionException { @@ -63,7 +63,7 @@ public class Patterns { } }); - public final static Cache CHAR_TO_PATTERN = CacheBuilder.newBuilder() + public final static LoadingCache CHAR_TO_PATTERN = CacheBuilder.newBuilder() . build(new CacheLoader() { @Override public Pattern load(Character plain) { @@ -71,7 +71,7 @@ public class Patterns { } }); - public final static Cache TOKEN_TO_PATTERN = CacheBuilder.newBuilder() + public final static LoadingCache TOKEN_TO_PATTERN = CacheBuilder.newBuilder() . build(new CacheLoader() { @Override public Pattern load(String tokenValue) { diff --git a/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java b/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java index 9ece866c91..7a29a04e25 100644 --- a/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java +++ b/core/src/test/java/org/jclouds/concurrent/internal/SyncProxyTest.java @@ -36,7 +36,7 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.common.base.Functions; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -183,7 +183,7 @@ public class SyncProxyTest { @BeforeTest public void setUp() throws IllegalArgumentException, SecurityException, NoSuchMethodException { - Cache cache = CacheBuilder.newBuilder().build( + LoadingCache cache = CacheBuilder.newBuilder().build( CacheLoader.from(Functions. constant(null))); sync = SyncProxy.proxy(Sync.class, new Async(), cache, ImmutableMap., Class> of(), ImmutableMap.of("Sync.takeXMillisecondsPropOverride", 250L)); @@ -258,7 +258,7 @@ public class SyncProxyTest { @Test(enabled = false, expectedExceptions = IllegalArgumentException.class) public void testWrongTypedException() throws IllegalArgumentException, SecurityException, NoSuchMethodException, IOException { - Cache cache = CacheBuilder.newBuilder().build( + LoadingCache cache = CacheBuilder.newBuilder().build( CacheLoader.from(Functions. constant(null))); SyncProxy.proxy(SyncWrongException.class, new Async(), cache, ImmutableMap., Class> of(), ImmutableMap. of()); @@ -278,7 +278,7 @@ public class SyncProxyTest { @Test(enabled = false, expectedExceptions = IllegalArgumentException.class) public void testNoTimeOutException() throws IllegalArgumentException, SecurityException, NoSuchMethodException, IOException { - Cache cache = CacheBuilder.newBuilder().build( + LoadingCache cache = CacheBuilder.newBuilder().build( CacheLoader.from(Functions. constant(null))); SyncProxy.proxy(SyncNoTimeOut.class, new Async(), cache, ImmutableMap., Class> of(), ImmutableMap. of()); @@ -299,7 +299,7 @@ public class SyncProxyTest { @Test(enabled = false, expectedExceptions = RuntimeException.class) public void testClassOverridePropTimeout() throws Exception { - Cache cache = CacheBuilder.newBuilder().build( + LoadingCache cache = CacheBuilder.newBuilder().build( CacheLoader.from(Functions. constant(null))); final SyncClassOverride sync2 = SyncProxy.proxy(SyncClassOverride.class, new Async(), cache, ImmutableMap., Class> of(), ImmutableMap. of("SyncClassOverride", 100L)); diff --git a/core/src/test/java/org/jclouds/functions/CacheLearningTest.java b/core/src/test/java/org/jclouds/functions/CacheLearningTest.java index ead9600f1a..851d0af535 100644 --- a/core/src/test/java/org/jclouds/functions/CacheLearningTest.java +++ b/core/src/test/java/org/jclouds/functions/CacheLearningTest.java @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutionException; import org.testng.annotations.Test; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.util.concurrent.UncheckedExecutionException; @@ -37,7 +37,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException; public class CacheLearningTest { @Test public void howTo() throws ExecutionException { - Cache cache = CacheBuilder.newBuilder().build(new CacheLoader() { + LoadingCache cache = CacheBuilder.newBuilder().build(new CacheLoader() { @Override public String load(String key) throws Exception { @@ -57,10 +57,17 @@ public class CacheLearningTest { try { cache.get("foo"); assert false : "expected exception on miss"; - } catch (NullPointerException e) { - assertEquals(e.getMessage(), "testLoader returned null for key foo."); + } catch (CacheLoader.InvalidCacheLoadException e) { + assertEquals(e.getMessage(), "CacheLoader returned null for key foo."); } - + + try { + cache.getUnchecked("foo"); + assert false : "expected exception on miss"; + } catch (CacheLoader.InvalidCacheLoadException e) { + assertEquals(e.getMessage(), "CacheLoader returned null for key foo."); + } + assertEquals(cache.asMap().keySet().size(), 0); assertEquals(cache.asMap().size(), 0); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java index 5987a02b36..9d7b138573 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeService.java @@ -74,7 +74,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -85,7 +85,7 @@ import com.google.common.collect.Iterables; @Singleton public class AWSEC2ComputeService extends EC2ComputeService { - private final Cache placementGroupMap; + private final LoadingCache placementGroupMap; private final Predicate placementGroupDeleted; private final AWSEC2Client ec2Client; private final AWSEC2AsyncClient aclient; @@ -108,8 +108,8 @@ public class AWSEC2ComputeService extends EC2ComputeService { PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, AWSEC2Client ec2Client, ConcurrentMap credentialsMap, - @Named("SECURITY") Cache securityGroupMap, - @Named("PLACEMENT") Cache placementGroupMap, + @Named("SECURITY") LoadingCache securityGroupMap, + @Named("PLACEMENT") LoadingCache placementGroupMap, @Named("DELETED") Predicate placementGroupDeleted, @Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, AWSEC2AsyncClient aclient) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderImpl.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderImpl.java index 4d95533b72..dd82269794 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderImpl.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderImpl.java @@ -34,7 +34,7 @@ import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; /** * @@ -46,7 +46,7 @@ public class AWSEC2TemplateBuilderImpl extends EC2TemplateBuilderImpl { protected AWSEC2TemplateBuilderImpl(@Memoized Supplier> locations, @Memoized Supplier> images, @Memoized Supplier> sizes, Supplier defaultLocation, @Named("DEFAULT") Provider optionsProvider, - @Named("DEFAULT") Provider defaultTemplateProvider, Supplier> imageMap) { + @Named("DEFAULT") Provider defaultTemplateProvider, Supplier> imageMap) { super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, imageMap); } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java index aa32f67ded..53f93a2e49 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java @@ -66,7 +66,7 @@ import org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; @@ -116,7 +116,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext @Override protected Supplier> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, final Supplier> imageSupplier, Injector injector) { - final Supplier> cache = injector.getInstance(Key.get(new TypeLiteral>>() {})); + final Supplier> cache = injector.getInstance(Key.get(new TypeLiteral>>() {})); return new Supplier>() { @Override public Set get() { @@ -158,7 +158,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext @Provides @Singleton - protected Supplier> provideRegionAndNameToImageSupplierCache( + protected Supplier> provideRegionAndNameToImageSupplierCache( final RegionAndNameToImageSupplier supplier) { return supplier; } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java index 4007ba24b4..3abd841d89 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java @@ -59,7 +59,7 @@ import org.jclouds.rest.internal.RestContextImpl; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.Sets; @@ -116,7 +116,7 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep @Provides @Singleton @Named("PLACEMENT") - protected Cache placementGroupMap(CreatePlacementGroupIfNeeded in) { + protected LoadingCache placementGroupMap(CreatePlacementGroupIfNeeded in) { return CacheBuilder.newBuilder().build(in); } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java index f1cbbc7098..1b613e143d 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java @@ -43,7 +43,7 @@ import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.RunningInstance; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; /** * @author Adrian Cole @@ -53,7 +53,7 @@ public class AWSRunningInstanceToNodeMetadata extends RunningInstanceToNodeMetad @Inject protected AWSRunningInstanceToNodeMetadata(Map instanceToNodeState, - Map credentialStore, Supplier> imageMap, + Map credentialStore, Supplier> imageMap, @Memoized Supplier> locations, @Memoized Supplier> hardware) { super(instanceToNodeState, credentialStore, imageMap, locations, hardware); } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java index f2cb7cbee9..ebe5d6b2df 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java @@ -52,7 +52,7 @@ import org.jclouds.logging.Logger; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -82,7 +82,7 @@ public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupT CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, AWSEC2InstancePresent instancePresent, Function runningInstanceToNodeMetadata, - Cache instanceToCredentials, Map credentialStore, + LoadingCache instanceToCredentials, Map credentialStore, ComputeUtils utils, SpotInstanceRequestToAWSRunningInstance spotConverter) { super(client, templateBuilderProvider, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, instancePresent, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java index 3e9907a386..4872ffdfbc 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -46,7 +46,7 @@ import org.jclouds.logging.Logger; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; /** * @@ -59,7 +59,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @VisibleForTesting - final Cache placementGroupMap; + final LoadingCache placementGroupMap; @VisibleForTesting final CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded; @VisibleForTesting @@ -68,9 +68,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions @Inject public CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions( Function makeKeyPair, ConcurrentMap credentialsMap, - @Named("SECURITY") Cache securityGroupMap, + @Named("SECURITY") LoadingCache securityGroupMap, Provider optionsProvider, - @Named("PLACEMENT") Cache placementGroupMap, + @Named("PLACEMENT") LoadingCache placementGroupMap, CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded, Function importExistingKeyPair) { super(makeKeyPair, credentialsMap, securityGroupMap, optionsProvider); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java index f585583529..2f039873a7 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2ImageSupplier.java @@ -47,7 +47,7 @@ import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.base.Throwables; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -75,13 +75,13 @@ public class AWSEC2ImageSupplier implements Supplier> { private final String amiQuery; private final Iterable clusterRegions; private final String ccAmiQuery; - private final Supplier> cache; + private final Supplier> cache; @Inject protected AWSEC2ImageSupplier(@Region Set regions, @Named(PROPERTY_EC2_AMI_QUERY) String amiQuery, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions, @Named(PROPERTY_EC2_CC_AMI_QUERY) String ccAmiQuery, - Supplier> cache, + Supplier> cache, CallForImages.Factory factory, @ClusterCompute Set clusterComputeIds, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.factory = factory; diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java index b98faea803..2053d4a95f 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadataTest.java @@ -46,7 +46,7 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -160,7 +160,7 @@ public class AWSRunningInstanceToNodeMetadataTest { final Map backing = ImagesToRegionAndIdMap.imagesToMap(images); - Cache instanceToImage = CacheBuilder.newBuilder().build(new CacheLoader (){ + LoadingCache instanceToImage = CacheBuilder.newBuilder().build(new CacheLoader (){ @Override public Image load(RegionAndName key) throws Exception { @@ -175,7 +175,7 @@ public class AWSRunningInstanceToNodeMetadataTest { private AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final ImmutableSet locations, Map credentialStore, - Map instanceToNodeState, Cache instanceToImage) { + Map instanceToNodeState, LoadingCache instanceToImage) { Supplier> locationSupplier = new Supplier>() { @Override @@ -193,7 +193,7 @@ public class AWSRunningInstanceToNodeMetadataTest { }; AWSRunningInstanceToNodeMetadata parser = new AWSRunningInstanceToNodeMetadata(instanceToNodeState, - credentialStore, Suppliers.> ofInstance(instanceToImage), + credentialStore, Suppliers.> ofInstance(instanceToImage), locationSupplier, hardwareSupplier); return parser; } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index c9eea64cd4..2be19c7070 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -57,7 +57,7 @@ import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; @@ -934,8 +934,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT private CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions setupStrategy() { Function makeKeyPair = createMock(Function.class); ConcurrentMap credentialsMap = createMock(ConcurrentMap.class); - Cache securityGroupMap = createMock(Cache.class); - Cache placementGroupMap = createMock(Cache.class); + LoadingCache securityGroupMap = createMock(LoadingCache.class); + LoadingCache placementGroupMap = createMock(LoadingCache.class); Function importExistingKeyPair = createMock(Function.class); CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded = createMock(CreatePlacementGroupIfNeeded.class); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java index a08888ab7b..556c630b36 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/BaseAWSEC2AsyncClientTest.java @@ -42,7 +42,7 @@ import org.jclouds.rest.RestContextSpec; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.collect.ImmutableMap; @@ -70,7 +70,7 @@ public abstract class BaseAWSEC2AsyncClientTest extends RestClientTest { @Provides @Singleton - Cache provide(){ + LoadingCache provide(){ return CacheBuilder.newBuilder().build(new CacheLoader() { @Override diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java index 65c1385077..38848d65cd 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3AsyncBlobStore.java @@ -18,7 +18,6 @@ */ package org.jclouds.aws.s3.blobstore; -import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -48,6 +47,7 @@ import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.s3.domain.AccessControlList; import com.google.common.base.Supplier; +import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.ListenableFuture; /** @@ -65,7 +65,7 @@ public class AWSS3AsyncBlobStore extends S3AsyncBlobStore { BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, - Provider fetchBlobMetadataProvider, Map bucketAcls, + Provider fetchBlobMetadataProvider, LoadingCache bucketAcls, Provider multipartUploadStrategy) { super(context, blobUtils, service, defaultLocation, locations, async, sync, bucket2ResourceMd, container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object, diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java index 47554e9c28..8bb382d61b 100644 --- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java +++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java @@ -18,7 +18,6 @@ */ package org.jclouds.aws.s3.blobstore; -import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -44,6 +43,7 @@ import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.s3.domain.AccessControlList; import com.google.common.base.Supplier; +import com.google.common.cache.LoadingCache; /** * Proived AWS S3 specific extensions. @@ -60,7 +60,7 @@ public class AWSS3BlobStore extends S3BlobStore { BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, - Provider fetchBlobMetadataProvider, Map bucketAcls, + Provider fetchBlobMetadataProvider, LoadingCache bucketAcls, Provider multipartUploadStrategy) { super(context, blobUtils, defaultLocation, locations, sync, bucket2ResourceMd, container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object, object2BlobMd, diff --git a/providers/azureblob/pom.xml b/providers/azureblob/pom.xml index 1884fc678d..f7d398f617 100644 --- a/providers/azureblob/pom.xml +++ b/providers/azureblob/pom.xml @@ -74,12 +74,6 @@ ${project.version} test - - log4j - log4j - 1.2.16 - test - diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java index cc828fa094..8a4717873e 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/config/AzureBlobStoreContextModule.java @@ -18,7 +18,6 @@ */ package org.jclouds.azureblob.blobstore.config; -import java.util.Map; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; @@ -40,8 +39,9 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.location.config.JustProviderLocationModule; -import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Scopes; @@ -69,10 +69,11 @@ public class AzureBlobStoreContextModule extends AbstractModule { @Provides @Singleton - protected Map containerAcls(final AzureBlobClient client) { - return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap( - new Function() { - public PublicAccess apply(String container) { + protected LoadingCache containerAcls(final AzureBlobClient client) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build( + new CacheLoader() { + @Override + public PublicAccess load(String container) { return client.getPublicAccessForContainer(container); } diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java index 2d821d2a06..f5d1e0e5a4 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/functions/BlobPropertiesToBlobMetadata.java @@ -20,8 +20,6 @@ package org.jclouds.azureblob.blobstore.functions; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; - import javax.inject.Inject; import javax.inject.Singleton; @@ -34,6 +32,8 @@ import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy; import org.jclouds.http.HttpUtils; import com.google.common.base.Function; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * @author Adrian Cole @@ -41,11 +41,11 @@ import com.google.common.base.Function; @Singleton public class BlobPropertiesToBlobMetadata implements Function { private final IfDirectoryReturnNameStrategy ifDirectoryReturnName; - private final Map containerAcls; + private final LoadingCache containerAcls; @Inject public BlobPropertiesToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName, - Map containerAcls) { + LoadingCache containerAcls) { this.ifDirectoryReturnName = checkNotNull(ifDirectoryReturnName, "ifDirectoryReturnName"); this.containerAcls = checkNotNull(containerAcls, "containerAcls"); } @@ -61,13 +61,14 @@ public class BlobPropertiesToBlobMetadata implements Function> { +public class ImageFromYamlStream implements Function> { /** * Type-safe config class for YAML @@ -63,7 +63,7 @@ public class ImageFromYamlStream implements Function apply(InputStream source) { + public LoadingCache apply(InputStream source) { Constructor constructor = new Constructor(Config.class); @@ -82,7 +82,7 @@ public class ImageFromYamlStream implements Function cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); + LoadingCache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); for (String node : backingMap.keySet()) cache.getUnchecked(node); return cache; diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java index 05b133a19d..c7d265b325 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java @@ -33,7 +33,7 @@ import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.sshj.config.SshjSshClientModule; -import com.google.common.cache.Cache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; @@ -85,7 +85,7 @@ public class TestUtils { return null; } - public static ComputeServiceContext computeServiceForVirtualBox(Cache cache) { + public static ComputeServiceContext computeServiceForVirtualBox(LoadingCache cache) { return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of( new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(cache)));