forked from qiniu/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.java
More file actions
386 lines (334 loc) · 10.3 KB
/
Configuration.java
File metadata and controls
386 lines (334 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package com.qiniu.storage;
import com.qiniu.common.Constants;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Dns;
import com.qiniu.http.ProxyConfiguration;
import java.util.concurrent.ExecutorService;
/**
* 该类封装了SDK相关配置参数
*/
public final class Configuration implements Cloneable {
/**
* 公有云 RS 域名,内部使用,不保证兼容性变更
*/
public static String defaultRsHost = "rs.qiniu.com";
/**
* 公有云 API 域名,内部使用,不保证兼容性变更
*/
public static String defaultApiHost = "api.qiniu.com";
/**
* 公有云 Uc 域名,内部使用,不保证兼容性变更
*/
public static String defaultUcHost = "uc.qiniuapi.com";
static final String ucBackUpHost0 = "kodo-config.qiniuapi.com";
static final String ucBackUpHost1 = "uc.qbox.me";
static final String[] defaultUcHosts = new String[]{defaultUcHost, ucBackUpHost0, ucBackUpHost1};
/**
* 使用的Region
*/
public Region region;
/**
* 使用的Zone
*/
@Deprecated
public Zone zone;
/**
* 空间相关上传管理操作是否使用 https , 默认 是
*/
public boolean useHttpsDomains = true;
/**
* 空间相关上传管理操作是否使用代理加速上传,默认 是
*/
public boolean accUpHostFirst = true;
/**
* 使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是
* upload.qiniup.com, upload-z1.qiniup.com, upload-z2.qiniup.com,
* upload-na0.qiniup.com, upload-as0.qiniup.com
*/
public boolean useDefaultUpHostIfNone = true;
/**
* 使用分片 V2 上传时的分片大小
* 范围为:1M ~ 1GB,
* 注:每个文件最大分片数量为 10000
*/
public int resumableUploadAPIV2BlockSize = Constants.BLOCK_SIZE;
/**
* 分片上传每个文件传时的最大并发任务数,并发数量会影响内存使用,请合理配置
* 当 resumableUploadMaxConcurrentTaskCount 小于或等于 1 时,使用同步上传,resumableUploadConcurrentTaskExecutorService 不被使用
* 当 resumableUploadMaxConcurrentTaskCount 大于 1 时,使用并发上传
* <p>
* 分片上传,每个上传操作会占用 blockSize 大小内存,blockSize 也即分片大小,
* 在分片 v1 中 blockSize 为 4M;
* 分片 v2 可自定义,定义方式为:Configuration.resumableUploadAPIV2BlockSize,范围为:1M ~ 1GB,分片 v2 需要注意每个文件最大分片数量为 10000;
* 当采用并发分片时,占用内存大小和当时启用并发任务数量有关,即:blockSize * 并发数量,
* 并发任务数量配置方式:Configuration.resumableUploadMaxConcurrentTaskCount
*/
public int resumableUploadMaxConcurrentTaskCount = 1;
/**
* 分片上传并发任务的 ExecutorService
* 当 resumableUploadMaxConcurrentTaskCount 小于或等于 1,此设置无效;
* 当 resumableUploadMaxConcurrentTaskCount 大于 1 且 resumableUploadConcurrentTaskExecutorService 为空,则会创建 Executors.newFixedThreadPool(maxConcurrentTaskCount)
* 当 resumableUploadMaxConcurrentTaskCount 大于 1 且 resumableUploadConcurrentTaskExecutorService 不为空,则直接使用 resumableUploadConcurrentTaskExecutorService
*/
public ExecutorService resumableUploadConcurrentTaskExecutorService = null;
/**
* 分片上传的版本
*/
public ResumableUploadAPIVersion resumableUploadAPIVersion = ResumableUploadAPIVersion.V1;
/**
* 如果文件大小大于此值则使用断点上传, 否则使用Form上传
*/
public int putThreshold = Constants.BLOCK_SIZE;
/**
* 连接超时时间 单位秒(默认10s)
*/
public int connectTimeout = Constants.CONNECT_TIMEOUT;
/**
* 写超时时间 单位秒(默认 0 , 不超时)
*/
public int writeTimeout = Constants.WRITE_TIMEOUT;
/**
* 回复超时时间 单位秒(默认30s)
*/
public int readTimeout = Constants.READ_TIMEOUT;
/**
* 底层HTTP库所有的并发执行的请求数量
*/
public int dispatcherMaxRequests = Constants.DISPATCHER_MAX_REQUESTS;
/**
* 底层HTTP库对每个独立的Host进行并发请求的数量
*/
public int dispatcherMaxRequestsPerHost = Constants.DISPATCHER_MAX_REQUESTS_PER_HOST;
/**
* 底层HTTP库中复用连接对象的最大空闲数量
*/
public int connectionPoolMaxIdleCount = Constants.CONNECTION_POOL_MAX_IDLE_COUNT;
/**
* 底层HTTP库中复用连接对象的回收周期(单位分钟)
*/
public int connectionPoolMaxIdleMinutes = Constants.CONNECTION_POOL_MAX_IDLE_MINUTES;
/**
* 上传过程中,如果上传失败,单个域名最大重试次数
*/
public int retryMax = 1;
/**
* 重试时间间隔,单位:毫秒
**/
public int retryInterval = 300;
/**
* 域名冻结时间,单位:毫秒
* <p>
* 当一个请求失败,会根据条件判断是否需要冻结请求的域名,冻结后在指定的冻结时间内不会使用此域名进行重试
**/
public int hostFreezeDuration = 600 * 1000;
/**
* 外部dns
*/
public Dns dns;
/*
* 解析域名时,优先使用host配置,主要针对内部局域网配置
*/
@Deprecated
public boolean useDnsHostFirst;
/**
* 代理对象
*/
public ProxyConfiguration proxy;
private ConfigHelper configHelper;
/**
* 构造函数:
* 使用 {@link Configuration#create()} 替换
*/
@Deprecated
public Configuration() {
configHelper = new ConfigHelper(this);
}
/**
* 构造函数:
* 使用 {@link Configuration#create(Region)} 替换
*
* @param region
*/
@Deprecated
public Configuration(Region region) {
if (region instanceof RegionGroup) {
this.region = (Region) region.clone();
} else {
this.region = region;
}
configHelper = new ConfigHelper(this);
}
/**
* 构造函数:
* 使用 {@link Configuration#create(Region)} 替换
*
* @param zone Zone
*/
@Deprecated
public Configuration(Zone zone) {
this.zone = zone;
configHelper = new ConfigHelper(this);
}
/**
* 默认配置
*
* @return Configuration
*/
public static Configuration create() {
Configuration configuration = new Configuration();
configuration.resumableUploadAPIVersion = ResumableUploadAPIVersion.V2;
return configuration;
}
/**
* 构建配置
*
* @param region Region
* @return Configuration
*/
public static Configuration create(Region region) {
Configuration configuration = new Configuration(region);
configuration.resumableUploadAPIVersion = ResumableUploadAPIVersion.V2;
return configuration;
}
/**
* 克隆
*
* @return Configuration
*/
public Configuration clone() {
try {
Configuration configuration = (Configuration) super.clone();
if (region != null) {
configuration.region = (Region) region.clone();
}
return configuration;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
/***
* 获取上传域名
*
* @param upToken 上传 token
* @return 上传域名
* @throws QiniuException 获取域名失败异常
*/
@Deprecated
public String upHost(String upToken) throws QiniuException {
return configHelper.upHost(upToken);
}
/**
* 获取备用上传域名
*
* @param upToken 上传 token
* @return 上传域名
* @throws QiniuException 获取域名失败异常
*/
@Deprecated
public String upHostBackup(String upToken) throws QiniuException {
return configHelper.tryChangeUpHost(upToken, null);
}
/**
* 获取 io 域名
*
* @param ak 七牛 AK
* @param bucket 存储空间名称
* @return io 域名
*/
@Deprecated
public String ioHost(String ak, String bucket) {
try {
return configHelper.ioHost(ak, bucket);
} catch (QiniuException e) {
throw new RuntimeException(e);
}
}
/**
* 获取 api 域名
*
* @param ak 七牛 AK
* @param bucket 存储空间名称
* @return api 域名
*/
@Deprecated
public String apiHost(String ak, String bucket) {
try {
return configHelper.apiHost(ak, bucket);
} catch (QiniuException e) {
throw new RuntimeException(e);
}
}
/**
* 获取 rs 域名
*
* @param ak 七牛 AK
* @param bucket 存储空间名称
* @return rs 域名
*/
@Deprecated
public String rsHost(String ak, String bucket) {
try {
return configHelper.rsHost(ak, bucket);
} catch (QiniuException e) {
throw new RuntimeException(e);
}
}
/**
* 获取 rsf 域名
*
* @param ak 七牛 AK
* @param bucket 存储空间名称
* @return rsf 域名
*/
@Deprecated
public String rsfHost(String ak, String bucket) {
try {
return configHelper.rsfHost(ak, bucket);
} catch (QiniuException e) {
throw new RuntimeException(e);
}
}
/**
* 获取 rs 域名
*
* @return rs 域名
*/
@Deprecated
public String rsHost() {
return configHelper.rsHost();
}
/**
* 获取 api 域名
*
* @return api 域名
*/
@Deprecated
public String apiHost() {
return configHelper.apiHost();
}
/**
* 获取 uc 域名
*
* @return uc 域名
*/
@Deprecated
public String ucHost() {
return configHelper.ucHost();
}
/**
* 分片上传 API 版本
*/
public enum ResumableUploadAPIVersion {
/**
* 使用 V1 的分块上传API。
*/
V1,
/**
* 使用 V2 的分块上传API。
* 推荐使用 V2 的分片上传版本,更稳定,更高效。
*/
V2
}
}