use of io.airlift.http.client.FullJsonResponseHandler.JsonResponse in project presto by prestodb.
the class RemoteNodeState method asyncRefresh.
public synchronized void asyncRefresh() {
Duration sinceUpdate = nanosSince(lastUpdateNanos.get());
if (nanosSince(lastWarningLogged.get()).toMillis() > 1_000 && sinceUpdate.toMillis() > 10_000 && future.get() != null) {
log.warn("Node state update request to %s has not returned in %s", stateInfoUri, sinceUpdate.toString(SECONDS));
lastWarningLogged.set(System.nanoTime());
}
if (sinceUpdate.toMillis() > 1_000 && future.get() == null) {
Request request = prepareGet().setUri(stateInfoUri).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).build();
HttpResponseFuture<JsonResponse<NodeState>> responseFuture = httpClient.executeAsync(request, createFullJsonResponseHandler(jsonCodec(NodeState.class)));
future.compareAndSet(null, responseFuture);
Futures.addCallback(responseFuture, new FutureCallback<JsonResponse<NodeState>>() {
@Override
public void onSuccess(@Nullable JsonResponse<NodeState> result) {
lastUpdateNanos.set(System.nanoTime());
future.compareAndSet(responseFuture, null);
if (result != null) {
if (result.hasValue()) {
nodeState.set(ofNullable(result.getValue()));
}
if (result.getStatusCode() != OK.code()) {
log.warn("Error fetching node state from %s returned status %d: %s", stateInfoUri, result.getStatusCode(), result.getStatusMessage());
return;
}
}
}
@Override
public void onFailure(Throwable t) {
log.warn("Error fetching node state from %s: %s", stateInfoUri, t.getMessage());
lastUpdateNanos.set(System.nanoTime());
future.compareAndSet(responseFuture, null);
}
});
}
}
Aggregations