| 1 | /** | 
| 2 |  * | 
| 3 |  * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> | 
| 4 |  * | 
| 5 |  * ==================================================================== | 
| 6 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
| 7 |  * you may not use this file except in compliance with the License. | 
| 8 |  * 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, software | 
| 13 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
| 14 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 15 |  * See the License for the specific language governing permissions and | 
| 16 |  * limitations under the License. | 
| 17 |  * ==================================================================== | 
| 18 |  */ | 
| 19 | package org.jclouds.compute.internal; | 
| 20 |   | 
| 21 | import static com.google.common.base.Preconditions.checkNotNull; | 
| 22 |   | 
| 23 | import java.util.Map; | 
| 24 |   | 
| 25 | import javax.inject.Inject; | 
| 26 | import javax.inject.Singleton; | 
| 27 |   | 
| 28 | import org.jclouds.compute.ComputeService; | 
| 29 | import org.jclouds.compute.ComputeServiceContext; | 
| 30 | import org.jclouds.compute.Utils; | 
| 31 | import org.jclouds.domain.Credentials; | 
| 32 | import org.jclouds.rest.RestContext; | 
| 33 |   | 
| 34 | /** | 
| 35 |  * @author Adrian Cole | 
| 36 |  */ | 
| 37 | @Singleton | 
| 38 | public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext { | 
| 39 |    private final ComputeService computeService; | 
| 40 |    private final RestContext<S, A> providerSpecificContext; | 
| 41 |    private final Utils utils; | 
| 42 |    private final Map<String, Credentials> credentialStore; | 
| 43 |   | 
| 44 |    @SuppressWarnings( { "unchecked" }) | 
| 45 |    @Inject | 
| 46 |    public ComputeServiceContextImpl(ComputeService computeService, Map<String, Credentials> credentialStore, | 
| 47 |             Utils utils, @SuppressWarnings("rawtypes") RestContext providerSpecificContext) { | 
| 48 |       this.credentialStore = credentialStore; | 
| 49 |       this.utils = utils; | 
| 50 |       this.providerSpecificContext = providerSpecificContext; | 
| 51 |       this.computeService = checkNotNull(computeService, "computeService"); | 
| 52 |    } | 
| 53 |   | 
| 54 |    public ComputeService getComputeService() { | 
| 55 |       return computeService; | 
| 56 |    } | 
| 57 |   | 
| 58 |    @SuppressWarnings( { "unchecked", "hiding" }) | 
| 59 |    @Override | 
| 60 |    public <S, A> RestContext<S, A> getProviderSpecificContext() { | 
| 61 |       return (RestContext<S, A>) providerSpecificContext; | 
| 62 |    } | 
| 63 |   | 
| 64 |    @Override | 
| 65 |    public void close() { | 
| 66 |       providerSpecificContext.close(); | 
| 67 |    } | 
| 68 |   | 
| 69 |    @Override | 
| 70 |    public Utils getUtils() { | 
| 71 |       return utils(); | 
| 72 |    } | 
| 73 |   | 
| 74 |    @Override | 
| 75 |    public Utils utils() { | 
| 76 |       return utils; | 
| 77 |    } | 
| 78 |   | 
| 79 |    public int hashCode() { | 
| 80 |       return providerSpecificContext.hashCode(); | 
| 81 |    } | 
| 82 |   | 
| 83 |    @Override | 
| 84 |    public String toString() { | 
| 85 |       return providerSpecificContext.toString(); | 
| 86 |    } | 
| 87 |   | 
| 88 |    @Override | 
| 89 |    public boolean equals(Object obj) { | 
| 90 |       return providerSpecificContext.equals(obj); | 
| 91 |    } | 
| 92 |   | 
| 93 |    @Override | 
| 94 |    public Map<String, Credentials> getCredentialStore() { | 
| 95 |       return credentialStore; | 
| 96 |    } | 
| 97 |   | 
| 98 |    @Override | 
| 99 |    public Map<String, Credentials> credentialStore() { | 
| 100 |       return credentialStore; | 
| 101 |    } | 
| 102 | } |