Implementation:Datahub project Datahub MetadataResponseFuture
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Metadata_Emission |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A Future<MetadataWriteResponse> implementation that wraps an underlying HTTP response future and maps it to a DataHub metadata write response.
Description
MetadataResponseFuture adapts an Apache HTTP Client Future<SimpleHttpResponse> into a Future<MetadataWriteResponse> that the DataHub client SDK consumers can work with. It supports two resolution strategies:
- Callback-based resolution: Uses a
CountDownLatchand anAtomicReference<MetadataWriteResponse>that an external callback populates. Theget()method waits on the latch until the callback completes. - Mapper-based resolution: Uses a
ResponseMapperfunctional interface to synchronously transform theSimpleHttpResponseinto aMetadataWriteResponsewhenget()is called.
The class delegates cancellation and status checks (cancel, isCancelled, isDone) directly to the underlying HTTP future.
The inner ResponseMapper functional interface provides a clean extension point for custom response mapping logic.
Usage
This class is used internally by the REST emitter to wrap asynchronous HTTP calls. It is not typically instantiated directly by SDK consumers but is returned from Emitter.emit() calls.
Code Reference
Source Location
metadata-integration/java/datahub-client/src/main/java/datahub/client/MetadataResponseFuture.java
Signature
public class MetadataResponseFuture implements Future<MetadataWriteResponse> {
// Callback-based constructor
public MetadataResponseFuture(
Future<SimpleHttpResponse> underlyingFuture,
AtomicReference<MetadataWriteResponse> responseAtomicReference,
CountDownLatch responseLatch)
// Mapper-based constructor
public MetadataResponseFuture(
Future<SimpleHttpResponse> underlyingFuture,
ResponseMapper mapper)
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
public boolean isDone()
public MetadataWriteResponse get() throws InterruptedException, ExecutionException
public MetadataWriteResponse get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException
@FunctionalInterface
public interface ResponseMapper {
MetadataWriteResponse map(SimpleHttpResponse httpResponse);
}
}
Import
import datahub.client.MetadataResponseFuture;
I/O Contract
Inputs
| Constructor | Parameter | Type | Description |
|---|---|---|---|
| Callback-based | underlyingFuture |
Future<SimpleHttpResponse> |
The underlying HTTP future |
| Callback-based | responseAtomicReference |
AtomicReference<MetadataWriteResponse> |
Reference populated by external callback |
| Callback-based | responseLatch |
CountDownLatch |
Latch signaled when the callback completes |
| Mapper-based | underlyingFuture |
Future<SimpleHttpResponse> |
The underlying HTTP future |
| Mapper-based | mapper |
ResponseMapper |
Functional interface mapping HTTP response to metadata response |
Outputs
get()andget(timeout, unit)return aMetadataWriteResponsecontaining the success status and response content.cancel(),isCancelled(), andisDone()return boolean status values delegated from the underlying future.
Usage Examples
// Mapper-based usage (internal to REST emitter)
MetadataResponseFuture future = new MetadataResponseFuture(
httpFuture,
response -> MetadataWriteResponse.builder()
.success(response.getCode() == 200)
.responseContent(response.getBodyText())
.build()
);
MetadataWriteResponse result = future.get(10, TimeUnit.SECONDS);
Related Pages
- Datahub_project_Datahub_MetadataWriteCallback_Interface -- Callback interface used with callback-based resolution
- Datahub_project_Datahub_RestEmitterConfig -- Configuration for the REST emitter that produces these futures