Skip to content

Commit 05b46da

Browse files
author
hexiaochun
committed
feat: expose dispatcher and connection pool
1 parent 889357e commit 05b46da

File tree

1 file changed

+23
-5
lines changed
  • volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/service

1 file changed

+23
-5
lines changed

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/service/ArkService.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
import io.reactivex.BackpressureStrategy;
2828
import io.reactivex.Flowable;
2929
import io.reactivex.Single;
30-
import okhttp3.Headers;
31-
import okhttp3.ResponseBody;
30+
import okhttp3.*;
3231
import org.apache.commons.lang.StringUtils;
3332
import retrofit2.Call;
3433
import retrofit2.HttpException;
3534
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
3635
import retrofit2.converter.jackson.JacksonConverterFactory;
37-
import okhttp3.ConnectionPool;
38-
import okhttp3.OkHttpClient;
3936
import retrofit2.Retrofit;
4037
import 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

Comments
 (0)