Unverified Commit 4b2f3a4e authored by Brian Krische's avatar Brian Krische Committed by GitHub
Browse files

Implement AutoCloseable to close the underlying client. (#520)

parent 75a66339
package org.gitlab4j.api; package org.gitlab4j.api;
import java.io.Closeable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -23,7 +24,7 @@ import org.gitlab4j.api.utils.SecretString; ...@@ -23,7 +24,7 @@ import org.gitlab4j.api.utils.SecretString;
* This class is provides a simplified interface to a GitLab API server, and divides the API up into * This class is provides a simplified interface to a GitLab API server, and divides the API up into
* a separate API class for each concern. * a separate API class for each concern.
*/ */
public class GitLabApi { public class GitLabApi implements AutoCloseable {
private final static Logger LOGGER = Logger.getLogger(GitLabApi.class.getName()); private final static Logger LOGGER = Logger.getLogger(GitLabApi.class.getName());
...@@ -482,6 +483,17 @@ public class GitLabApi { ...@@ -482,6 +483,17 @@ public class GitLabApi {
return (this); return (this);
} }
/**
* Close the underlying {@link javax.ws.rs.client.Client} and its associated resources.
*/
@Override
public void close() {
if (apiClient != null) {
apiClient.close();
}
}
/** /**
* Enable the logging of the requests to and the responses from the GitLab server API * Enable the logging of the requests to and the responses from the GitLab server API
* using the GitLab4J shared Logger instance and Level.FINE as the level. * using the GitLab4J shared Logger instance and Level.FINE as the level.
......
...@@ -48,7 +48,7 @@ import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; ...@@ -48,7 +48,7 @@ import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
/** /**
* This class utilizes the Jersey client package to communicate with a GitLab API endpoint. * This class utilizes the Jersey client package to communicate with a GitLab API endpoint.
*/ */
public class GitLabApiClient { public class GitLabApiClient implements AutoCloseable {
protected static final String PRIVATE_TOKEN_HEADER = "PRIVATE-TOKEN"; protected static final String PRIVATE_TOKEN_HEADER = "PRIVATE-TOKEN";
protected static final String SUDO_HEADER = "Sudo"; protected static final String SUDO_HEADER = "Sudo";
...@@ -243,6 +243,16 @@ public class GitLabApiClient { ...@@ -243,6 +243,16 @@ public class GitLabApiClient {
clientConfig.register(MultiPartFeature.class); clientConfig.register(MultiPartFeature.class);
} }
/**
* Close the underlying {@link Client} and its associated resources.
*/
@Override
public void close() {
if (apiClient != null) {
apiClient.close();
}
}
/** /**
* Enable the logging of the requests to and the responses from the GitLab server API. * Enable the logging of the requests to and the responses from the GitLab server API.
* *
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment