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.rest.internal; |
20 | |
21 | import java.util.concurrent.ExecutorService; |
22 | |
23 | import javax.inject.Inject; |
24 | import javax.inject.Named; |
25 | |
26 | import org.jclouds.Constants; |
27 | import org.jclouds.crypto.Crypto; |
28 | import org.jclouds.date.DateService; |
29 | import org.jclouds.json.Json; |
30 | import org.jclouds.logging.Logger.LoggerFactory; |
31 | import org.jclouds.rest.HttpAsyncClient; |
32 | import org.jclouds.rest.HttpClient; |
33 | import org.jclouds.rest.Utils; |
34 | |
35 | import com.google.inject.Singleton; |
36 | |
37 | /** |
38 | * @author Adrian Cole |
39 | */ |
40 | @Singleton |
41 | public class UtilsImpl implements Utils { |
42 | |
43 | private final Json json; |
44 | private final HttpClient simpleClient; |
45 | private final HttpAsyncClient simpleAsyncClient; |
46 | private final Crypto encryption; |
47 | private final DateService date; |
48 | private final ExecutorService userExecutor; |
49 | private final ExecutorService ioExecutor; |
50 | private final LoggerFactory loggerFactory; |
51 | |
52 | @Inject |
53 | protected UtilsImpl(Json json, HttpClient simpleClient, HttpAsyncClient simpleAsyncClient, |
54 | Crypto encryption, DateService date, |
55 | @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads, |
56 | @Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, LoggerFactory loggerFactory) { |
57 | this.json = json; |
58 | this.simpleClient = simpleClient; |
59 | this.simpleAsyncClient = simpleAsyncClient; |
60 | this.encryption = encryption; |
61 | this.date = date; |
62 | this.userExecutor = userThreads; |
63 | this.ioExecutor = ioThreads; |
64 | this.loggerFactory = loggerFactory; |
65 | } |
66 | |
67 | @Override |
68 | public HttpAsyncClient asyncHttp() { |
69 | return simpleAsyncClient; |
70 | } |
71 | |
72 | @Override |
73 | public DateService date() { |
74 | return date; |
75 | } |
76 | |
77 | @Override |
78 | public Crypto crypto() { |
79 | return encryption; |
80 | } |
81 | |
82 | @Override |
83 | public DateService getDateService() { |
84 | return date; |
85 | } |
86 | |
87 | @Override |
88 | public Crypto getCrypto() { |
89 | return encryption; |
90 | } |
91 | |
92 | @Override |
93 | public HttpAsyncClient getHttpAsyncClient() { |
94 | return simpleAsyncClient; |
95 | } |
96 | |
97 | @Override |
98 | public HttpClient getHttpClient() { |
99 | return simpleClient; |
100 | } |
101 | |
102 | @Override |
103 | public HttpClient http() { |
104 | return simpleClient; |
105 | } |
106 | |
107 | @Override |
108 | public ExecutorService getIoExecutor() { |
109 | return ioExecutor; |
110 | } |
111 | |
112 | @Override |
113 | public ExecutorService getUserExecutor() { |
114 | return userExecutor; |
115 | } |
116 | |
117 | @Override |
118 | public ExecutorService ioExecutor() { |
119 | return ioExecutor; |
120 | } |
121 | |
122 | @Override |
123 | public ExecutorService userExecutor() { |
124 | return userExecutor; |
125 | } |
126 | |
127 | @Override |
128 | public LoggerFactory getLoggerFactory() { |
129 | return loggerFactory; |
130 | } |
131 | |
132 | @Override |
133 | public LoggerFactory loggerFactory() { |
134 | return loggerFactory; |
135 | } |
136 | |
137 | @Override |
138 | public Json getJson() { |
139 | return json; |
140 | } |
141 | |
142 | @Override |
143 | public Json json() { |
144 | return json; |
145 | } |
146 | |
147 | } |