Search in sources :

Example 6 with ResponseHandler

use of com.facebook.airlift.http.client.ResponseHandler in project presto by prestodb.

the class TaskInfoFetcher method sendNextRequest.

private synchronized void sendNextRequest() {
    TaskInfo taskInfo = getTaskInfo();
    TaskStatus taskStatus = taskInfo.getTaskStatus();
    if (!running) {
        return;
    }
    // we already have the final task info
    if (isDone(getTaskInfo())) {
        stop();
        return;
    }
    // if we have an outstanding request
    if (future != null && !future.isDone()) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendNextRequest, executor);
        return;
    }
    MetadataUpdates metadataUpdateRequests = taskInfo.getMetadataUpdates();
    if (!metadataUpdateRequests.getMetadataUpdates().isEmpty()) {
        scheduleMetadataUpdates(metadataUpdateRequests);
    }
    HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf());
    URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build();
    Request.Builder uriBuilder = setContentTypeHeaders(isBinaryTransportEnabled, prepareGet());
    if (taskInfoRefreshMaxWait.toMillis() != 0L) {
        uriBuilder.setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, taskInfoRefreshMaxWait.toString());
    }
    Request request = uriBuilder.setUri(uri).build();
    ResponseHandler responseHandler;
    if (isBinaryTransportEnabled) {
        responseHandler = createFullSmileResponseHandler((SmileCodec<TaskInfo>) taskInfoCodec);
    } else {
        responseHandler = createAdaptingJsonResponseHandler((JsonCodec<TaskInfo>) taskInfoCodec);
    }
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, responseHandler);
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats.getHttpResponseStats(), REMOTE_TASK_ERROR), executor);
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) SmileCodec(com.facebook.airlift.json.smile.SmileCodec) JsonCodec(com.facebook.airlift.json.JsonCodec) SimpleHttpResponseHandler(com.facebook.presto.server.SimpleHttpResponseHandler) FullSmileResponseHandler.createFullSmileResponseHandler(com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler) ResponseHandler(com.facebook.airlift.http.client.ResponseHandler) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) Request(com.facebook.airlift.http.client.Request) TaskStatus(com.facebook.presto.execution.TaskStatus) URI(java.net.URI)

Aggregations

ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)6 AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler (com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler)6 FullSmileResponseHandler.createFullSmileResponseHandler (com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler)6 Request (com.facebook.airlift.http.client.Request)5 SimpleHttpResponseHandler (com.facebook.presto.server.SimpleHttpResponseHandler)5 JsonCodec (com.facebook.airlift.json.JsonCodec)4 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)4 TaskStatus (com.facebook.presto.execution.TaskStatus)4 BaseResponse (com.facebook.presto.server.smile.BaseResponse)4 HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)2 StatusResponseHandler.createStatusResponseHandler (com.facebook.airlift.http.client.StatusResponseHandler.createStatusResponseHandler)2 TaskInfo (com.facebook.presto.execution.TaskInfo)2 Response (com.facebook.airlift.http.client.Response)1 ThriftResponseHandler (com.facebook.airlift.http.client.thrift.ThriftResponseHandler)1 TaskSource (com.facebook.presto.execution.TaskSource)1 TableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo)1 MetadataUpdates (com.facebook.presto.metadata.MetadataUpdates)1 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)1 ThriftHttpResponseHandler (com.facebook.presto.server.thrift.ThriftHttpResponseHandler)1 PrestoException (com.facebook.presto.spi.PrestoException)1