Implementation:Datahub project Datahub DataHubClientV2 Close
| Property | Value |
|---|---|
| Implementation Name | DataHubClientV2_Close |
| Workflow | Java_SDK_V2_Entity_Management |
| Type | API Doc |
| Principle | Principle:Datahub_project_Datahub_Client_Resource_Cleanup |
| Repository | https://github.com/datahub-project/datahub |
| Last Updated | 2026-02-09 17:00 GMT |
Overview
Description
DataHubClientV2_Close documents the DataHubClientV2.close() method, which implements the AutoCloseable interface for deterministic resource cleanup. The method shuts down the underlying RestEmitter, which in turn closes the HTTP async client, terminates worker threads, and releases all pooled connections. This enables the use of Java's try-with-resources pattern for guaranteed cleanup.
Usage
Call client.close() when the client is no longer needed, or use try-with-resources for automatic cleanup. Ensure all pending operations have completed before closing.
Code Reference
Source Location
metadata-integration/java/datahub-client/src/main/java/datahub/client/v2/DataHubClientV2.java (Lines 212-216)
Signature
@Override
public void close() throws IOException {
log.info("Closing DataHub Client V2");
emitter.close();
}
Import
import datahub.client.v2.DataHubClientV2;
I/O Contract
Input:
| Parameter | Type | Description |
|---|---|---|
| none | -- | Method takes no parameters |
Output:
| Return | Description |
|---|---|
void |
Method completes when all resources are released |
Exceptions:
| Exception | Cause |
|---|---|
IOException |
Thrown if the underlying RestEmitter fails to close (e.g., error shutting down HTTP client)
|
Resources Released:
| Resource | Action |
|---|---|
| HTTP async client | Shut down via RestEmitter.close()
|
| Connection pool | All pooled HTTP connections closed |
| Worker threads | Async I/O thread pools terminated |
Interface:
DataHubClientV2 implements java.lang.AutoCloseable, which declares:
public interface AutoCloseable {
void close() throws Exception;
}
Usage Examples
Try-With-Resources (Recommended)
import datahub.client.v2.DataHubClientV2;
import datahub.client.v2.entity.Dataset;
// Client is automatically closed when try block exits
try (DataHubClientV2 client = DataHubClientV2.builder()
.server("http://localhost:8080")
.token("my-token")
.build()) {
Dataset dataset = Dataset.builder()
.platform("snowflake")
.name("analytics.users")
.description("User table")
.build();
client.entities().upsert(dataset);
} // client.close() called automatically here, even if an exception occurred
Explicit Close
DataHubClientV2 client = DataHubClientV2.builder()
.server("http://localhost:8080")
.build();
try {
// Perform operations
client.entities().upsert(dataset);
} finally {
// Ensure cleanup even on exception
client.close();
}
Application Lifecycle Management
public class MetadataService {
private final DataHubClientV2 client;
public MetadataService(String server, String token) throws IOException {
this.client = DataHubClientV2.builder()
.server(server)
.token(token)
.build();
}
public void registerDataset(String platform, String name) throws Exception {
Dataset dataset = Dataset.builder()
.platform(platform)
.name(name)
.build();
client.entities().upsert(dataset);
}
// Called during application shutdown
public void shutdown() throws IOException {
client.close();
}
}
Multiple Clients in Try-With-Resources
// Multiple clients are closed in reverse order of declaration
try (DataHubClientV2 prodClient = DataHubClientV2.builder()
.server("https://prod.datahub.example.com")
.token(prodToken)
.build();
DataHubClientV2 devClient = DataHubClientV2.builder()
.server("http://dev.datahub.example.com")
.token(devToken)
.build()) {
// Use both clients...
Dataset prodDataset = prodClient.entities().get(urn, Dataset.class);
} // devClient.close() called first, then prodClient.close()
Related Pages
- Principle:Datahub_project_Datahub_Client_Resource_Cleanup
- Implementation:Datahub_project_Datahub_DataHubClientV2_Builder -- Client creation that establishes resources
- Implementation:Datahub_project_Datahub_EntityClient_Upsert -- Operations that must complete before close
- Implementation:Datahub_project_Datahub_EntityClient_Get -- Operations that must complete before close
- Environment:Datahub_project_Datahub_Java_Build