| 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 | |
| 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Provider; |
| 25 | import javax.inject.Singleton; |
| 26 | |
| 27 | import org.jclouds.blobstore.BlobStoreContext; |
| 28 | import org.jclouds.blobstore.functions.BlobToHttpGetOptions; |
| 29 | import org.jclouds.blobstore.options.CreateContainerOptions; |
| 30 | import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; |
| 31 | import org.jclouds.blobstore.util.BlobUtils; |
| 32 | import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache; |
| 33 | import org.jclouds.collect.Memoized; |
| 34 | import org.jclouds.domain.Location; |
| 35 | import org.jclouds.openstack.swift.CommonSwiftClient; |
| 36 | import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; |
| 37 | import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; |
| 38 | import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; |
| 39 | import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList; |
| 40 | import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata; |
| 41 | import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; |
| 42 | import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; |
| 43 | |
| 44 | import com.google.common.base.Supplier; |
| 45 | |
| 46 | /** |
| 47 | * |
| 48 | * @author Adrian Cole |
| 49 | */ |
| 50 | @Singleton |
| 51 | public class CloudFilesBlobStore extends SwiftBlobStore { |
| 52 | |
| 53 | private EnableCDNAndCache enableCDNAndCache; |
| 54 | |
| 55 | @Inject |
| 56 | protected CloudFilesBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation, |
| 57 | @Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync, |
| 58 | ContainerToResourceMetadata container2ResourceMd, |
| 59 | BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, |
| 60 | ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, |
| 61 | ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, |
| 62 | Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) { |
| 63 | super(context, blobUtils, defaultLocation, locations, sync, container2ResourceMd, container2ContainerListOptions, |
| 64 | container2ResourceList, object2Blob, blob2Object, object2BlobMd, blob2ObjectGetOptions, |
| 65 | fetchBlobMetadataProvider); |
| 66 | this.enableCDNAndCache = enableCDNAndCache; |
| 67 | |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { |
| 72 | try { |
| 73 | return createContainerInLocation(location, container); |
| 74 | } finally { |
| 75 | if (options.isPublicRead()) |
| 76 | enableCDNAndCache.apply(container); |
| 77 | } |
| 78 | } |
| 79 | } |