Search in sources :

Example 6 with BufferedRecord

use of org.apache.gobblin.async.BufferedRecord in project incubator-gobblin by apache.

the class AsyncHttpJoinConverter method convertRecordAsync.

/**
 * Convert an input record to a future object where an output record will be filled in sometime later
 * Sequence:
 *    Convert input (DI) to an http request
 *    Send http request asynchronously, and registers an http callback
 *    Create an {@link CompletableFuture} object. When the callback is invoked, this future object is filled in by an output record which is converted from http response.
 *    Return the future object.
 */
@Override
public final CompletableFuture<DO> convertRecordAsync(SO outputSchema, DI inputRecord, WorkUnitState workUnitState) throws DataConversionException {
    // Convert DI to HttpOperation
    HttpOperation operation = generateHttpOperation(inputRecord, workUnitState);
    BufferedRecord<GenericRecord> bufferedRecord = new BufferedRecord<>(operation, WriteCallback.EMPTY);
    // Convert HttpOperation to RQ
    Queue<BufferedRecord<GenericRecord>> buffer = new LinkedBlockingDeque<>();
    buffer.add(bufferedRecord);
    AsyncRequest<GenericRecord, RQ> request = this.requestBuilder.buildRequest(buffer);
    RQ rawRequest = request.getRawRequest();
    // Execute query and get response
    AsyncHttpJoinConverterContext context = new AsyncHttpJoinConverterContext(this, outputSchema, inputRecord, request);
    try {
        httpClient.sendAsyncRequest(rawRequest, context.getCallback());
    } catch (IOException e) {
        throw new DataConversionException(e);
    }
    return context.future;
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HttpOperation(org.apache.gobblin.http.HttpOperation) BufferedRecord(org.apache.gobblin.async.BufferedRecord) IOException(java.io.IOException) GenericRecord(org.apache.avro.generic.GenericRecord)

Aggregations

BufferedRecord (org.apache.gobblin.async.BufferedRecord)6 GenericRecord (org.apache.avro.generic.GenericRecord)5 HttpOperation (org.apache.gobblin.http.HttpOperation)3 IOException (java.io.IOException)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 URI (java.net.URI)1 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 ResponseStatus (org.apache.gobblin.http.ResponseStatus)1 R2RestRequestBuilder (org.apache.gobblin.r2.R2RestRequestBuilder)1 FutureWrappedWriteCallback (org.apache.gobblin.writer.FutureWrappedWriteCallback)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 RequestBuilder (org.apache.http.client.methods.RequestBuilder)1 StringEntity (org.apache.http.entity.StringEntity)1