Skip to content

Commit 74b14cf

Browse files
author
thomasva
committed
Add injection of custom executor service to S3Base supplyAsync calls
1 parent 40b054f commit 74b14cf

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

api/src/main/java/io/minio/MinioAsyncClient.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
import java.util.concurrent.CompletableFuture;
7777
import java.util.concurrent.CompletionException;
7878
import java.util.concurrent.ExecutionException;
79+
import java.util.concurrent.ExecutorService;
80+
import java.util.concurrent.ForkJoinPool;
7981
import java.util.regex.Matcher;
8082
import okhttp3.HttpUrl;
8183
import okhttp3.OkHttpClient;
@@ -139,7 +141,8 @@ private MinioAsyncClient(
139141
boolean useVirtualStyle,
140142
String region,
141143
Provider provider,
142-
OkHttpClient httpClient) {
144+
OkHttpClient httpClient,
145+
ExecutorService executorService) {
143146
super(
144147
baseUrl,
145148
awsS3Prefix,
@@ -148,7 +151,8 @@ private MinioAsyncClient(
148151
useVirtualStyle,
149152
region,
150153
provider,
151-
httpClient);
154+
httpClient,
155+
executorService);
152156
}
153157

154158
protected MinioAsyncClient(MinioAsyncClient client) {
@@ -3221,6 +3225,7 @@ public static final class Builder {
32213225
private String region;
32223226
private Provider provider;
32233227
private OkHttpClient httpClient;
3228+
private ExecutorService executorService = ForkJoinPool.commonPool();
32243229

32253230
private void setAwsInfo(String host, boolean https) {
32263231
this.awsS3Prefix = null;
@@ -3327,6 +3332,11 @@ public Builder httpClient(OkHttpClient httpClient) {
33273332
return this;
33283333
}
33293334

3335+
public Builder executorService(ExecutorService executorService) {
3336+
this.executorService = executorService;
3337+
return this;
3338+
}
3339+
33303340
public MinioAsyncClient build() {
33313341
HttpUtils.validateNotNull(this.baseUrl, "endpoint");
33323342

@@ -3352,7 +3362,8 @@ public MinioAsyncClient build() {
33523362
useVirtualStyle,
33533363
region,
33543364
provider,
3355-
httpClient);
3365+
httpClient,
3366+
executorService);
33563367
}
33573368
}
33583369
}

api/src/main/java/io/minio/S3Base.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import java.util.concurrent.CompletionException;
8585
import java.util.concurrent.ConcurrentHashMap;
8686
import java.util.concurrent.ExecutionException;
87+
import java.util.concurrent.ExecutorService;
8788
import java.util.concurrent.TimeUnit;
8889
import java.util.logging.Logger;
8990
import java.util.stream.Collectors;
@@ -136,6 +137,7 @@ public abstract class S3Base {
136137
protected String region;
137138
protected Provider provider;
138139
protected OkHttpClient httpClient;
140+
private final ExecutorService executorService;
139141

140142
protected S3Base(
141143
HttpUrl baseUrl,
@@ -145,7 +147,8 @@ protected S3Base(
145147
boolean useVirtualStyle,
146148
String region,
147149
Provider provider,
148-
OkHttpClient httpClient) {
150+
OkHttpClient httpClient,
151+
ExecutorService executorService) {
149152
this.baseUrl = baseUrl;
150153
this.awsS3Prefix = awsS3Prefix;
151154
this.awsDomainSuffix = awsDomainSuffix;
@@ -154,6 +157,7 @@ protected S3Base(
154157
this.region = region;
155158
this.provider = provider;
156159
this.httpClient = httpClient;
160+
this.executorService = executorService;
157161
}
158162

159163
/** @deprecated This method is no longer supported. */
@@ -167,7 +171,8 @@ protected S3Base(
167171
boolean isDualStackHost,
168172
boolean useVirtualStyle,
169173
Provider provider,
170-
OkHttpClient httpClient) {
174+
OkHttpClient httpClient,
175+
ExecutorService executorService) {
171176
this.baseUrl = baseUrl;
172177
if (isAwsHost) this.awsS3Prefix = "s3.";
173178
if (isFipsHost) this.awsS3Prefix = "s3-fips.";
@@ -182,6 +187,7 @@ protected S3Base(
182187
this.region = region;
183188
this.provider = provider;
184189
this.httpClient = httpClient;
190+
this.executorService = executorService;
185191
}
186192

187193
protected S3Base(S3Base client) {
@@ -193,6 +199,7 @@ protected S3Base(S3Base client) {
193199
this.region = client.region;
194200
this.provider = client.provider;
195201
this.httpClient = client.httpClient;
202+
this.executorService = client.executorService;
196203
}
197204

198205
/** Check whether argument is valid or not. */
@@ -1135,7 +1142,8 @@ protected CompletableFuture<Integer> calculatePartCountAsync(List<ComposeSource>
11351142
long[] objectSize = {0};
11361143
int index = 0;
11371144

1138-
CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> 0);
1145+
CompletableFuture<Integer> completableFuture =
1146+
CompletableFuture.supplyAsync(() -> 0, executorService);
11391147
for (ComposeSource src : sources) {
11401148
index++;
11411149
final int i = index;
@@ -2854,7 +2862,8 @@ private CompletableFuture<ObjectWriteResponse> putMultipartObjectAsync(
28542862
}
28552863
}
28562864
return response;
2857-
});
2865+
},
2866+
executorService);
28582867
}
28592868

28602869
/**
@@ -2900,7 +2909,8 @@ protected CompletableFuture<ObjectWriteResponse> putObjectAsync(
29002909
} catch (NoSuchAlgorithmException | IOException e) {
29012910
throw new CompletionException(e);
29022911
}
2903-
})
2912+
},
2913+
executorService)
29042914
.thenCompose(
29052915
partSource -> {
29062916
try {

0 commit comments

Comments
 (0)