Package io.airlift.http.client

Examples of io.airlift.http.client.Request


        TaskUpdateRequest updateRequest = new TaskUpdateRequest(session,
                planFragment,
                sources,
                new OutputBuffers(outputIds, noMoreOutputIds));

        Request request = preparePost()
                .setUri(uriBuilderFrom(taskInfo.get().getSelf()).build())
                .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
                .setBodyGenerator(jsonBodyGenerator(taskUpdateRequestCodec, updateRequest))
                .build();

        ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
        currentRequest = future;
        currentRequestStartNanos = System.nanoTime();

        Futures.addCallback(future, new SimpleHttpResponseHandler<>(new UpdateResponseHandler(sources), request.getUri()), executor);

        needsUpdate.set(false);
    }
View Full Code Here


                    ImmutableMap.<PlanNodeId, Set<?>>of()));

            // fire delete to task and ignore response
            if (taskInfo.getSelf() != null) {
                final long start = System.nanoTime();
                final Request request = prepareDelete().setUri(taskInfo.getSelf()).build();
                Futures.addCallback(httpClient.executeAsync(request, createStatusResponseHandler()), new FutureCallback<StatusResponse>()
                {
                    @Override
                    public void onSuccess(StatusResponse result)
                    {
                        // assume any response is good enough
                    }

                    @Override
                    public void onFailure(Throwable t)
                    {
                        if (t instanceof RejectedExecutionException) {
                            // client has been shutdown
                            return;
                        }

                        // reschedule
                        if (Duration.nanosSince(start).compareTo(new Duration(2, TimeUnit.MINUTES)) < 0) {
                            Futures.addCallback(httpClient.executeAsync(request, createStatusResponseHandler()), this, executor);
                        }
                        else {
                            log.error(t, "Unable to cancel task at %s", request.getUri());
                        }
                    }
                }, executor);
            }
        }
View Full Code Here

                    // this should never happen
                    log.error("Can not reschedule update because an update is already running");
                    return;
                }

                Request request = prepareGet()
                        .setUri(taskInfo.getSelf())
                        .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
                        .setHeader(PrestoHeaders.PRESTO_CURRENT_STATE, taskInfo.getState().toString())
                        .setHeader(PrestoHeaders.PRESTO_MAX_WAIT, "200ms")
                        .build();

                future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
                Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri()), executor);
            }
        }
View Full Code Here

        TaskUpdateRequest updateRequest = new TaskUpdateRequest(session,
                planFragment,
                sources,
                outputBuffers.get());

        Request request = preparePost()
                .setUri(uriBuilderFrom(taskInfo.get().getSelf()).build())
                .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
                .setBodyGenerator(jsonBodyGenerator(taskUpdateRequestCodec, updateRequest))
                .build();

        ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
        currentRequest = future;
        currentRequestStartNanos = System.nanoTime();

        Futures.addCallback(future, new SimpleHttpResponseHandler<>(new UpdateResponseHandler(sources), request.getUri()), executor);

        needsUpdate.set(false);
    }
View Full Code Here

                    ImmutableList.<ExecutionFailureInfo>of()));

            // fire delete to task and ignore response
            if (taskInfo.getSelf() != null) {
                final long start = System.nanoTime();
                final Request request = prepareDelete().setUri(taskInfo.getSelf()).build();
                Futures.addCallback(httpClient.executeAsync(request, createStatusResponseHandler()), new FutureCallback<StatusResponse>()
                {
                    @Override
                    public void onSuccess(StatusResponse result)
                    {
                        // assume any response is good enough
                    }

                    @Override
                    public void onFailure(Throwable t)
                    {
                        if (t instanceof RejectedExecutionException) {
                            // client has been shutdown
                            return;
                        }

                        // reschedule
                        if (Duration.nanosSince(start).compareTo(new Duration(2, TimeUnit.MINUTES)) < 0) {
                            Futures.addCallback(httpClient.executeAsync(request, createStatusResponseHandler()), this, executor);
                        }
                        else {
                            log.error(t, "Unable to cancel task at %s", request.getUri());
                        }
                    }
                }, executor);
            }
        }
View Full Code Here

                    // this should never happen
                    log.error("Can not reschedule update because an update is already running");
                    return;
                }

                Request request = prepareGet()
                        .setUri(taskInfo.getSelf())
                        .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
                        .setHeader(PrestoHeaders.PRESTO_CURRENT_STATE, taskInfo.getState().toString())
                        .setHeader(PrestoHeaders.PRESTO_MAX_WAIT, "200ms")
                        .build();

                future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
                Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri()), executor);
            }
        }
View Full Code Here

        assertEquals(response.getBody(), expected);
    }

    private StringResponse executeQuery(String query)
    {
        Request request = preparePost()
                .setUri(server.resolve("/v1/execute"))
                .setHeader(PrestoHeaders.PRESTO_USER, "test")
                .setHeader(PrestoHeaders.PRESTO_CATALOG, Session.DEFAULT_CATALOG)
                .setHeader(PrestoHeaders.PRESTO_SCHEMA, Session.DEFAULT_SCHEMA)
                .setBodyGenerator(createStaticBodyGenerator(query, Charsets.UTF_8))
View Full Code Here

            });
        }

        public void execute(String query)
        {
            Request request = buildQueryRequest(session, query);
            StatusResponse response = httpClient.execute(request, createStatusResponseHandler());
            if (response.getStatusCode() != 200) {
                throw new RuntimeException("Query failed: [" + response.getStatusCode() + "] " + response.getStatusMessage());
            }
        }
View Full Code Here

        this.responseHandler = createFullJsonResponseHandler(queryResultsCodec);
        this.debug = session.isDebug();
        this.timeZoneId = session.getTimeZoneId();
        this.query = query;

        Request request = buildQueryRequest(session, query);
        currentResults.set(httpClient.execute(request, responseHandler).getValue());
    }
View Full Code Here

        if (isClosed() || (current().getNextUri() == null)) {
            valid.set(false);
            return false;
        }

        Request request = prepareGet()
                .setHeader(USER_AGENT, USER_AGENT_VALUE)
                .setUri(current().getNextUri())
                .build();

        Exception cause = null;
        long start = System.nanoTime();
        long attempts = 0;

        do {
            // back-off on retry
            if (attempts > 0) {
                sleepUninterruptibly(attempts * 100, MILLISECONDS);
            }
            attempts++;

            JsonResponse<QueryResults> response;
            try {
                response = httpClient.execute(request, responseHandler);
            }
            catch (RuntimeException e) {
                cause = e;
                continue;
            }

            if (response.getStatusCode() == HttpStatus.OK.code() && response.hasValue()) {
                currentResults.set(response.getValue());
                return true;
            }

            if (response.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE.code()) {
                gone.set(true);
                if (!response.hasValue()) {
                    throw new RuntimeException(format("Error fetching next at %s returned an invalid response", request.getUri()),
                            response.getException());
                }
                throw new RuntimeException(format("Error fetching next at %s returned %s: %s",
                        request.getUri(),
                        response.getStatusCode(),
                        response.getStatusMessage()));
            }
        }
        while ((System.nanoTime() - start) < MINUTES.toNanos(2) && !isClosed());
View Full Code Here

TOP

Related Classes of io.airlift.http.client.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.