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);
}
Aggregations