| 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.atmos.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.atmos.AtmosAsyncClient; |
| 27 | import org.jclouds.atmos.AtmosClient; |
| 28 | import org.jclouds.atmos.blobstore.AtmosAsyncBlobStore; |
| 29 | import org.jclouds.atmos.blobstore.AtmosBlobRequestSigner; |
| 30 | import org.jclouds.atmos.blobstore.AtmosBlobStore; |
| 31 | import org.jclouds.atmos.blobstore.strategy.FindMD5InUserMetadata; |
| 32 | import org.jclouds.blobstore.AsyncBlobStore; |
| 33 | import org.jclouds.blobstore.BlobRequestSigner; |
| 34 | import org.jclouds.blobstore.BlobStore; |
| 35 | import org.jclouds.blobstore.BlobStoreContext; |
| 36 | import org.jclouds.blobstore.attr.ConsistencyModel; |
| 37 | import org.jclouds.blobstore.config.BlobStoreMapModule; |
| 38 | import org.jclouds.blobstore.internal.BlobStoreContextImpl; |
| 39 | import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; |
| 40 | import org.jclouds.location.config.JustProviderLocationModule; |
| 41 | |
| 42 | import com.google.common.base.Function; |
| 43 | import com.google.common.collect.MapMaker; |
| 44 | import com.google.inject.AbstractModule; |
| 45 | import com.google.inject.Provides; |
| 46 | import com.google.inject.Scopes; |
| 47 | import com.google.inject.TypeLiteral; |
| 48 | |
| 49 | /** |
| 50 | * Configures the {@link AtmosBlobStoreContext}; requires {@link AtmosAsyncBlobStore} bound. |
| 51 | * |
| 52 | * @author Adrian Cole |
| 53 | */ |
| 54 | public class AtmosBlobStoreContextModule extends AbstractModule { |
| 55 | |
| 56 | @Override |
| 57 | protected void configure() { |
| 58 | install(new BlobStoreMapModule()); |
| 59 | bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL); |
| 60 | bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON); |
| 61 | bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON); |
| 62 | bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AtmosClient, AtmosAsyncClient>>() { |
| 63 | }).in(Scopes.SINGLETON); |
| 64 | bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class); |
| 65 | bind(BlobRequestSigner.class).to(AtmosBlobRequestSigner.class); |
| 66 | install(new JustProviderLocationModule()); |
| 67 | } |
| 68 | |
| 69 | @Provides |
| 70 | @Singleton |
| 71 | protected Map<String, Boolean> isPublic(final AtmosClient client) { |
| 72 | return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function<String, Boolean>() { |
| 73 | public Boolean apply(String directory) { |
| 74 | return client.isPublic(directory); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return "isPublic()"; |
| 80 | } |
| 81 | }); |
| 82 | } |
| 83 | } |