From 4c697e4cb39ba7e223f8f624a94c1dbf0e733a88 Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Fri, 9 Feb 2024 14:31:41 +0100 Subject: [PATCH] feat: close minioClient properly --- .../java/fr/insee/arc/utils/minio/S3Template.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java b/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java index bb2f9693e..5f7127acf 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java @@ -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 { @@ -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) { @@ -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(); } @@ -73,5 +75,10 @@ public void createDirectory(String path) throws ArcException { } } + public void closeMinioClient() + { + httpClient.dispatcher().executorService().shutdown(); + this.minioClient=null; + } }