Search in sources :

Example 1 with ThriftResponseHandler

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

the class ContinuousTaskStatusFetcher method scheduleNextRequest.

private synchronized void scheduleNextRequest() {
    // stopped or done?
    TaskStatus taskStatus = getTaskStatus();
    if (!running || taskStatus.getState().isDone()) {
        return;
    }
    // outstanding request?
    if (future != null && !future.isDone()) {
        // this should never happen
        log.error("Can not reschedule update because an update is already running");
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::scheduleNextRequest, executor);
        return;
    }
    Request.Builder requestBuilder;
    ResponseHandler responseHandler;
    if (thriftTransportEnabled) {
        requestBuilder = ThriftRequestUtils.prepareThriftGet(thriftProtocol);
        responseHandler = new ThriftResponseHandler(unwrapThriftCodec(taskStatusCodec));
    } else if (binaryTransportEnabled) {
        requestBuilder = getBinaryTransportBuilder(prepareGet());
        responseHandler = createFullSmileResponseHandler((SmileCodec<TaskStatus>) taskStatusCodec);
    } else {
        requestBuilder = getJsonTransportBuilder(prepareGet());
        responseHandler = createAdaptingJsonResponseHandler((JsonCodec<TaskStatus>) taskStatusCodec);
    }
    Request request = requestBuilder.setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build()).setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString()).build();
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, responseHandler);
    currentRequestStartNanos.set(System.nanoTime());
    FutureCallback callback;
    if (thriftTransportEnabled) {
        callback = new ThriftHttpResponseHandler(this, request.getUri(), stats.getHttpResponseStats(), REMOTE_TASK_ERROR);
    } else {
        callback = new SimpleHttpResponseHandler<>(this, request.getUri(), stats.getHttpResponseStats(), REMOTE_TASK_ERROR);
    }
    Futures.addCallback(future, callback, executor);
}
Also used : ThriftResponseHandler(com.facebook.airlift.http.client.thrift.ThriftResponseHandler) SimpleHttpResponseHandler(com.facebook.presto.server.SimpleHttpResponseHandler) ThriftHttpResponseHandler(com.facebook.presto.server.thrift.ThriftHttpResponseHandler) 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) ThriftHttpResponseHandler(com.facebook.presto.server.thrift.ThriftHttpResponseHandler) Request(com.facebook.airlift.http.client.Request) ThriftResponseHandler(com.facebook.airlift.http.client.thrift.ThriftResponseHandler) TaskStatus(com.facebook.presto.execution.TaskStatus) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

Request (com.facebook.airlift.http.client.Request)1 ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)1 ThriftResponseHandler (com.facebook.airlift.http.client.thrift.ThriftResponseHandler)1 TaskStatus (com.facebook.presto.execution.TaskStatus)1 SimpleHttpResponseHandler (com.facebook.presto.server.SimpleHttpResponseHandler)1 AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler (com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler)1 FullSmileResponseHandler.createFullSmileResponseHandler (com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler)1 ThriftHttpResponseHandler (com.facebook.presto.server.thrift.ThriftHttpResponseHandler)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1