3
3
import io .github .doocs .im .util .VersionInfoUtil ;
4
4
import okhttp3 .ConnectionPool ;
5
5
6
+ import java .util .Collections ;
7
+ import java .util .HashSet ;
6
8
import java .util .Objects ;
9
+ import java .util .Set ;
7
10
8
11
/**
9
12
* 客户端配置类
@@ -36,6 +39,17 @@ public class ClientConfiguration {
36
39
* 默认业务错误码重试开关关闭
37
40
*/
38
41
public static final boolean DEFAULT_ENABLE_BUSINESS_RETRY = false ;
42
+
43
+ /**
44
+ * 默认重试错误码
45
+ */
46
+ public static final Set <Integer > DEFAULT_BUSINESS_RETRY_CODES =
47
+ Collections .unmodifiableSet (new HashSet <Integer >() {{
48
+ add (10002 );
49
+ add (20004 );
50
+ add (20005 );
51
+ }});
52
+
39
53
/**
40
54
* 默认超时时间(毫秒)
41
55
*/
@@ -63,14 +77,15 @@ public class ClientConfiguration {
63
77
private long expireTime = DEFAULT_EXPIRE_TIME ;
64
78
private boolean autoRenewSig = DEFAULT_RENEW_SIG ;
65
79
private boolean enableBusinessRetry = DEFAULT_ENABLE_BUSINESS_RETRY ;
80
+ private Set <Integer > businessRetryCodes = DEFAULT_BUSINESS_RETRY_CODES ;
66
81
private String userAgent = DEFAULT_USER_AGENT ;
67
82
private ConnectionPool connectionPool = DEFAULT_CONNECTION_POOL ;
68
83
69
84
public ClientConfiguration () {
70
85
}
71
86
72
87
public ClientConfiguration (int maxRetries , long retryIntervalMs , long connectTimeout , long readTimeout , long writeTimeout ,
73
- long callTimeout , long expireTime , boolean autoRenewSig , boolean enableBusinessRetry ,
88
+ long callTimeout , long expireTime , boolean autoRenewSig , boolean enableBusinessRetry , Set < Integer > businessRetryCodes ,
74
89
String userAgent , ConnectionPool connectionPool ) {
75
90
if (connectionPool == null ) {
76
91
connectionPool = DEFAULT_CONNECTION_POOL ;
@@ -84,6 +99,7 @@ public ClientConfiguration(int maxRetries, long retryIntervalMs, long connectTim
84
99
this .expireTime = expireTime ;
85
100
this .autoRenewSig = autoRenewSig ;
86
101
this .enableBusinessRetry = enableBusinessRetry ;
102
+ this .businessRetryCodes = businessRetryCodes ;
87
103
this .userAgent = userAgent ;
88
104
this .connectionPool = connectionPool ;
89
105
}
@@ -98,6 +114,7 @@ private ClientConfiguration(Builder builder) {
98
114
this .expireTime = builder .expireTime ;
99
115
this .autoRenewSig = builder .autoRenewSig ;
100
116
this .enableBusinessRetry = builder .enableBusinessRetry ;
117
+ this .businessRetryCodes = builder .businessRetryCodes ;
101
118
this .userAgent = builder .userAgent ;
102
119
this .connectionPool = builder .connectionPool ;
103
120
}
@@ -178,6 +195,14 @@ public void setEnableBusinessRetry(boolean enableBusinessRetry) {
178
195
this .enableBusinessRetry = enableBusinessRetry ;
179
196
}
180
197
198
+ public Set <Integer > getBusinessRetryCodes () {
199
+ return businessRetryCodes ;
200
+ }
201
+
202
+ public void setBusinessRetryCodes (Set <Integer > businessRetryCodes ) {
203
+ this .businessRetryCodes = businessRetryCodes ;
204
+ }
205
+
181
206
public String getUserAgent () {
182
207
return userAgent ;
183
208
}
@@ -234,6 +259,9 @@ public boolean equals(Object o) {
234
259
if (enableBusinessRetry != that .enableBusinessRetry ) {
235
260
return false ;
236
261
}
262
+ if (businessRetryCodes != that .businessRetryCodes ) {
263
+ return false ;
264
+ }
237
265
if (!userAgent .equals (that .userAgent )) {
238
266
return false ;
239
267
}
@@ -242,7 +270,7 @@ public boolean equals(Object o) {
242
270
243
271
@ Override
244
272
public int hashCode () {
245
- return Objects .hash (maxRetries , retryIntervalMs , connectTimeout , readTimeout , writeTimeout , callTimeout , expireTime , autoRenewSig , enableBusinessRetry , userAgent , connectionPool );
273
+ return Objects .hash (maxRetries , retryIntervalMs , connectTimeout , readTimeout , writeTimeout , callTimeout , expireTime , autoRenewSig , enableBusinessRetry , businessRetryCodes , userAgent , connectionPool );
246
274
}
247
275
248
276
public static final class Builder {
@@ -255,6 +283,7 @@ public static final class Builder {
255
283
private long expireTime = DEFAULT_EXPIRE_TIME ;
256
284
private boolean autoRenewSig = DEFAULT_RENEW_SIG ;
257
285
private boolean enableBusinessRetry = DEFAULT_ENABLE_BUSINESS_RETRY ;
286
+ private Set <Integer > businessRetryCodes = DEFAULT_BUSINESS_RETRY_CODES ;
258
287
private String userAgent = DEFAULT_USER_AGENT ;
259
288
private ConnectionPool connectionPool = DEFAULT_CONNECTION_POOL ;
260
289
@@ -310,6 +339,11 @@ public Builder enableBusinessRetry(boolean enableBusinessRetry) {
310
339
return this ;
311
340
}
312
341
342
+ public Builder businessRetryCodes (Set <Integer > businessRetryCodes ) {
343
+ this .businessRetryCodes = businessRetryCodes ;
344
+ return this ;
345
+ }
346
+
313
347
public Builder userAgent (String userAgent ) {
314
348
this .userAgent = userAgent ;
315
349
return this ;
0 commit comments