| 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.aws.s3.blobstore; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | import java.util.Set; |
| 23 | import java.util.concurrent.ExecutorService; |
| 24 | |
| 25 | import javax.inject.Inject; |
| 26 | import javax.inject.Named; |
| 27 | import javax.inject.Provider; |
| 28 | |
| 29 | import org.jclouds.Constants; |
| 30 | import org.jclouds.aws.s3.AWSS3AsyncClient; |
| 31 | import org.jclouds.aws.s3.AWSS3Client; |
| 32 | import org.jclouds.aws.s3.blobstore.strategy.AsyncMultipartUploadStrategy; |
| 33 | import org.jclouds.blobstore.BlobStoreContext; |
| 34 | import org.jclouds.blobstore.domain.Blob; |
| 35 | import org.jclouds.blobstore.functions.BlobToHttpGetOptions; |
| 36 | import org.jclouds.blobstore.options.PutOptions; |
| 37 | import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; |
| 38 | import org.jclouds.blobstore.util.BlobUtils; |
| 39 | import org.jclouds.collect.Memoized; |
| 40 | import org.jclouds.domain.Location; |
| 41 | import org.jclouds.s3.blobstore.S3AsyncBlobStore; |
| 42 | import org.jclouds.s3.blobstore.functions.BlobToObject; |
| 43 | import org.jclouds.s3.blobstore.functions.BucketToResourceList; |
| 44 | import org.jclouds.s3.blobstore.functions.BucketToResourceMetadata; |
| 45 | import org.jclouds.s3.blobstore.functions.ContainerToBucketListOptions; |
| 46 | import org.jclouds.s3.blobstore.functions.ObjectToBlob; |
| 47 | import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata; |
| 48 | import org.jclouds.s3.domain.AccessControlList; |
| 49 | |
| 50 | import com.google.common.base.Supplier; |
| 51 | import com.google.common.util.concurrent.ListenableFuture; |
| 52 | |
| 53 | /** |
| 54 | * |
| 55 | * @author Tibor Kiss |
| 56 | */ |
| 57 | public class AWSS3AsyncBlobStore extends S3AsyncBlobStore { |
| 58 | |
| 59 | private final Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy; |
| 60 | |
| 61 | @Inject |
| 62 | public AWSS3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, |
| 63 | @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, |
| 64 | @Memoized Supplier<Set<? extends Location>> locations, AWSS3AsyncClient async, AWSS3Client sync, |
| 65 | BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, |
| 66 | BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, |
| 67 | BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, |
| 68 | Provider<FetchBlobMetadata> fetchBlobMetadataProvider, Map<String, AccessControlList> bucketAcls, |
| 69 | Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { |
| 70 | super(context, blobUtils, service, defaultLocation, locations, async, sync, bucket2ResourceMd, |
| 71 | container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object, |
| 72 | object2BlobMd, fetchBlobMetadataProvider, bucketAcls); |
| 73 | this.multipartUploadStrategy = multipartUploadStrategy; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public ListenableFuture<String> putBlob(String container, Blob blob, PutOptions options) { |
| 78 | // need to use a provider if the strategy object is stateful |
| 79 | return multipartUploadStrategy.get().execute(container, blob); |
| 80 | } |
| 81 | |
| 82 | } |