updated to guava 11 syntax

This commit is contained in:
Adrian Cole 2011-12-19 17:40:31 -08:00
parent fc7bc3f638
commit 60691544c7
3 changed files with 19 additions and 17 deletions

View File

@ -19,7 +19,6 @@
package org.jclouds.hpcloud.object.storage.blobstore.config; package org.jclouds.hpcloud.object.storage.blobstore.config;
import java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Singleton; 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.config.SwiftBlobStoreContextModule;
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
import com.google.common.base.Function; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.MapMaker; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -46,9 +46,10 @@ public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreCo
@Provides @Provides
@Singleton @Singleton
protected Map<String, URI> cdnContainer(final HPCloudObjectStorageClient client) { protected LoadingCache<String, URI> cdnContainer(final HPCloudObjectStorageClient client) {
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function<String, URI>() { return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader<String, URI>() {
public URI apply(String container) { @Override
public URI load(String container) {
ContainerCDNMetadata md = client.getCDNMetadata(container); ContainerCDNMetadata md = client.getCDNMetadata(container);
return md != null ? md.getCDNUri() : null; return md != null ? md.getCDNUri() : null;
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.hpcloud.object.storage.blobstore.functions; package org.jclouds.hpcloud.object.storage.blobstore.functions;
import java.net.URI; import java.net.URI;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -27,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.cache.LoadingCache;
/** /**
* *
@ -34,11 +34,11 @@ import com.google.common.base.Function;
*/ */
@Singleton @Singleton
public class EnableCDNAndCache implements Function<String, URI> { public class EnableCDNAndCache implements Function<String, URI> {
private final Map<String, URI> cdnContainer; private final LoadingCache<String, URI> cdnContainer;
private final HPCloudObjectStorageClient sync; private final HPCloudObjectStorageClient sync;
@Inject @Inject
public EnableCDNAndCache(HPCloudObjectStorageClient sync, Map<String, URI> cdnContainer) { public EnableCDNAndCache(HPCloudObjectStorageClient sync, LoadingCache<String, URI> cdnContainer) {
this.sync = sync; this.sync = sync;
this.cdnContainer = cdnContainer; this.cdnContainer = cdnContainer;
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.hpcloud.object.storage.blobstore.functions; package org.jclouds.hpcloud.object.storage.blobstore.functions;
import java.net.URI; import java.net.URI;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider; import javax.inject.Provider;
@ -29,17 +28,19 @@ import javax.ws.rs.core.UriBuilder;
import org.jclouds.openstack.swift.domain.ObjectInfo; import org.jclouds.openstack.swift.domain.ObjectInfo;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> { public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
private final Map<String, URI> cdnContainer; private final LoadingCache<String, URI> cdnContainer;
private final Provider<UriBuilder> uriBuilders; private final Provider<UriBuilder> uriBuilders;
@Inject @Inject
public PublicUriForObjectInfo(Map<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) { public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) {
this.cdnContainer = cdnContainer; this.cdnContainer = cdnContainer;
this.uriBuilders = uriBuilders; this.uriBuilders = uriBuilders;
} }
@ -48,10 +49,10 @@ public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
if (from == null) if (from == null)
return null; return null;
try { 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(); .build();
} catch (NullPointerException e) { } catch (CacheLoader.InvalidCacheLoadException e) {
// MapMaker constructed maps are not allowed to return null; // nulls not permitted from cache loader
return null; return null;
} }
} }