mirror of https://github.com/apache/jclouds.git
updated to guava 11 syntax
This commit is contained in:
parent
fc7bc3f638
commit
60691544c7
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.hpcloud.object.storage.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 HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreCo
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<String, URI> cdnContainer(final HPCloudObjectStorageClient client) {
|
||||
return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function<String, URI>() {
|
||||
public URI apply(String container) {
|
||||
protected LoadingCache<String, URI> cdnContainer(final HPCloudObjectStorageClient 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;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.hpcloud.object.storage.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.hpcloud.object.storage.HPCloudObjectStorageClient;
|
||||
|
||||
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 HPCloudObjectStorageClient sync;
|
||||
|
||||
@Inject
|
||||
public EnableCDNAndCache(HPCloudObjectStorageClient sync, Map<String, URI> cdnContainer) {
|
||||
public EnableCDNAndCache(HPCloudObjectStorageClient sync, LoadingCache<String, URI> cdnContainer) {
|
||||
this.sync = sync;
|
||||
this.cdnContainer = cdnContainer;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.hpcloud.object.storage.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,11 +49,11 @@ 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("")
|
||||
.build();
|
||||
} catch (NullPointerException e) {
|
||||
// MapMaker constructed maps are not allowed to return null;
|
||||
return uriBuilders.get().uri(cdnContainer.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("")
|
||||
.build();
|
||||
} catch (CacheLoader.InvalidCacheLoadException e) {
|
||||
// nulls not permitted from cache loader
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue