Issue 781:update to guava 11.0-rc1

This commit is contained in:
Adrian Cole 2011-12-14 23:56:50 -08:00
parent 40d2abbac5
commit beb87a2131
80 changed files with 357 additions and 346 deletions

View File

@ -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<URI, ComputeServiceContext> computeMap;
private final LoadingCache<URI, ComputeServiceContext> computeMap;
private String provider;
private String actions;
private NodeElement nodeElement;
@ -71,7 +71,7 @@ public class ComputeTask extends Task {
}
};
public ComputeTask(@Nullable Cache<URI, ComputeServiceContext> computeMap) {
public ComputeTask(@Nullable LoadingCache<URI, ComputeServiceContext> computeMap) {
this.computeMap = computeMap != null ? computeMap : buildComputeMap(projectProvider);
}

View File

@ -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<URI, ComputeServiceContext> buildComputeMap(final Provider<Project> projectProvider) {
static LoadingCache<URI, ComputeServiceContext> buildComputeMap(final Provider<Project> projectProvider) {
return CacheBuilder.newBuilder().build(new CacheLoader<URI, ComputeServiceContext>() {
@SuppressWarnings("unchecked")

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider;
private final Map<String, Boolean> isPublic;
private final LoadingCache<String, Boolean> 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<FetchBlobMetadata> fetchBlobMetadataProvider,
Map<String, Boolean> isPublic) {
LoadingCache<String, Boolean> 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<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 Futures.makeListenable(service.submit(new Callable<String>() {

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider;
private final Map<String, Boolean> isPublic;
private final LoadingCache<String, Boolean> isPublic;
@Inject
AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
@ -78,7 +79,7 @@ public class AtmosBlobStore extends BaseBlobStore {
BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
Map<String, Boolean> isPublic) {
LoadingCache<String, Boolean> 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);
}

View File

@ -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<String, Boolean> isPublic(final AtmosClient client) {
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function<String, Boolean>() {
public Boolean apply(String directory) {
return client.isPublic(directory);
}
protected LoadingCache<String, Boolean> isPublic(final AtmosClient client) {
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader<String, Boolean>() {
@Override
public String toString() {
return "isPublic()";
}
@Override
public Boolean load(String arg0) throws Exception {
return client.isPublic(arg0);
}
});
}
}

View File

@ -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<Cache<String, Node>> in) {
Supplier provideApi(Supplier<LoadingCache<String, Node>> in) {
return in;
}

View File

@ -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<String, Node> backing;
private final LoadingCache<String, Node> backing;
public CacheNodeStoreModule(Cache<String, Node> backing) {
public CacheNodeStoreModule(LoadingCache<String, Node> backing) {
this.backing = checkNotNull(backing, "backing");
}
@ -55,10 +55,10 @@ public class CacheNodeStoreModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<Cache<String, Node>>() {
bind(new TypeLiteral<LoadingCache<String, Node>>() {
}).toInstance(backing);
bind(new TypeLiteral<Supplier<Cache<String, Node>>>() {
}).toInstance(Suppliers.<Cache<String, Node>> ofInstance(backing));
bind(new TypeLiteral<Supplier<LoadingCache<String, Node>>>() {
}).toInstance(Suppliers.<LoadingCache<String, Node>> ofInstance(backing));
}
}

View File

@ -27,7 +27,7 @@ import java.lang.annotation.Target;
import com.google.common.annotations.Beta;
/**
* designates the module configures a {@code Cache<String, Node>}
* designates the module configures a {@code LoadingCache<String, Node>}
*
* @author Adrian Cole
*

View File

@ -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<Supplier<Cache<String, Node>>>() {
bind(new TypeLiteral<Supplier<LoadingCache<String, Node>>>() {
}).to(NodesParsedFromSupplier.class);
bind(new TypeLiteral<Function<InputStream, Cache<String, Node>>>() {
bind(new TypeLiteral<Function<InputStream, LoadingCache<String, Node>>>() {
}).to(NodesFromYamlStream.class);
bind(new TypeLiteral<Function<YamlNode, InputStream>>() {
}).toInstance(org.jclouds.byon.domain.YamlNode.yamlNodeToInputStream);
@ -103,7 +103,7 @@ public class YamlNodeStoreModule extends AbstractModule {
@Provides
@Singleton
protected Cache<String, Node> provideNodeStore(Map<String, YamlNode> backing, Function<Node, YamlNode> yamlSerializer,
protected LoadingCache<String, Node> provideNodeStore(Map<String, YamlNode> backing, Function<Node, YamlNode> yamlSerializer,
Function<YamlNode, Node> yamlDeserializer) {
return CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(new TransformingMap<String, YamlNode, Node>(backing, yamlDeserializer, yamlSerializer))));
}

View File

@ -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<InputStream, Cache<String, Node>> {
public class NodesFromYamlStream implements Function<InputStream, LoadingCache<String, Node>> {
/**
* Type-safe config class for YAML
@ -80,7 +80,7 @@ public class NodesFromYamlStream implements Function<InputStream, Cache<String,
}
@Override
public Cache<String, Node> apply(InputStream source) {
public LoadingCache<String, Node> apply(InputStream source) {
Constructor constructor = new Constructor(Config.class);
@ -105,7 +105,7 @@ public class NodesFromYamlStream implements Function<InputStream, Cache<String,
return node.getId();
}
});
Cache<String, Node> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
LoadingCache<String, Node> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
for (String node : backingMap.keySet())
cache.getUnchecked(node);
return cache;

View File

@ -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<Cache<String, Node>> nodes;
private final Supplier<LoadingCache<String, Node>> nodes;
private final NodeToNodeMetadata converter;
private final JustProvider locationSupplier;
@Inject
public BYONComputeServiceAdapter(Supplier<Cache<String, Node>> nodes, NodeToNodeMetadata converter,
public BYONComputeServiceAdapter(Supplier<LoadingCache<String, Node>> nodes, NodeToNodeMetadata converter,
JustProvider locationSupplier) {
this.nodes = checkNotNull(nodes, "nodes");
this.converter = checkNotNull(converter, "converter");

View File

@ -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<Cache<String, Node>> {
public class NodesParsedFromSupplier implements Supplier<LoadingCache<String, Node>> {
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<InputStream> supplier;
private final Function<InputStream, Cache<String, Node>> parser;
private final Function<InputStream, LoadingCache<String, Node>> parser;
@Inject
NodesParsedFromSupplier(@Provider Supplier<InputStream> supplier, Function<InputStream, Cache<String, Node>> parser) {
NodesParsedFromSupplier(@Provider Supplier<InputStream> supplier, Function<InputStream, LoadingCache<String, Node>> parser) {
this.supplier = checkNotNull(supplier, "supplier");
this.parser = checkNotNull(parser, "parser");
}
@Override
public Cache<String, Node> get() {
Cache<String, Node> nodes = parser.apply(supplier.get());
public LoadingCache<String, Node> get() {
LoadingCache<String, Node> nodes = parser.apply(supplier.get());
checkState(nodes != null && nodes.size() > 0, "no nodes parsed from supplier: %s", supplier);
return nodes;
}

View File

@ -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<Cache<String, Node>> supplier = (Supplier<Cache<String, Node>>) context.getProviderSpecificContext()
Supplier<LoadingCache<String, Node>> supplier = (Supplier<LoadingCache<String, Node>>) 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<Cache<String, Node>> supplier = (Supplier<Cache<String, Node>>) context.getProviderSpecificContext()
Supplier<LoadingCache<String, Node>> supplier = (Supplier<LoadingCache<String, Node>>) context.getProviderSpecificContext()
.getApi();
assertEquals(supplier.get().size(), context.getComputeService().listNodes().size());

View File

@ -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<String, Node> map = Maps.newConcurrentMap();
Injector injector = createInjectorWithProvidedMap(map);
assertEquals(injector.getInstance(Key.get(new TypeLiteral<Cache<String, Node>>() {
assertEquals(injector.getInstance(Key.get(new TypeLiteral<LoadingCache<String, Node>>() {
})).asMap(), map);
Cache<String, Node> store = getStore(injector);
LoadingCache<String, Node> 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<String, Node> map = Maps.newConcurrentMap();
Cache<String, Node> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(map)));
LoadingCache<String, Node> 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<String, Node> getStore(Injector injector) {
return injector.getInstance(Key.get(new TypeLiteral<Cache<String, Node>>() {
private LoadingCache<String, Node> getStore(Injector injector) {
return injector.getInstance(Key.get(new TypeLiteral<LoadingCache<String, Node>>() {
}));
}
@ -118,7 +118,7 @@ public class CacheNodeStoreModuleTest {
});
}
private Injector createInjectorWithProvidedCache(Cache<String, Node> cache) {
private Injector createInjectorWithProvidedCache(LoadingCache<String, Node> cache) {
return Guice.createInjector(new CacheNodeStoreModule(cache), new AbstractModule() {
@Override
@ -130,14 +130,14 @@ public class CacheNodeStoreModuleTest {
});
}
private void check(Map<String, Node> map, Cache<String, Node> store, String key, String id, String name)
private void check(Map<String, Node> map, LoadingCache<String, Node> 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<String, Node> map, Cache<String, Node> store, String key) {
private void remove(Map<String, Node> map, LoadingCache<String, Node> 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<String, Node> map, Cache<String, Node> store, String key, String id, String name)
private void checkConsistent(Map<String, Node> map, LoadingCache<String, Node> 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<String, Node> map, Cache<String, Node> store, String key, String id, String name) {
private void put(Map<String, Node> map, LoadingCache<String, Node> 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());

View File

@ -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<Map<String, InputStream>>() {
}, Names.named("yaml"))), map);
Cache<String, Node> store = getStore(injector);
LoadingCache<String, Node> 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<String, Node> getStore(Injector injector) {
return injector.getInstance(Key.get(new TypeLiteral<Cache<String, Node>>() {
protected LoadingCache<String, Node> getStore(Injector injector) {
return injector.getInstance(Key.get(new TypeLiteral<LoadingCache<String, Node>>() {
}));
}
@ -148,14 +148,14 @@ public class YamlNodeStoreModuleTest {
});
}
protected void check(Map<String, InputStream> map, Cache<String, Node> store, String key, String id, String name)
protected void check(Map<String, InputStream> map, LoadingCache<String, Node> 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<String, InputStream> map, Cache<String, Node> store, String key) {
protected void remove(Map<String, InputStream> map, LoadingCache<String, Node> 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<String, InputStream> map, Cache<String, Node> store, String key, String id,
protected void checkConsistent(Map<String, InputStream> map, LoadingCache<String, Node> 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<String, InputStream> map, Cache<String, Node> store, String key, String id, String name) {
protected void put(Map<String, InputStream> map, LoadingCache<String, Node> 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()));

View File

@ -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<String, URI> cdnContainer(final CloudFilesClient client) {
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function<String, URI>() {
public URI apply(String container) {
protected LoadingCache<String, URI> cdnContainer(final CloudFilesClient client) {
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader<String, URI>() {
@Override
public URI load(String container) {
ContainerCDNMetadata md = client.getCDNMetadata(container);
return md != null ? md.getCDNUri() : null;
}

View File

@ -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<String, URI> {
private final Map<String, URI> cdnContainer;
private final LoadingCache<String, URI> cdnContainer;
private final CloudFilesClient sync;
@Inject
public EnableCDNAndCache(CloudFilesClient sync, Map<String, URI> cdnContainer) {
public EnableCDNAndCache(CloudFilesClient sync, LoadingCache<String, URI> cdnContainer) {
this.sync = sync;
this.cdnContainer = cdnContainer;
}

View File

@ -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<ObjectInfo, URI> {
private final Map<String, URI> cdnContainer;
private final LoadingCache<String, URI> cdnContainer;
private final Provider<UriBuilder> uriBuilders;
@Inject
public PublicUriForObjectInfo(Map<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) {
public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) {
this.cdnContainer = cdnContainer;
this.uriBuilders = uriBuilders;
}
@ -48,10 +49,10 @@ public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
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;
}
}

View File

@ -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<DriveInfo> driveNotClaimed;
private final JustProvider locationSupplier;
private final String defaultVncPassword;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> cache;
private final ExecutorService executor;
@Resource
@ -96,7 +96,7 @@ public class CloudSigmaComputeServiceAdapter implements
@Inject
public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, Predicate<DriveInfo> driveNotClaimed,
JustProvider locationSupplier, @Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword,
Cache<String, DriveInfo> cache, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
LoadingCache<String, DriveInfo> cache, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = checkNotNull(client, "client");
this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");

View File

@ -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<String, DriveInfo> cache(GetDrive getDrive) {
protected LoadingCache<String, DriveInfo> cache(GetDrive getDrive) {
return CacheBuilder.newBuilder().build(getDrive);
}

View File

@ -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<ServerInfo, NodeMetada
@Resource
protected Logger logger = Logger.NULL;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> cache;
@Inject
public DeviceToVolume(Cache<String, DriveInfo> cache) {
public DeviceToVolume(LoadingCache<String, DriveInfo> cache) {
this.cache = checkNotNull(cache, "cache");
}
@ -149,10 +149,10 @@ public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetada
@Resource
protected Logger logger = Logger.NULL;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> cache;
@Inject
public GetImageIdFromServer(Cache<String, DriveInfo> cache) {
public GetImageIdFromServer(LoadingCache<String, DriveInfo> cache) {
this.cache = cache;
}

View File

@ -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<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine(
protected LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine(
CacheLoader<Long, Set<IPForwardingRule>> getIPForwardingRules) {
return CacheBuilder.newBuilder().build(getIPForwardingRules);
}

View File

@ -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<VirtualMachine, No
private final FindLocationForVirtualMachine findLocationForVirtualMachine;
private final FindHardwareForVirtualMachine findHardwareForVirtualMachine;
private final FindImageForVirtualMachine findImageForVirtualMachine;
private final Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
private final LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
@Inject
VirtualMachineToNodeMetadata(FindLocationForVirtualMachine findLocationForVirtualMachine,
FindHardwareForVirtualMachine findHardwareForVirtualMachine,
FindImageForVirtualMachine findImageForVirtualMachine,
Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine");
this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine");
this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine");

View File

@ -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<Long, Set<IPForwardingRule>> vmToRules;
private final LoadingCache<Long, Set<IPForwardingRule>> vmToRules;
private final Map<String, Credentials> credentialStore;
@Inject
@ -94,7 +94,7 @@ public class CloudStackComputeServiceAdapter implements
@Memoized Supplier<Map<Long, Network>> networkSupplier,
BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult,
StaticNATVirtualMachineInNetwork.Factory staticNATVMInNetwork,
CreatePortForwardingRulesForIP setupPortForwardingRulesForIP, Cache<Long, Set<IPForwardingRule>> vmToRules,
CreatePortForwardingRulesForIP setupPortForwardingRulesForIP, LoadingCache<Long, Set<IPForwardingRule>> vmToRules,
Map<String, Credentials> credentialStore) {
this.client = checkNotNull(client, "client");
this.jobComplete = checkNotNull(jobComplete, "jobComplete");

View File

@ -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<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
private final LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
@Inject
public CreatePortForwardingRulesForIP(CloudStackClient client,
BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult,
Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
this.client = checkNotNull(client, "client");
this.blockUntilJobCompletesAndReturnResult = checkNotNull(blockUntilJobCompletesAndReturnResult,
"blockUntilJobCompletesAndReturnResult");

View File

@ -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<Long, Set<IPForwardingRule>> getIPForwardingRuleByVirtualMachine(
protected LoadingCache<Long, Set<IPForwardingRule>> getIPForwardingRuleByVirtualMachine(
GetIPForwardingRulesByVirtualMachine getIPForwardingRule) {
return CacheBuilder.newBuilder().build(getIPForwardingRule);
}

View File

@ -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<RegionAndName, KeyPair> credentialsMap;
private final Cache<RegionAndName, String> securityGroupMap;
private final LoadingCache<RegionAndName, String> securityGroupMap;
@Inject
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> 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<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") Cache<RegionAndName, String> securityGroupMap) {
ConcurrentMap<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy,
templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended,

View File

@ -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<Set<? extends Image>> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
final Supplier<Cache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<Cache<RegionAndName, ? extends Image>>>() {}));
final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {}));
return new Supplier<Set<? extends Image>>() {
@Override
public Set<? extends Image> get() {
@ -92,7 +92,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
@Provides
@Singleton
protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
protected Supplier<LoadingCache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
final RegionAndNameToImageSupplier supplier) {
return supplier;
}

View File

@ -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<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
protected LoadingCache<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
return CacheBuilder.newBuilder().build(in);
}
@ -141,7 +141,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
@Provides
@Singleton
@Named("SECURITY")
protected Cache<RegionAndName, String> securityGroupMap(CacheLoader<RegionAndName, String> in) {
protected LoadingCache<RegionAndName, String> securityGroupMap(CacheLoader<RegionAndName, String> in) {
return CacheBuilder.newBuilder().build(in);
}

View File

@ -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<RunningInstance, Credentials> {
private final ConcurrentMap<RegionAndName, KeyPair> credentialsMap;
private final Supplier<Cache<RegionAndName, ? extends Image>> imageMap;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap;
@Inject
CredentialsForInstance(ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
Supplier<Cache<RegionAndName, ? extends Image>> imageMap) {
Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap) {
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
this.imageMap = imageMap;
}

View File

@ -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<RunningInstance,
protected final Supplier<Set<? extends Location>> locations;
protected final Supplier<Set<? extends Hardware>> hardware;
protected final Supplier<Cache<RegionAndName, ? extends Image>> imageMap;
protected final Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap;
protected final Map<String, Credentials> credentialStore;
protected final Map<InstanceState, NodeState> instanceToNodeState;
@Inject
protected RunningInstanceToNodeMetadata(Map<InstanceState, NodeState> instanceToNodeState,
Map<String, Credentials> credentialStore, Supplier<Cache<RegionAndName, ? extends Image>> imageMap,
Map<String, Credentials> credentialStore, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap,
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware) {
this.locations = checkNotNull(locations, "locations");
this.hardware = checkNotNull(hardware, "hardware");
@ -133,7 +134,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
Image image = imageMap.get().getUnchecked(regionAndName);
if (image != null)
builder.operatingSystem(image.getOperatingSystem());
} catch (NullPointerException e) {
} catch (CacheLoader.InvalidCacheLoadException e) {
logger.debug("image not found for %s: %s", regionAndName, e);
} catch (UncheckedExecutionException e) {
logger.debug("error getting image for %s: %s", regionAndName, e);

View File

@ -39,7 +39,8 @@ import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.util.Throwables2;
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.util.concurrent.UncheckedExecutionException;
@ -49,13 +50,13 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
*/
public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
private final Supplier<Cache<RegionAndName, ? extends Image>> lazyImageCache;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> lazyImageCache;
@Inject
protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Supplier<Cache<RegionAndName, ? extends Image>> imageMap) {
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Supplier<LoadingCache<RegionAndName, ? extends Image>> 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()));
}
}

View File

@ -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<RegionAndName, KeyPair> credentialsMap;
@VisibleForTesting
public final Cache<RegionAndName, String> securityGroupMap;
public final LoadingCache<RegionAndName, String> securityGroupMap;
@VisibleForTesting
public final Provider<RunInstancesOptions> optionsProvider;
@Inject
public CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions(Function<RegionAndName, KeyPair> makeKeyPair,
ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
@Named("SECURITY") Cache<RegionAndName, String> securityGroupMap,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
Provider<RunInstancesOptions> optionsProvider) {
this.makeKeyPair = checkNotNull(makeKeyPair, "makeKeyPair");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");

View File

@ -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<RunningInstance, Credentials> instanceToCredentials;
final LoadingCache<RunningInstance, Credentials> instanceToCredentials;
final Map<String, Credentials> credentialStore;
final Provider<TemplateBuilder> templateBuilderProvider;
@ -88,7 +88,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
Provider<TemplateBuilder> templateBuilderProvider,
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
InstancePresent instancePresent, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
Cache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
LoadingCache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
ComputeUtils utils) {
this.client = checkNotNull(client, "client");
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider");

View File

@ -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<Set<? extends Image>> {
private final DescribeImagesParallel describer;
private final String[] amiOwners;
private final EC2ImageParser parser;
private final Supplier<Cache<RegionAndName, ? extends Image>> cache;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache;
@Inject
protected EC2ImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer,
@Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier<Cache<RegionAndName, ? extends Image>> cache,
@Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
EC2ImageParser parser) {
this.regions = regions;
this.describer = describer;

View File

@ -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<Cache<RegionAndName, ? extends Image>> {
private final Cache<RegionAndName, Image> cache;
public class RegionAndNameToImageSupplier implements Supplier<LoadingCache<RegionAndName, ? extends Image>> {
private final LoadingCache<RegionAndName, Image> cache;
@Inject
protected RegionAndNameToImageSupplier(CacheLoader<RegionAndName, Image> regionAndIdToImage,
@ -49,7 +49,7 @@ public class RegionAndNameToImageSupplier implements Supplier<Cache<RegionAndNam
}
@Override
public Cache<RegionAndName, ? extends Image> get() {
public LoadingCache<RegionAndName, ? extends Image> get() {
return cache;
}
}

View File

@ -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<Cache<RegionAndName, ? extends Image>> imageCache = Suppliers.<Cache<RegionAndName, ? extends Image>> ofInstance(
Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache = Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(
CacheBuilder.newBuilder().<RegionAndName,Image>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<RegionAndName, Image> imageMap = (ImmutableMap<RegionAndName, Image>) ImagesToRegionAndIdMap.imagesToMap(images.get());
Supplier<Cache<RegionAndName, ? extends Image>> imageCache = Suppliers.<Cache<RegionAndName, ? extends Image>> ofInstance(
Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache = Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(
CacheBuilder.newBuilder().<RegionAndName,Image>build(CacheLoader.from(Functions.forMap(imageMap))));
return newTemplateBuilder(images, imageCache);
}
@SuppressWarnings("unchecked")
private TemplateBuilder newTemplateBuilder(Supplier<Set<? extends Image>> images, Supplier<Cache<RegionAndName, ? extends Image>> imageCache) {
private TemplateBuilder newTemplateBuilder(Supplier<Set<? extends Image>> images, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache) {
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateOptions defaultOptions = createMock(TemplateOptions.class);

View File

@ -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<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction);
LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(nullReturningFunction);
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small32().build()), ImmutableSet
.of(provider), ImmutableMap.<String, Credentials> of(),
@ -235,13 +235,13 @@ public class RunningInstanceToNodeMetadataTest {
return ImagesToRegionAndIdMap.imagesToMap(images).get(from);
}
};
Cache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(getRealImage);
LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(getRealImage);
return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage);
}
private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore,
Map<InstanceState, NodeState> instanceToNodeState, Cache<RegionAndName, Image> instanceToImage) {
Map<InstanceState, NodeState> instanceToNodeState, LoadingCache<RegionAndName, Image> instanceToImage) {
Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() {
@Override
@ -259,7 +259,7 @@ public class RunningInstanceToNodeMetadataTest {
};
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(instanceToNodeState, credentialStore,
Suppliers.<Cache<RegionAndName, ? extends Image>> ofInstance(instanceToImage), locationSupplier,
Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(instanceToImage), locationSupplier,
hardwareSupplier);
return parser;
}

View File

@ -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<Set<? extends Hardware>> sizes, Location defaultLocation,
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
Cache<RegionAndName, ? extends Image> imageMap;
LoadingCache<RegionAndName, ? extends Image> 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.<Cache<RegionAndName, ? extends Image>>ofInstance(imageMap));
optionsProvider, templateBuilderProvider, Suppliers.<LoadingCache<RegionAndName, ? extends Image>>ofInstance(imageMap));
}
@SuppressWarnings("unchecked")

View File

@ -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<RegionAndName, KeyPair> makeKeyPair = createMock(Function.class);
ConcurrentMap<RegionAndName, KeyPair> credentialsMap = createMock(ConcurrentMap.class);
Cache<RegionAndName, String> securityGroupMap = createMock(Cache.class);
LoadingCache<RegionAndName, String> securityGroupMap = createMock(LoadingCache.class);
return new CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions(makeKeyPair, credentialsMap,
securityGroupMap, OPTIONS_PROVIDER);
}

View File

@ -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<RunningInstance, Credentials> instanceToCredentials = createMock(Cache.class);
LoadingCache<RunningInstance, Credentials> instanceToCredentials = createMock(LoadingCache.class);
Map<String, Credentials> credentialStore = createMock(Map.class);
ComputeUtils utils = createMock(ComputeUtils.class);
return new EC2CreateNodesInGroupThenAddToSet(client, Providers.<TemplateBuilder> of(template),

View File

@ -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<T> extends RestClientTest<T> {
@Provides
@Singleton
Cache<RegionAndName, Image> provide(){
LoadingCache<RegionAndName, Image> provide(){
return CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image>() {
@Override

View File

@ -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<DriveInfo> driveNotClaimed;
private final Map<String, WellKnownImage> preinstalledImages;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> 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<DriveInfo> driveNotClaimed,
JustProvider locationSupplier, Map<String, WellKnownImage> preinstalledImages, Cache<String, DriveInfo> cache,
JustProvider locationSupplier, Map<String, WellKnownImage> preinstalledImages, LoadingCache<String, DriveInfo> cache,
@Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = checkNotNull(client, "client");

View File

@ -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<String, DriveInfo> cache(GetDrive getDrive) {
protected LoadingCache<String, DriveInfo> cache(GetDrive getDrive) {
return CacheBuilder.newBuilder().build(getDrive);
}

View File

@ -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<ServerInfo, NodeMetada
@Resource
protected Logger logger = Logger.NULL;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> cache;
@Inject
public DeviceToVolume(Cache<String, DriveInfo> cache) {
public DeviceToVolume(LoadingCache<String, DriveInfo> cache) {
this.cache = checkNotNull(cache, "cache");
}
@ -149,10 +149,10 @@ public class ServerInfoToNodeMetadata implements Function<ServerInfo, NodeMetada
@Resource
protected Logger logger = Logger.NULL;
private final Cache<String, DriveInfo> cache;
private final LoadingCache<String, DriveInfo> cache;
@Inject
public GetImageIdFromServer(Cache<String, DriveInfo> cache) {
public GetImageIdFromServer(LoadingCache<String, DriveInfo> cache) {
this.cache = cache;
}

View File

@ -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

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider;
private final Map<String, AccessControlList> bucketAcls;
private final LoadingCache<String, AccessControlList> 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<FetchBlobMetadata> fetchBlobMetadataProvider, Map<String, AccessControlList> bucketAcls) {
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, LoadingCache<String, AccessControlList> 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<String> 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);
}

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider;
private final Map<String, AccessControlList> bucketAcls;
private final LoadingCache<String, AccessControlList> bucketAcls;
@Inject
protected S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> 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<FetchBlobMetadata> fetchBlobMetadataProvider, Map<String, AccessControlList> bucketAcls) {
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, LoadingCache<String, AccessControlList> 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);
}

View File

@ -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<String, AccessControlList> bucketAcls(final S3Client client) {
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(
new Function<String, AccessControlList>() {
public AccessControlList apply(String bucketName) {
protected LoadingCache<String, AccessControlList> bucketAcls(final S3Client client) {
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(
new CacheLoader<String, AccessControlList>() {
@Override
public AccessControlList load(String bucketName) {
return client.getBucketACL(bucketName);
}

View File

@ -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<ObjectMetadata, MutableBlobMetadata> {
private final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
private final Map<String, AccessControlList> bucketAcls;
private final LoadingCache<String, AccessControlList> bucketAcls;
@Inject
public ObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName,
Map<String, AccessControlList> bucketAcls) {
LoadingCache<String, AccessControlList> bucketAcls) {
this.ifDirectoryReturnName = ifDirectoryReturnName;
this.bucketAcls = bucketAcls;
}
@ -56,11 +56,11 @@ public class ObjectToBlobMetadata implements Function<ObjectMetadata, MutableBlo
MutableBlobMetadata to = new MutableBlobMetadataImpl();
HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata());
try {
AccessControlList bucketAcl = bucketAcls.get(from.getBucket());
AccessControlList bucketAcl = bucketAcls.getUnchecked(from.getBucket());
if (bucketAcl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ))
to.setPublicUri(from.getUri());
} catch (NullPointerException e) {
// MapMaker cannot return null, but a call to get acls can
} catch (CacheLoader.InvalidCacheLoadException e) {
// nulls not permitted from cache loader
}
to.setUri(from.getUri());
to.setContainer(from.getBucket());

View File

@ -109,7 +109,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
<version>11.0-rc1</version>
</dependency>
</dependencies>

View File

@ -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> T proxy(Class<T> clazz, Object async,
@Named("sync") Cache<ClassMethodArgs, Object> delegateMap,
@Named("sync") LoadingCache<ClassMethodArgs, Object> delegateMap,
Map<Class<?>, Class<?>> sync2Async, Map<String, Long> 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<Method, Method> methodMap;
private final Map<Method, Method> syncMethodMap;
private final Map<Method, Long> timeoutMap;
private final Cache<ClassMethodArgs, Object> delegateMap;
private final LoadingCache<ClassMethodArgs, Object> delegateMap;
private final Map<Class<?>, Class<?>> sync2Async;
private static final Set<Method> objectMethods = ImmutableSet.of(Object.class.getMethods());
private static final Set<Method> objectMethods = ImmutableSet.copyOf(Object.class.getMethods());
@Inject
private SyncProxy(Class<?> declaring, Object async,
@Named("sync") Cache<ClassMethodArgs, Object> delegateMap, Map<Class<?>,
@Named("sync") LoadingCache<ClassMethodArgs, Object> delegateMap, Map<Class<?>,
Class<?>> sync2Async, final Map<String, Long> timeouts)
throws SecurityException, NoSuchMethodException {
this.delegateMap = delegateMap;

View File

@ -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<T extends Enum<T>> implements J
}
}
private final static Cache<Class<?>, Method> classToConvert = CacheBuilder.newBuilder()
private final static LoadingCache<Class<?>, Method> classToConvert = CacheBuilder.newBuilder()
.build(new CacheLoader<Class<?>, Method>() {
@Override

View File

@ -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<S, A> implements Provider<S> {
@Singleton
public S get() {
A client = (A) injector.getInstance(Key.get(asyncClientType));
Cache<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
new TypeLiteral<Cache<ClassMethodArgs, Object>>() {
LoadingCache<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
new TypeLiteral<LoadingCache<ClassMethodArgs, Object>>() {
}, Names.named("sync")));
try {
return (S) SyncProxy.proxy(syncClientType, client, delegateMap, sync2Async,

View File

@ -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<ClassMethodArgs, Object> {
@Inject
Injector injector;
private final Cache<ClassMethodArgs, Object> asyncMap;
private final Provider<Cache<ClassMethodArgs, Object>> delegateMap;
private final LoadingCache<ClassMethodArgs, Object> asyncMap;
private final Provider<LoadingCache<ClassMethodArgs, Object>> delegateMap;
Map<Class<?>, Class<?>> sync2Async;
@Inject
CreateClientForCaller(@Named("async") Cache<ClassMethodArgs, Object> asyncMap,
@Named("sync") Provider<Cache<ClassMethodArgs, Object>> delegateMap) {
CreateClientForCaller(@Named("async") LoadingCache<ClassMethodArgs, Object> asyncMap,
@Named("sync") Provider<LoadingCache<ClassMethodArgs, Object>> delegateMap) {
this.asyncMap = asyncMap;
this.delegateMap = delegateMap;
}

View File

@ -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<S, A> extends AbstractModule {
@Provides
@Singleton
@Named("sync")
Cache<ClassMethodArgs, Object> provideSyncDelegateMap(
LoadingCache<ClassMethodArgs, Object> provideSyncDelegateMap(
CreateClientForCaller createClientForCaller) {
createClientForCaller.sync2Async = delegates;
return CacheBuilder.newBuilder().build(createClientForCaller);

View File

@ -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<Class<?>, Boolean> seedAnnotationCache(SeedAnnotationCache seedAnnotationCache) {
protected LoadingCache<Class<?>, Boolean> seedAnnotationCache(SeedAnnotationCache seedAnnotationCache) {
return CacheBuilder.newBuilder().build(seedAnnotationCache);
}
@Provides
@Singleton
@Named("async")
Cache<ClassMethodArgs, Object> provideAsyncDelegateMap(CreateAsyncClientForCaller createAsyncClientForCaller) {
LoadingCache<ClassMethodArgs, Object> 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<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
new TypeLiteral<Cache<ClassMethodArgs, Object>>() {
LoadingCache<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
new TypeLiteral<LoadingCache<ClassMethodArgs, Object>>() {
}, Names.named("async")));
AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector, factory, util, typeLiteral, delegateMap);
injector.injectMembers(proxy);

View File

@ -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<T> implements InvocationHandler {
@Resource
protected Logger logger = Logger.NULL;
private final Cache<ClassMethodArgs, Object> delegateMap;
private final LoadingCache<ClassMethodArgs, Object> delegateMap;
@SuppressWarnings("unchecked")
@Inject
public AsyncRestClientProxy(Injector injector, Factory factory, RestAnnotationProcessor<T> util,
TypeLiteral<T> typeLiteral, @Named("async") Cache<ClassMethodArgs, Object> delegateMap) {
TypeLiteral<T> typeLiteral, @Named("async") LoadingCache<ClassMethodArgs, Object> delegateMap) {
this.injector = injector;
this.annotationProcessor = util;
this.declaring = (Class<T>) typeLiteral.getRawType();

View File

@ -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<T> {
private final Class<T> declaring;
// TODO replace with Table object
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToBinderParamAnnotation = createMethodToIndexOfParamToAnnotation(BinderParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToWrapWithAnnotation = createMethodToIndexOfParamToAnnotation(WrapWith.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointAnnotations = createMethodToIndexOfParamToAnnotation(Endpoint.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointParamAnnotations = createMethodToIndexOfParamToAnnotation(EndpointParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToMatrixParamAnnotations = createMethodToIndexOfParamToAnnotation(MatrixParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(PayloadParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
static final Cache<Method, Cache<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToBinderParamAnnotation = createMethodToIndexOfParamToAnnotation(BinderParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToWrapWithAnnotation = createMethodToIndexOfParamToAnnotation(WrapWith.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointAnnotations = createMethodToIndexOfParamToAnnotation(Endpoint.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointParamAnnotations = createMethodToIndexOfParamToAnnotation(EndpointParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToMatrixParamAnnotations = createMethodToIndexOfParamToAnnotation(MatrixParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(PayloadParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
static final Map<MethodKey, Method> delegationMap = newHashMap();
static Cache<Method, Cache<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
static LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
final Class<? extends Annotation> annotation) {
return CacheBuilder.newBuilder().build(new CacheLoader<Method, Cache<Integer, Set<Annotation>>>() {
public Cache<Integer, Set<Annotation>> load(Method method) {
return CacheBuilder.newBuilder().build(new CacheLoader<Method, LoadingCache<Integer, Set<Annotation>>>() {
public LoadingCache<Integer, Set<Annotation>> load(Method method) {
return CacheBuilder.newBuilder().build(CacheLoader.from(new GetAnnotationsForMethodParameterIndex(method, annotation)));
}
});
@ -229,7 +229,7 @@ public class RestAnnotationProcessor<T> {
};
static final Cache<Method, Set<Integer>> methodToIndexesOfOptions = CacheBuilder.newBuilder().build(
static final LoadingCache<Method, Set<Integer>> methodToIndexesOfOptions = CacheBuilder.newBuilder().build(
new CacheLoader<Method, Set<Integer>>() {
@Override
public Set<Integer> load(Method method) {
@ -246,7 +246,7 @@ public class RestAnnotationProcessor<T> {
private final ParseSax.Factory parserFactory;
private final HttpUtils utils;
private final Provider<UriBuilder> uriBuilderProvider;
private final Cache<Class<?>, Boolean> seedAnnotationCache;
private final LoadingCache<Class<?>, Boolean> seedAnnotationCache;
private final String apiVersion;
private char[] skips;
@ -308,7 +308,7 @@ public class RestAnnotationProcessor<T> {
@SuppressWarnings("unchecked")
@Inject
public RestAnnotationProcessor(Injector injector, Cache<Class<?>, Boolean> seedAnnotationCache,
public RestAnnotationProcessor(Injector injector, LoadingCache<Class<?>, Boolean> seedAnnotationCache,
@Named(Constants.PROPERTY_API_VERSION) String apiVersion, ParseSax.Factory parserFactory, HttpUtils utils,
TypeLiteral<T> typeLiteral) throws ExecutionException {
this.declaring = (Class<T>) typeLiteral.getRawType();
@ -1010,7 +1010,7 @@ public class RestAnnotationProcessor<T> {
}
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
Cache<Method, Cache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
if (indexToPayloadAnnotation.size() > 1) {
throw new IllegalStateException(String.format(
@ -1021,7 +1021,7 @@ public class RestAnnotationProcessor<T> {
}
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
Cache<Method, Cache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> toRefine) throws ExecutionException {
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method).asMap(),
new Predicate<Set<Annotation>>() {
public boolean apply(Set<Annotation> input) {
@ -1061,7 +1061,7 @@ public class RestAnnotationProcessor<T> {
final Object... args) throws ExecutionException {
Multimap<String, String> headers = LinkedHashMultimap.create();
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
Cache<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToHeaderParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
String value = args[entry.getKey()].toString();
@ -1128,7 +1128,7 @@ public class RestAnnotationProcessor<T> {
List<? extends Part> getParts(Method method, Object[] args, Iterable<Entry<String, String>> iterable) throws ExecutionException {
List<Part> parts = newLinkedList();
Cache<Integer, Set<Annotation>> indexToPartParam = methodToIndexOfParamToPartParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToPartParam = methodToIndexOfParamToPartParamAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToPartParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
PartParam param = (PartParam) key;
@ -1168,9 +1168,9 @@ public class RestAnnotationProcessor<T> {
private Multimap<String, String> getPathParamKeyValues(Method method, Object... args) throws ExecutionException {
Multimap<String, String> pathParamValues = LinkedHashMultimap.create();
Cache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPathParamAnnotations.get(method);
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
@ -1205,9 +1205,9 @@ public class RestAnnotationProcessor<T> {
private Multimap<String, String> getMatrixParamKeyValues(Method method, Object... args) throws ExecutionException {
Multimap<String, String> matrixParamValues = LinkedHashMultimap.create();
Cache<Integer, Set<Annotation>> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations.get(method);
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToMatrixParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
@ -1234,9 +1234,9 @@ public class RestAnnotationProcessor<T> {
private Multimap<String, String> getFormParamKeyValues(Method method, Object... args) throws ExecutionException {
Multimap<String, String> formParamValues = LinkedHashMultimap.create();
Cache<Integer, Set<Annotation>> indexToFormParam = methodToIndexOfParamToFormParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToFormParam = methodToIndexOfParamToFormParamAnnotations.get(method);
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToFormParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
@ -1265,9 +1265,9 @@ public class RestAnnotationProcessor<T> {
private Multimap<String, String> getQueryParamKeyValues(Method method, Object... args) throws ExecutionException {
Multimap<String, String> queryParamValues = LinkedHashMultimap.create();
Cache<Integer, Set<Annotation>> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToQueryParam = methodToIndexOfParamToQueryParamAnnotations.get(method);
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToQueryParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
@ -1294,8 +1294,8 @@ public class RestAnnotationProcessor<T> {
private Map<String, String> buildPostParams(Method method, Object... args) throws ExecutionException {
Map<String, String> postParams = newHashMap();
Cache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method);
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());

View File

@ -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<Character, Pattern> CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder()
public final static LoadingCache<Character, Pattern> CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder()
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
@Override
public Pattern load(Character plain) throws ExecutionException {
@ -63,7 +63,7 @@ public class Patterns {
}
});
public final static Cache<Character, Pattern> CHAR_TO_PATTERN = CacheBuilder.newBuilder()
public final static LoadingCache<Character, Pattern> CHAR_TO_PATTERN = CacheBuilder.newBuilder()
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
@Override
public Pattern load(Character plain) {
@ -71,7 +71,7 @@ public class Patterns {
}
});
public final static Cache<String, Pattern> TOKEN_TO_PATTERN = CacheBuilder.newBuilder()
public final static LoadingCache<String, Pattern> TOKEN_TO_PATTERN = CacheBuilder.newBuilder()
.<String, Pattern> build(new CacheLoader<String, Pattern>() {
@Override
public Pattern load(String tokenValue) {

View File

@ -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<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
LoadingCache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
CacheLoader.from(Functions.<Object> constant(null)));
sync = SyncProxy.proxy(Sync.class, new Async(), cache, ImmutableMap.<Class<?>, 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<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
LoadingCache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
CacheLoader.from(Functions.<Object> constant(null)));
SyncProxy.proxy(SyncWrongException.class, new Async(), cache, ImmutableMap.<Class<?>, Class<?>> of(),
ImmutableMap.<String, Long> of());
@ -278,7 +278,7 @@ public class SyncProxyTest {
@Test(enabled = false, expectedExceptions = IllegalArgumentException.class)
public void testNoTimeOutException() throws IllegalArgumentException, SecurityException, NoSuchMethodException,
IOException {
Cache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
LoadingCache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
CacheLoader.from(Functions.<Object> constant(null)));
SyncProxy.proxy(SyncNoTimeOut.class, new Async(), cache, ImmutableMap.<Class<?>, Class<?>> of(),
ImmutableMap.<String, Long> of());
@ -299,7 +299,7 @@ public class SyncProxyTest {
@Test(enabled = false, expectedExceptions = RuntimeException.class)
public void testClassOverridePropTimeout() throws Exception {
Cache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
LoadingCache<ClassMethodArgs, Object> cache = CacheBuilder.newBuilder().build(
CacheLoader.from(Functions.<Object> constant(null)));
final SyncClassOverride sync2 = SyncProxy.proxy(SyncClassOverride.class, new Async(), cache,
ImmutableMap.<Class<?>, Class<?>> of(), ImmutableMap.<String, Long> of("SyncClassOverride", 100L));

View File

@ -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<String, String> cache = CacheBuilder.newBuilder().build(new CacheLoader<String, String>() {
LoadingCache<String, String> cache = CacheBuilder.newBuilder().build(new CacheLoader<String, String>() {
@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);

View File

@ -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<RegionAndName, String> placementGroupMap;
private final LoadingCache<RegionAndName, String> placementGroupMap;
private final Predicate<PlacementGroup> 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<RegionAndName, KeyPair> credentialsMap,
@Named("SECURITY") Cache<RegionAndName, String> securityGroupMap,
@Named("PLACEMENT") Cache<RegionAndName, String> placementGroupMap,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
@Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap,
@Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted,
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, AWSEC2AsyncClient aclient) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,

View File

@ -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<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Supplier<Cache<RegionAndName, ? extends Image>> imageMap) {
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, imageMap);
}

View File

@ -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<Set<? extends Image>> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
final Supplier<Cache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<Cache<RegionAndName, ? extends Image>>>() {}));
final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {}));
return new Supplier<Set<? extends Image>>() {
@Override
public Set<? extends Image> get() {
@ -158,7 +158,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext
@Provides
@Singleton
protected Supplier<Cache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
protected Supplier<LoadingCache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
final RegionAndNameToImageSupplier supplier) {
return supplier;
}

View File

@ -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<RegionAndName, String> placementGroupMap(CreatePlacementGroupIfNeeded in) {
protected LoadingCache<RegionAndName, String> placementGroupMap(CreatePlacementGroupIfNeeded in) {
return CacheBuilder.newBuilder().build(in);
}

View File

@ -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<InstanceState, NodeState> instanceToNodeState,
Map<String, Credentials> credentialStore, Supplier<Cache<RegionAndName, ? extends Image>> imageMap,
Map<String, Credentials> credentialStore, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap,
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware) {
super(instanceToNodeState, credentialStore, imageMap, locations, hardware);
}

View File

@ -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<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
Cache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
LoadingCache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
ComputeUtils utils, SpotInstanceRequestToAWSRunningInstance spotConverter) {
super(client, templateBuilderProvider, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, instancePresent,
runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);

View File

@ -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<RegionAndName, String> placementGroupMap;
final LoadingCache<RegionAndName, String> placementGroupMap;
@VisibleForTesting
final CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded;
@VisibleForTesting
@ -68,9 +68,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
@Inject
public CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(
Function<RegionAndName, KeyPair> makeKeyPair, ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
@Named("SECURITY") Cache<RegionAndName, String> securityGroupMap,
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
Provider<RunInstancesOptions> optionsProvider,
@Named("PLACEMENT") Cache<RegionAndName, String> placementGroupMap,
@Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap,
CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded,
Function<RegionNameAndPublicKeyMaterial, KeyPair> importExistingKeyPair) {
super(makeKeyPair, credentialsMap, securityGroupMap, optionsProvider);

View File

@ -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<Set<? extends Image>> {
private final String amiQuery;
private final Iterable<String> clusterRegions;
private final String ccAmiQuery;
private final Supplier<Cache<RegionAndName, ? extends Image>> cache;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache;
@Inject
protected AWSEC2ImageSupplier(@Region Set<String> 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<RegionAndName, ? extends Image>> cache,
Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
CallForImages.Factory factory, @ClusterCompute Set<String> clusterComputeIds,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.factory = factory;

View File

@ -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<RegionAndName, ? extends Image> backing = ImagesToRegionAndIdMap.imagesToMap(images);
Cache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image> (){
LoadingCache<RegionAndName, Image> instanceToImage = CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image> (){
@Override
public Image load(RegionAndName key) throws Exception {
@ -175,7 +175,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
private AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore,
Map<InstanceState, NodeState> instanceToNodeState, Cache<RegionAndName, ? extends Image> instanceToImage) {
Map<InstanceState, NodeState> instanceToNodeState, LoadingCache<RegionAndName, ? extends Image> instanceToImage) {
Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() {
@Override
@ -193,7 +193,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
};
AWSRunningInstanceToNodeMetadata parser = new AWSRunningInstanceToNodeMetadata(instanceToNodeState,
credentialStore, Suppliers.<Cache<RegionAndName, ? extends Image>> ofInstance(instanceToImage),
credentialStore, Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(instanceToImage),
locationSupplier, hardwareSupplier);
return parser;
}

View File

@ -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<RegionAndName, KeyPair> makeKeyPair = createMock(Function.class);
ConcurrentMap<RegionAndName, KeyPair> credentialsMap = createMock(ConcurrentMap.class);
Cache<RegionAndName, String> securityGroupMap = createMock(Cache.class);
Cache<RegionAndName, String> placementGroupMap = createMock(Cache.class);
LoadingCache<RegionAndName, String> securityGroupMap = createMock(LoadingCache.class);
LoadingCache<RegionAndName, String> placementGroupMap = createMock(LoadingCache.class);
Function<RegionNameAndPublicKeyMaterial, KeyPair> importExistingKeyPair = createMock(Function.class);
CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded = createMock(CreatePlacementGroupIfNeeded.class);

View File

@ -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<T> extends RestClientTest<T> {
@Provides
@Singleton
Cache<RegionAndName, Image> provide(){
LoadingCache<RegionAndName, Image> provide(){
return CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image>() {
@Override

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider, Map<String, AccessControlList> bucketAcls,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, LoadingCache<String, AccessControlList> bucketAcls,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, service, defaultLocation, locations, async, sync, bucket2ResourceMd,
container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object,

View File

@ -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<FetchBlobMetadata> fetchBlobMetadataProvider, Map<String, AccessControlList> bucketAcls,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, LoadingCache<String, AccessControlList> bucketAcls,
Provider<MultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, defaultLocation, locations, sync, bucket2ResourceMd, container2BucketListOptions,
bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object, object2BlobMd,

View File

@ -74,12 +74,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>

View File

@ -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<String, PublicAccess> containerAcls(final AzureBlobClient client) {
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(
new Function<String, PublicAccess>() {
public PublicAccess apply(String container) {
protected LoadingCache<String, PublicAccess> containerAcls(final AzureBlobClient client) {
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(
new CacheLoader<String, PublicAccess>() {
@Override
public PublicAccess load(String container) {
return client.getPublicAccessForContainer(container);
}

View File

@ -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<BlobProperties, MutableBlobMetadata> {
private final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
private final Map<String, PublicAccess> containerAcls;
private final LoadingCache<String, PublicAccess> containerAcls;
@Inject
public BlobPropertiesToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName,
Map<String, PublicAccess> containerAcls) {
LoadingCache<String, PublicAccess> containerAcls) {
this.ifDirectoryReturnName = checkNotNull(ifDirectoryReturnName, "ifDirectoryReturnName");
this.containerAcls = checkNotNull(containerAcls, "containerAcls");
}
@ -61,13 +61,14 @@ public class BlobPropertiesToBlobMetadata implements Function<BlobProperties, Mu
to.setName(from.getName());
to.setContainer(from.getContainer());
to.setUri(from.getUrl());
try {
PublicAccess containerAcl = containerAcls.get(from.getContainer());
if (containerAcl != null && containerAcl != PublicAccess.PRIVATE)
to.setPublicUri(from.getUrl());
} catch (NullPointerException e) {
// MapMaker cannot return null, but a call to get acls can
}
if (from.getContainer() != null)
try {
PublicAccess containerAcl = containerAcls.getUnchecked(from.getContainer());
if (containerAcl != PublicAccess.PRIVATE)
to.setPublicUri(from.getUrl());
} catch (CacheLoader.InvalidCacheLoadException e) {
// nulls not permitted from cache loader
}
String directoryName = ifDirectoryReturnName.execute(to);
if (directoryName != null) {
to.setName(directoryName);

View File

@ -36,7 +36,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;
@ -47,7 +47,7 @@ import com.google.common.collect.Maps;
* @author Andrea Turli
*/
@Singleton
public class ImageFromYamlStream implements Function<InputStream, Cache<String, Image>> {
public class ImageFromYamlStream implements Function<InputStream, LoadingCache<String, Image>> {
/**
* Type-safe config class for YAML
@ -63,7 +63,7 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
}
@Override
public Cache<String, Image> apply(InputStream source) {
public LoadingCache<String, Image> apply(InputStream source) {
Constructor constructor = new Constructor(Config.class);
@ -82,7 +82,7 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
return image.getId();
}
});
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
LoadingCache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
for (String node : backingMap.keySet())
cache.getUnchecked(node);
return cache;

View File

@ -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<String, Node> cache) {
public static ComputeServiceContext computeServiceForVirtualBox(LoadingCache<String, Node> cache) {
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
new CacheNodeStoreModule(cache)));