From 7bf6921c337f4cf4e9b9ad4efa0cb99dd8b48b65 Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Fri, 6 Jan 2023 11:47:17 -0800 Subject: [PATCH] Implements Closeable for SDKClients Signed-off-by: Owais Kazi --- src/main/java/org/opensearch/sdk/SDKClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index ed2790c35..3e8affd50 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -9,6 +9,7 @@ package org.opensearch.sdk; +import java.io.Closeable; import java.io.IOException; import com.fasterxml.jackson.annotation.JsonTypeInfo; @@ -39,7 +40,7 @@ /** * This class creates SDKClient for an extension to make requests to OpenSearch */ -public class SDKClient { +public class SDKClient implements Closeable { private OpenSearchClient javaClient; private RestClient restClient; private RestHighLevelClient highLevelClient; @@ -98,6 +99,7 @@ public OpenSearchClient initializeJavaClient(String hostAddress, int port) { } /** + * @Deprecated @deprecated Provided for compatibility with existing plugins to permit migration. New development should not use this client * Creates High Level Rest Client for SDK. * @param hostAddress The address of OpenSearch cluster, client can connect to * @param port The port of OpenSearch cluster @@ -131,4 +133,10 @@ public void doCloseHighLevelClient() throws IOException { highLevelClient.close(); } } + + @Override + public void close() throws IOException { + doCloseJavaClient(); + doCloseHighLevelClient(); + } }