本文整理了Java中io.airlift.http.client.HttpClient.executeAsync()
方法的一些代码示例,展示了HttpClient.executeAsync()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.executeAsync()
方法的具体详情如下:
包路径:io.airlift.http.client.HttpClient
类名称:HttpClient
方法名:executeAsync
暂无
代码示例来源:origin: prestodb/presto
private FluentFuture<ProxyResponse> executeHttp(Request request)
{
return FluentFuture.from(httpClient.executeAsync(request, new ProxyResponseHandler()));
}
代码示例来源:origin: prestodb/presto
private void doScheduleAsyncCleanupRequest(Backoff cleanupBackoff, Request request, String action)
Futures.addCallback(httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec)), new FutureCallback<JsonResponse<TaskInfo>>()
代码示例来源:origin: prestodb/presto
httpClient.executeAsync(prepareGet().setUri(uri).build(), new ResponseHandler<Void, RuntimeException>()
代码示例来源:origin: prestodb/presto
private synchronized void sendDelete()
HttpResponseFuture<StatusResponse> resultFuture = httpClient.executeAsync(prepareDelete().setUri(location).build(), createStatusResponseHandler());
future = resultFuture;
Futures.addCallback(resultFuture, new FutureCallback<StatusResponse>()
代码示例来源:origin: prestodb/presto
private void ping()
{
try {
stats.recordStart();
httpClient.executeAsync(prepareHead().setUri(uri).build(), new ResponseHandler<Object, Exception>()
{
@Override
public Exception handleException(Request request, Exception exception)
{
// ignore error
stats.recordFailure(exception);
// TODO: this will technically cause an NPE in httpClient, but it's not triggered because
// we never call get() on the response future. This behavior needs to be fixed in airlift
return null;
}
@Override
public Object handle(Request request, Response response)
{
stats.recordSuccess();
return null;
}
});
}
catch (RuntimeException e) {
log.warn(e, "Error scheduling request for %s", uri);
}
}
代码示例来源:origin: prestodb/presto
ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
currentRequest = future;
currentRequestStartNanos = System.nanoTime();
代码示例来源:origin: prestodb/presto
private synchronized void sendGetResults()
HttpResponseFuture<PagesResponse> resultFuture = httpClient.executeAsync(
prepareGet()
.setHeader(PRESTO_MAX_SIZE, maxResponseSize.toString())
代码示例来源:origin: prestodb/presto
future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
currentRequestStartNanos.set(System.nanoTime());
Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
代码示例来源:origin: prestodb/presto
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 request = prepareGet()
.setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build())
.setHeader(CONTENT_TYPE, JSON_UTF_8.toString())
.setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString())
.setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString())
.build();
errorTracker.startRequest();
future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec));
currentRequestStartNanos.set(System.nanoTime());
Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
代码示例来源:origin: prestosql/presto
private FluentFuture<ProxyResponse> executeHttp(Request request)
{
return FluentFuture.from(httpClient.executeAsync(request, new ProxyResponseHandler()));
}
代码示例来源:origin: airlift/airlift
@Override
public ListenableFuture<Void> unannounce()
{
URI uri = discoveryServiceURI.get();
if (uri == null) {
return immediateFuture(null);
}
Request request = prepareDelete()
.setUri(URI.create(uri + "/v1/announcement/" + nodeInfo.getNodeId()))
.setHeader("User-Agent", nodeInfo.getNodeId())
.build();
return httpClient.executeAsync(request, new DiscoveryResponseHandler<>("Unannouncement", uri));
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-client
@Override
public void close()
{
if (!closed.getAndSet(true)) {
URI uri = currentResults.get().getNextUri();
if (uri != null) {
Request request = prepareDelete()
.setHeader(USER_AGENT, USER_AGENT_VALUE)
.setUri(uri)
.build();
httpClient.executeAsync(request, createStatusResponseHandler());
}
}
}
}
代码示例来源:origin: com.teradata.airlift/discovery
@Override
public ListenableFuture<Void> unannounce()
{
URI uri = discoveryServiceURI.get();
if (uri == null) {
return Futures.immediateCheckedFuture(null);
}
Request request = prepareDelete()
.setUri(URI.create(uri + "/v1/announcement/" + nodeInfo.getNodeId()))
.setHeader("User-Agent", nodeInfo.getNodeId())
.build();
return httpClient.executeAsync(request, new DiscoveryResponseHandler<>("Unannouncement", uri));
}
代码示例来源:origin: io.prestosql/presto-main
private void ping()
{
try {
stats.recordStart();
httpClient.executeAsync(prepareHead().setUri(uri).build(), new ResponseHandler<Object, Exception>()
{
@Override
public Exception handleException(Request request, Exception exception)
{
// ignore error
stats.recordFailure(exception);
// TODO: this will technically cause an NPE in httpClient, but it's not triggered because
// we never call get() on the response future. This behavior needs to be fixed in airlift
return null;
}
@Override
public Object handle(Request request, Response response)
{
stats.recordSuccess();
return null;
}
});
}
catch (RuntimeException e) {
log.warn(e, "Error scheduling request for %s", uri);
}
}
代码示例来源:origin: airlift/airlift
@Override
public <T> ListenableFuture<Void> post(EventGenerator<T> eventGenerator)
{
requireNonNull(eventGenerator, "eventGenerator is null");
List<URI> uris = serviceSelector.selectHttpService();
if (uris.isEmpty()) {
return immediateFailedFuture(new ServiceUnavailableException(serviceSelector.getType(), serviceSelector.getPool()));
}
// todo this doesn't really work due to returning the future which can fail without being retried
Request request = preparePost()
.setUri(uris.get(0).resolve("/v2/event"))
.setHeader("User-Agent", nodeInfo.getNodeId())
.setHeader("Content-Type", MEDIA_TYPE_JSON.toString())
.setBodyGenerator(new JsonEntityWriter<>(eventWriter, eventGenerator))
.build();
return httpClient.executeAsync(request, new EventResponseHandler(serviceSelector.getType(), serviceSelector.getPool()));
}
代码示例来源:origin: com.teradata.airlift/event
@Override
public <T> ListenableFuture<Void> post(EventGenerator<T> eventGenerator)
{
checkNotNull(eventGenerator, "eventGenerator is null");
List<URI> uris = serviceSelector.selectHttpService();
if (uris.isEmpty()) {
return Futures.<Void, RuntimeException>immediateFailedCheckedFuture(new ServiceUnavailableException(serviceSelector.getType(), serviceSelector.getPool()));
}
// todo this doesn't really work due to returning the future which can fail without being retried
Request request = preparePost()
.setUri(uris.get(0).resolve("/v2/event"))
.setHeader("User-Agent", nodeInfo.getNodeId())
.setHeader("Content-Type", MEDIA_TYPE_JSON.toString())
.setBodyGenerator(new JsonEntityWriter<>(eventWriter, eventGenerator))
.build();
return httpClient.executeAsync(request, new EventResponseHandler(serviceSelector.getType(), serviceSelector.getPool()));
}
代码示例来源:origin: io.airlift/event
@Override
public <T> ListenableFuture<Void> post(EventGenerator<T> eventGenerator)
{
requireNonNull(eventGenerator, "eventGenerator is null");
List<URI> uris = serviceSelector.selectHttpService();
if (uris.isEmpty()) {
return immediateFailedFuture(new ServiceUnavailableException(serviceSelector.getType(), serviceSelector.getPool()));
}
// todo this doesn't really work due to returning the future which can fail without being retried
Request request = preparePost()
.setUri(uris.get(0).resolve("/v2/event"))
.setHeader("User-Agent", nodeInfo.getNodeId())
.setHeader("Content-Type", MEDIA_TYPE_JSON.toString())
.setBodyGenerator(new JsonEntityWriter<>(eventWriter, eventGenerator))
.build();
return httpClient.executeAsync(request, new EventResponseHandler(serviceSelector.getType(), serviceSelector.getPool()));
}
代码示例来源:origin: com.teradata.airlift/http-server
@Test(timeOut = 60000)
public void testStop()
throws Exception
{
createAndStartServer();
try (HttpClient client = new JettyHttpClient()) {
URI uri = URI.create(httpServerInfo.getHttpUri().toASCIIString() + "/?sleep=50000");
Request request = prepareGet().setUri(uri).build();
HttpResponseFuture<?> future = client.executeAsync(request, createStatusResponseHandler());
server.stop();
try {
future.get(1, TimeUnit.SECONDS);
fail("expected exception");
}
catch (ExecutionException e) {
assertInstanceOf(e.getCause(), RuntimeIOException.class);
}
}
}
代码示例来源:origin: io.airlift/http-server
@Test(timeOut = 30000)
public void testStop()
throws Exception
{
DummyServlet servlet = new DummyServlet();
createAndStartServer(servlet);
try (HttpClient client = new JettyHttpClient()) {
URI uri = URI.create(httpServerInfo.getHttpUri().toASCIIString() + "/?sleep=50000");
Request request = prepareGet().setUri(uri).build();
HttpResponseFuture<?> future = client.executeAsync(request, createStatusResponseHandler());
// wait until the servlet starts processing the request
servlet.getLatch().await(1, TimeUnit.SECONDS);
// stop server while the request is still active
server.stop();
// wait until the server is stopped
server.join();
// request should fail rather than sleeping the full duration
try {
future.get(5, TimeUnit.SECONDS);
fail("expected exception");
}
catch (ExecutionException e) {
assertInstanceOf(e.getCause(), UncheckedIOException.class);
}
}
}
代码示例来源:origin: prestosql/presto
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 request = prepareGet()
.setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build())
.setHeader(CONTENT_TYPE, JSON_UTF_8.toString())
.setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString())
.setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString())
.build();
errorTracker.startRequest();
future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec));
currentRequestStartNanos.set(System.nanoTime());
Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
内容来源于网络,如有侵权,请联系作者删除!