| 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.blobstore.config; |
| 20 | |
| 21 | import java.util.concurrent.ConcurrentHashMap; |
| 22 | import java.util.concurrent.ConcurrentMap; |
| 23 | |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.blobstore.AsyncBlobStore; |
| 27 | import org.jclouds.blobstore.BlobRequestSigner; |
| 28 | import org.jclouds.blobstore.BlobStore; |
| 29 | import org.jclouds.blobstore.BlobStoreContext; |
| 30 | import org.jclouds.blobstore.TransientAsyncBlobStore; |
| 31 | import org.jclouds.blobstore.TransientBlobRequestSigner; |
| 32 | import org.jclouds.blobstore.attr.ConsistencyModel; |
| 33 | import org.jclouds.blobstore.domain.Blob; |
| 34 | import org.jclouds.blobstore.internal.BlobStoreContextImpl; |
| 35 | import org.jclouds.domain.Location; |
| 36 | import org.jclouds.location.config.JustProviderLocationModule; |
| 37 | |
| 38 | import com.google.inject.AbstractModule; |
| 39 | import com.google.inject.Provides; |
| 40 | import com.google.inject.Scopes; |
| 41 | import com.google.inject.TypeLiteral; |
| 42 | |
| 43 | /** |
| 44 | * Configures the {@link TransientBlobStoreContext}; requires {@link TransientAsyncBlobStore} bound. |
| 45 | * |
| 46 | * @author Adrian Cole |
| 47 | */ |
| 48 | public class TransientBlobStoreContextModule extends AbstractModule { |
| 49 | |
| 50 | // must be singleton for all threads and all objects or tests may fail; |
| 51 | static final ConcurrentHashMap<String, ConcurrentMap<String, Blob>> map = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>(); |
| 52 | static final ConcurrentHashMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>(); |
| 53 | |
| 54 | @Override |
| 55 | protected void configure() { |
| 56 | bind(new TypeLiteral<BlobStoreContext>() { |
| 57 | }).to(new TypeLiteral<BlobStoreContextImpl<TransientBlobStore, AsyncBlobStore>>() { |
| 58 | }).in(Scopes.SINGLETON); |
| 59 | bind(new TypeLiteral<ConcurrentMap<String, ConcurrentMap<String, Blob>>>() { |
| 60 | }).toInstance(map); |
| 61 | bind(new TypeLiteral<ConcurrentMap<String, Location>>() { |
| 62 | }).toInstance(containerToLocation); |
| 63 | install(new BlobStoreObjectModule()); |
| 64 | install(new BlobStoreMapModule()); |
| 65 | install(new JustProviderLocationModule()); |
| 66 | bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT); |
| 67 | bind(BlobRequestSigner.class).to(TransientBlobRequestSigner.class); |
| 68 | } |
| 69 | |
| 70 | @Provides |
| 71 | @Singleton |
| 72 | BlobStore provide(TransientBlobStore in) { |
| 73 | return in; |
| 74 | } |
| 75 | } |