/** * @param request HTTP request to execute. * @param client The client used to execute the request. * @param responseClass Model class to unmarshal JSON body content. * @param fieldNamingPolicy FieldNamingPolicy for unmarshaling JSON. * @param errorTimeOut Number of milliseconds to re-send erroring requests. * @param maxRetries Number of times allowed to re-send erroring requests. */ public GaePendingResult( HTTPRequest request, URLFetchService client, Class<R> responseClass, FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry) { this.request = request; this.client = client; this.responseClass = responseClass; this.fieldNamingPolicy = fieldNamingPolicy; this.errorTimeOut = errorTimeOut; this.maxRetries = maxRetries; this.exceptionsAllowedToRetry = exceptionsAllowedToRetry; this.call = client.fetchAsync(request); }
private T retry() throws IOException, ApiException, InterruptedException { retryCounter++; LOG.info("Retrying request. Retry #{}", retryCounter); this.call = client.fetchAsync(request); return this.await(); }
/** * @param request HTTP request to execute. * @param client The client used to execute the request. * @param responseClass Model class to unmarshal JSON body content. * @param fieldNamingPolicy FieldNamingPolicy for unmarshaling JSON. * @param errorTimeOut Number of milliseconds to re-send erroring requests. * @param maxRetries Number of times allowed to re-send erroring requests. */ public GaePendingResult( HTTPRequest request, URLFetchService client, Class<R> responseClass, FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry) { this.request = request; this.client = client; this.responseClass = responseClass; this.fieldNamingPolicy = fieldNamingPolicy; this.errorTimeOut = errorTimeOut; this.maxRetries = maxRetries; this.exceptionsAllowedToRetry = exceptionsAllowedToRetry; this.call = client.fetchAsync(request); }
private T retry() throws IOException, ApiException, InterruptedException { retryCounter++; LOG.info("Retrying request. Retry #{}", retryCounter); this.call = client.fetchAsync(request); return this.await(); }
@Override public ListenableFuture<HttpResponse> submit(final HttpCommand command) { HTTPRequest nativeRequest = filterLogAndConvertRe(command.getCurrentRequest()); ListenableFuture<HttpResponse> response = transform( listenInPoolThread(urlFetchService.fetchAsync(nativeRequest)), convertToJcloudsResponse); return transform(response, new Function<HttpResponse, HttpResponse>() { public HttpResponse apply(HttpResponse response) { return receiveResponse(command, response); } }, ioExecutor); }
@Override public Future<HTTPResponse> fetchAsync(HTTPRequest req) { HTTPRequest authorizedRequest; try { authorizedRequest = createAuthorizeRequest(req); } catch (RetryHelperException e) { return Futures.immediateFailedCheckedFuture(e); } return urlFetch.fetchAsync(authorizedRequest); } }
protected HttpResponseImpl fetch(HTTPRequest request, HTTPMethod headGetDelete) { try { Future<HTTPResponse> fetchAsync = fetchService.fetchAsync(request); return new HttpResponseImpl(fetchAsync, this, request.getURL()); } catch (Exception e) { throw new HttpRequestException(e, "Failed to create a %s request: %s", headGetDelete, e.getMessage()); } }
@Test public void testAsyncOps() throws Exception { URLFetchService service = URLFetchServiceFactory.getURLFetchService(); URL adminConsole = findAvailableUrl(URLS); Future<HTTPResponse> response = service.fetchAsync(adminConsole); printResponse(response.get(5, TimeUnit.SECONDS)); response = service.fetchAsync(new HTTPRequest(adminConsole)); printResponse(response.get(5, TimeUnit.SECONDS)); URL jbossOrg = new URL("http://www.jboss.org"); if (available(jbossOrg)) { response = service.fetchAsync(jbossOrg); printResponse(response.get(30, TimeUnit.SECONDS)); } sync(5000L); // wait a bit for async to finish }