| 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.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.blobstore.AsyncBlobStore; |
| 27 | import org.jclouds.blobstore.BlobMap; |
| 28 | import org.jclouds.blobstore.BlobRequestSigner; |
| 29 | import org.jclouds.blobstore.BlobStore; |
| 30 | import org.jclouds.blobstore.BlobStoreContext; |
| 31 | import org.jclouds.blobstore.InputStreamMap; |
| 32 | import org.jclouds.blobstore.attr.ConsistencyModel; |
| 33 | import org.jclouds.blobstore.options.ListContainerOptions; |
| 34 | import org.jclouds.rest.RestContext; |
| 35 | import org.jclouds.rest.Utils; |
| 36 | |
| 37 | /** |
| 38 | * @author Adrian Cole |
| 39 | */ |
| 40 | @Singleton |
| 41 | public class BlobStoreContextImpl<S, A> implements BlobStoreContext { |
| 42 | private final BlobMap.Factory blobMapFactory; |
| 43 | private final InputStreamMap.Factory inputStreamMapFactory; |
| 44 | private final AsyncBlobStore ablobStore; |
| 45 | private final BlobStore blobStore; |
| 46 | private final RestContext<S, A> providerSpecificContext; |
| 47 | private final ConsistencyModel consistencyModel; |
| 48 | private final Utils utils; |
| 49 | private final BlobRequestSigner blobRequestSigner; |
| 50 | |
| 51 | @SuppressWarnings("unchecked") |
| 52 | @Inject |
| 53 | public BlobStoreContextImpl(BlobMap.Factory blobMapFactory, Utils utils, ConsistencyModel consistencyModel, |
| 54 | InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore, BlobStore blobStore, |
| 55 | @SuppressWarnings("rawtypes") RestContext providerSpecificContext, BlobRequestSigner blobRequestSigner) { |
| 56 | // unravel guice and avoid passing in a million type args by not injecting generic types for |
| 57 | // rest context |
| 58 | this.providerSpecificContext = checkNotNull(providerSpecificContext, "providerSpecificContext"); |
| 59 | this.consistencyModel = checkNotNull(consistencyModel, "consistencyModel"); |
| 60 | this.blobMapFactory = checkNotNull(blobMapFactory, "blobMapFactory"); |
| 61 | this.inputStreamMapFactory = checkNotNull(inputStreamMapFactory, "inputStreamMapFactory"); |
| 62 | this.ablobStore = checkNotNull(ablobStore, "ablobStore"); |
| 63 | this.blobStore = checkNotNull(blobStore, "blobStore"); |
| 64 | this.utils = checkNotNull(utils, "utils"); |
| 65 | this.blobRequestSigner = checkNotNull(blobRequestSigner, "blobRequestSigner"); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public ConsistencyModel getConsistencyModel() { |
| 70 | return consistencyModel; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public BlobMap createBlobMap(String container, ListContainerOptions options) { |
| 75 | return blobMapFactory.create(container, options); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public BlobMap createBlobMap(String container) { |
| 80 | return blobMapFactory.create(container, ListContainerOptions.NONE); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public InputStreamMap createInputStreamMap(String container, ListContainerOptions options) { |
| 85 | return inputStreamMapFactory.create(container, options); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public InputStreamMap createInputStreamMap(String container) { |
| 90 | return inputStreamMapFactory.create(container, ListContainerOptions.NONE); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public BlobStore getBlobStore() { |
| 95 | return blobStore; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public AsyncBlobStore getAsyncBlobStore() { |
| 100 | return ablobStore; |
| 101 | } |
| 102 | |
| 103 | @SuppressWarnings("unchecked") |
| 104 | @Override |
| 105 | public RestContext<S, A> getProviderSpecificContext() { |
| 106 | return (RestContext<S, A>) providerSpecificContext; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void close() { |
| 111 | providerSpecificContext.close(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public Utils getUtils() { |
| 116 | return utils(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Utils utils() { |
| 121 | return utils; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public int hashCode() { |
| 126 | return providerSpecificContext.hashCode(); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public String toString() { |
| 131 | return providerSpecificContext.toString(); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean equals(Object obj) { |
| 136 | return providerSpecificContext.equals(obj); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public BlobRequestSigner getSigner() { |
| 141 | return blobRequestSigner; |
| 142 | } |
| 143 | } |