| 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.azureblob.blobstore.config; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | import java.util.concurrent.TimeUnit; |
| 23 | |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.azureblob.AzureBlobAsyncClient; |
| 27 | import org.jclouds.azureblob.AzureBlobClient; |
| 28 | import org.jclouds.azureblob.blobstore.AzureAsyncBlobStore; |
| 29 | import org.jclouds.azureblob.blobstore.AzureBlobRequestSigner; |
| 30 | import org.jclouds.azureblob.blobstore.AzureBlobStore; |
| 31 | import org.jclouds.azureblob.blobstore.strategy.FindMD5InBlobProperties; |
| 32 | import org.jclouds.azureblob.domain.PublicAccess; |
| 33 | import org.jclouds.blobstore.AsyncBlobStore; |
| 34 | import org.jclouds.blobstore.BlobRequestSigner; |
| 35 | import org.jclouds.blobstore.BlobStore; |
| 36 | import org.jclouds.blobstore.BlobStoreContext; |
| 37 | import org.jclouds.blobstore.attr.ConsistencyModel; |
| 38 | import org.jclouds.blobstore.config.BlobStoreMapModule; |
| 39 | import org.jclouds.blobstore.internal.BlobStoreContextImpl; |
| 40 | import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; |
| 41 | import org.jclouds.location.config.JustProviderLocationModule; |
| 42 | |
| 43 | import com.google.common.base.Function; |
| 44 | import com.google.common.collect.MapMaker; |
| 45 | import com.google.inject.AbstractModule; |
| 46 | import com.google.inject.Provides; |
| 47 | import com.google.inject.Scopes; |
| 48 | import com.google.inject.TypeLiteral; |
| 49 | |
| 50 | /** |
| 51 | * Configures the {@link AzureBlobStoreContext}; requires {@link AzureAsyncBlobStore} bound. |
| 52 | * |
| 53 | * @author Adrian Cole |
| 54 | */ |
| 55 | public class AzureBlobStoreContextModule extends AbstractModule { |
| 56 | |
| 57 | @Override |
| 58 | protected void configure() { |
| 59 | install(new BlobStoreMapModule()); |
| 60 | install(new JustProviderLocationModule()); |
| 61 | bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT); |
| 62 | bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON); |
| 63 | bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON); |
| 64 | bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AzureBlobClient, AzureBlobAsyncClient>>() { |
| 65 | }).in(Scopes.SINGLETON); |
| 66 | bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class); |
| 67 | bind(BlobRequestSigner.class).to(AzureBlobRequestSigner.class); |
| 68 | } |
| 69 | |
| 70 | @Provides |
| 71 | @Singleton |
| 72 | protected Map<String, PublicAccess> containerAcls(final AzureBlobClient client) { |
| 73 | return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap( |
| 74 | new Function<String, PublicAccess>() { |
| 75 | public PublicAccess apply(String container) { |
| 76 | return client.getPublicAccessForContainer(container); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return "getPublicAccessForContainer()"; |
| 82 | } |
| 83 | }); |
| 84 | } |
| 85 | } |