2727import io .reactivex .BackpressureStrategy ;
2828import io .reactivex .Flowable ;
2929import io .reactivex .Single ;
30- import okhttp3 .Headers ;
31- import okhttp3 .ResponseBody ;
30+ import okhttp3 .*;
3231import org .apache .commons .lang .StringUtils ;
3332import retrofit2 .Call ;
3433import retrofit2 .HttpException ;
3534import retrofit2 .adapter .rxjava2 .RxJava2CallAdapterFactory ;
3635import retrofit2 .converter .jackson .JacksonConverterFactory ;
37- import okhttp3 .ConnectionPool ;
38- import okhttp3 .OkHttpClient ;
3936import retrofit2 .Retrofit ;
4037import retrofit2 .http .HeaderMap ;
4138
@@ -238,6 +235,8 @@ public static class Builder {
238235 private Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT ;
239236 private int retryTimes = 0 ;
240237 private Proxy proxy ;
238+ private ConnectionPool connectionPool ;
239+ private Dispatcher dispatcher ;
241240
242241 public ArkService .Builder ak (String ak ) {
243242 this .ak = ak ;
@@ -287,6 +286,16 @@ public ArkService.Builder proxy(Proxy proxy) {
287286 return this ;
288287 }
289288
289+ public ArkService .Builder connectionPool (ConnectionPool connectionPool ) {
290+ this .connectionPool = connectionPool ;
291+ return this ;
292+ }
293+
294+ public ArkService .Builder dispatcher (Dispatcher dispatcher ) {
295+ this .dispatcher = dispatcher ;
296+ return this ;
297+ }
298+
290299 public ArkService build () {
291300 ObjectMapper mapper = defaultObjectMapper ();
292301 OkHttpClient .Builder clientBuilder = new OkHttpClient .Builder ();
@@ -302,10 +311,19 @@ public ArkService build() {
302311 clientBuilder .proxy (proxy );
303312 }
304313
314+ if (connectionPool != null ) {
315+ clientBuilder .connectionPool (connectionPool );
316+ } else {
317+ clientBuilder .connectionPool (new ConnectionPool (5 , 1 , TimeUnit .SECONDS ));
318+ }
319+
320+ if (dispatcher != null ) {
321+ clientBuilder .dispatcher (dispatcher );
322+ }
323+
305324 OkHttpClient client = clientBuilder
306325 .addInterceptor (new RequestIdInterceptor ())
307326 .addInterceptor (new RetryInterceptor (retryTimes ))
308- .connectionPool (new ConnectionPool (5 , 1 , TimeUnit .SECONDS ))
309327 .readTimeout (timeout .toMillis (), TimeUnit .MILLISECONDS )
310328 .connectTimeout (connectTimeout )
311329 .build ();
0 commit comments