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.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 | } |