@Override public RemotingOkHttpCall doClone() { return new RemotingOkHttpCall(getDelegate().clone(), backoffStrategy, urls, client, schedulingExecutor, executionExecutor, limiter, maxNumRelocations); } }
private static Response buildFrom(Response unbufferedResponse, byte[] bodyBytes) { return unbufferedResponse.newBuilder() .body(buffer(unbufferedResponse.body().contentType(), bodyBytes)) .build(); }
@Override public void onFailure(Call call, IOException exception) { urls.markAsFailed(request().url()); // Fail call if backoffs are exhausted or if no retry URL can be determined. Optional<Duration> backoff = backoffStrategy.nextBackoff(); if (!backoff.isPresent()) { callback.onFailure(call, new IOException("Failed to complete the request due to an " + "IOException", exception)); return; } Optional<HttpUrl> redirectTo = urls.redirectToNext(request().url()); if (!redirectTo.isPresent()) { callback.onFailure(call, new IOException("Failed to determine valid failover URL for '" + request().url() + "' and base URLs " + urls.getBaseUrls())); return; } Request redirectedRequest = request().newBuilder() .url(redirectTo.get()) .build(); RemotingOkHttpCall retryCall = client.newCallWithMutableState(redirectedRequest, backoffStrategy, maxNumRelocations - 1); log.debug("Rescheduling call after backoff", SafeArg.of("backoffMillis", backoff.get().toMillis()), exception); scheduleExecution(() -> retryCall.enqueue(callback), backoff.get()); }
public Response execute() throws IOException { SettableFuture<Response> future = SettableFuture.create(); enqueue(new Callback() { @Override public void onFailure(Call call, IOException exception) { getDelegate().cancel(); Thread.currentThread().interrupt(); throw new InterruptedIOException("Call was interrupted during execution"); } catch (ExecutionException e) { getDelegate().cancel(); if (e.getCause() instanceof IoRemoteException) {
RemotingOkHttpCall newCallWithMutableState( Request request, BackoffStrategy backoffStrategy, int maxNumRelocations) { return new RemotingOkHttpCall( getDelegate().newCall(request), backoffStrategy, urls, this, schedulingExecutor, executionExecutor, concurrencyLimiters.acquireLimiter(request), maxNumRelocations); }
@Override public void enqueue(Callback callback) { ListenableFuture<Limiter.Listener> limiterListener = limiter.acquire(); request().tag(ConcurrencyLimiterListener.class).limiterListener().setFuture(limiterListener); Futures.addCallback(limiterListener, new FutureCallback<Limiter.Listener>() { @Override public void onSuccess(Limiter.Listener listener) { enqueueInternal(callback); } @Override public void onFailure(Throwable throwable) { callback.onFailure( RemotingOkHttpCall.this, new IOException(new AssertionError("This should never happen, since it implies " + "we failed when using the concurrency limiter", throwable))); } }, MoreExecutors.directExecutor()); }
@Override public void onFailure(Call call, IOException exception) { urls.markAsFailed(request().url()); // Fail call if backoffs are exhausted or if no retry URL can be determined. Optional<Duration> backoff = backoffStrategy.nextBackoff(); if (!backoff.isPresent()) { callback.onFailure(call, new IOException("Failed to complete the request due to an " + "IOException", exception)); return; } Optional<HttpUrl> redirectTo = urls.redirectToNext(request().url()); if (!redirectTo.isPresent()) { callback.onFailure(call, new IOException("Failed to determine valid failover URL for '" + request().url() + "' and base URLs " + urls.getBaseUrls())); return; } Request redirectedRequest = request().newBuilder() .url(redirectTo.get()) .build(); RemotingOkHttpCall retryCall = client.newCallWithMutableState(redirectedRequest, backoffStrategy, maxNumRelocations - 1); log.debug("Rescheduling call after backoff", SafeArg.of("backoffMillis", backoff.get().toMillis()), exception); scheduleExecution(() -> retryCall.enqueue(callback), backoff.get()); }
public Response execute() throws IOException { SettableFuture<Response> future = SettableFuture.create(); enqueue(new Callback() { @Override public void onFailure(Call call, IOException exception) { getDelegate().cancel(); Thread.currentThread().interrupt(); throw new InterruptedIOException("Call was interrupted during execution"); } catch (ExecutionException e) { getDelegate().cancel(); if (e.getCause() instanceof IoRemoteException) {
RemotingOkHttpCall newCallWithMutableState( Request request, BackoffStrategy backoffStrategy, int maxNumRelocations) { return new RemotingOkHttpCall( getDelegate().newCall(request), backoffStrategy, urls, this, schedulingExecutor, executionExecutor, concurrencyLimiters.acquireLimiter(request), maxNumRelocations); }
@Override public void enqueue(Callback callback) { ListenableFuture<Limiter.Listener> limiterListener = limiter.acquire(); request().tag(ConcurrencyLimiterListener.class).limiterListener().setFuture(limiterListener); Futures.addCallback(limiterListener, new FutureCallback<Limiter.Listener>() { @Override public void onSuccess(Limiter.Listener listener) { enqueueInternal(callback); } @Override public void onFailure(Throwable throwable) { callback.onFailure( RemotingOkHttpCall.this, new IOException(new AssertionError("This should never happen, since it implies " + "we failed when using the concurrency limiter", throwable))); } }, MoreExecutors.directExecutor()); }
@Override public RemotingOkHttpCall doClone() { return new RemotingOkHttpCall(getDelegate().clone(), backoffStrategy, urls, client, schedulingExecutor, executionExecutor, limiter, maxNumRelocations); } }
private static Response buildFrom(Response unbufferedResponse, byte[] bodyBytes) { return unbufferedResponse.newBuilder() .body(buffer(unbufferedResponse.body().contentType(), bodyBytes)) .build(); }