| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.cloudfiles.blobstore; |
| 20 | |
| 21 | import java.util.Set; |
| 22 | import java.util.concurrent.ExecutorService; |
| 23 | |
| 24 | import javax.inject.Inject; |
| 25 | import javax.inject.Named; |
| 26 | import javax.inject.Provider; |
| 27 | import javax.inject.Singleton; |
| 28 | |
| 29 | import org.jclouds.Constants; |
| 30 | import org.jclouds.blobstore.BlobStoreContext; |
| 31 | import org.jclouds.blobstore.functions.BlobToHttpGetOptions; |
| 32 | import org.jclouds.blobstore.options.CreateContainerOptions; |
| 33 | import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; |
| 34 | import org.jclouds.blobstore.util.BlobUtils; |
| 35 | import org.jclouds.cloudfiles.CloudFilesAsyncClient; |
| 36 | import org.jclouds.cloudfiles.CloudFilesClient; |
| 37 | import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache; |
| 38 | import org.jclouds.collect.Memoized; |
| 39 | import org.jclouds.concurrent.Futures; |
| 40 | import org.jclouds.domain.Location; |
| 41 | import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; |
| 42 | import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; |
| 43 | import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; |
| 44 | import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList; |
| 45 | import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata; |
| 46 | import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; |
| 47 | import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; |
| 48 | |
| 49 | import com.google.common.base.Function; |
| 50 | import com.google.common.base.Supplier; |
| 51 | import com.google.common.util.concurrent.ListenableFuture; |
| 52 | |
| 53 | /** |
| 54 | * |
| 55 | * @author Adrian Cole |
| 56 | */ |
| 57 | @Singleton |
| 58 | public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore { |
| 59 | private final EnableCDNAndCache enableCDNAndCache; |
| 60 | |
| 61 | @Inject |
| 62 | protected CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, |
| 63 | @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, |
| 64 | @Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async, |
| 65 | ContainerToResourceMetadata container2ResourceMd, |
| 66 | BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, |
| 67 | ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, |
| 68 | ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, |
| 69 | Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) { |
| 70 | super(context, blobUtils, service, defaultLocation, locations, sync, async, container2ResourceMd, |
| 71 | container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, |
| 72 | blob2ObjectGetOptions, fetchBlobMetadataProvider); |
| 73 | this.enableCDNAndCache = enableCDNAndCache; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public ListenableFuture<Boolean> createContainerInLocation(Location location, final String container, |
| 78 | CreateContainerOptions options) { |
| 79 | |
| 80 | ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container); |
| 81 | if (options.isPublicRead()) |
| 82 | return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() { |
| 83 | |
| 84 | @Override |
| 85 | public Boolean apply(Boolean input) { |
| 86 | if (Boolean.TRUE.equals(input)) { |
| 87 | return enableCDNAndCache.apply(container) != null; |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | }, service); |
| 93 | return returnVal; |
| 94 | } |
| 95 | } |