Skip to content

Commit

Permalink
feat: close minioClient properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Feb 9, 2024
1 parent 01bc923 commit 4c697e4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.minio.errors.InvalidResponseException;
import io.minio.errors.ServerException;
import io.minio.errors.XmlParserException;
import okhttp3.OkHttpClient;

public class S3Template {

Expand All @@ -34,6 +35,8 @@ public S3Template(String s3ApiUri, String bucket, String accessKey, String secre

private MinioClient minioClient;

private OkHttpClient httpClient;


public MinioClient getMinioClient() {
if (this.minioClient == null) {
Expand All @@ -48,9 +51,8 @@ public MinioClient getMinioClient() {
}

private void buildMinioClient() throws KeyManagementException, NoSuchAlgorithmException {


this.minioClient = MinioClient.builder().endpoint(s3ApiUri).credentials(accessKey, secretKey).build();
httpClient = new OkHttpClient().newBuilder().build();
this.minioClient = MinioClient.builder().endpoint(s3ApiUri).credentials(accessKey, secretKey).httpClient(httpClient).build();
this.minioClient.ignoreCertCheck();
}

Expand All @@ -73,5 +75,10 @@ public void createDirectory(String path) throws ArcException {
}
}

public void closeMinioClient()
{
httpClient.dispatcher().executorService().shutdown();
this.minioClient=null;
}

}

0 comments on commit 4c697e4

Please sign in to comment.