Skip to content

Commit

Permalink
Implements Closeable for SDKClients
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
  • Loading branch information
owaiskazi19 committed Jan 6, 2023
1 parent f57c047 commit 18971a6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.opensearch.sdk;

import java.io.Closeable;
import java.io.IOException;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -98,11 +99,13 @@ public OpenSearchClient initializeJavaClient(String hostAddress, int port) {
}

/**
* @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
* @return The SDKClient implementation of RestHighLevelClient. The user is responsible for calling {@link #doCloseHighLevelClient()} when finished with the client
*/
@Deprecated
public RestHighLevelClient initializeRestClient(String hostAddress, int port) {
RestClientBuilder builder = builder(hostAddress, port);

Expand Down Expand Up @@ -131,4 +134,10 @@ public void doCloseHighLevelClient() throws IOException {
highLevelClient.close();
}
}

@Override
public void close() throws IOException {
doCloseJavaClient();
doCloseHighLevelClient();
}
}

0 comments on commit 18971a6

Please sign in to comment.