void sent() { long timeout = getTimeout(); timeoutAt = timeout > 0 ? System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeout) : -1; }
@Override public void onTimeoutExpired() { nextTimeout.set(Long.MAX_VALUE); long now = System.nanoTime(); long nextExpiresAt = Long.MAX_VALUE; // Check all queued exchanges for those that have expired // and to determine when the next check must be. for (HttpExchange exchange : exchanges) { HttpRequest request = exchange.getRequest(); long expiresAt = request.getTimeoutAt(); if (expiresAt == -1) continue; if (expiresAt <= now) request.abort(new TimeoutException("Total timeout " + request.getTimeout() + " ms elapsed")); else if (expiresAt < nextExpiresAt) nextExpiresAt = expiresAt; } if (nextExpiresAt < Long.MAX_VALUE && client.isRunning()) schedule(nextExpiresAt); }
@Override public void send(Response.CompleteListener listener) { if (getTimeout() > 0) { TimeoutCompleteListener timeoutListener = new TimeoutCompleteListener(this); timeoutListener.schedule(client.getScheduler()); responseListeners.add(timeoutListener); } send(this, listener); }
@Override public void send(Response.CompleteListener listener) { if (getTimeout() > 0) { TimeoutCompleteListener timeoutListener = new TimeoutCompleteListener(this); timeoutListener.schedule(client.getScheduler()); responseListeners.add(timeoutListener); } send(this, listener); }
@Override public ContentResponse send() throws InterruptedException, TimeoutException, ExecutionException { FutureResponseListener listener = new FutureResponseListener(this); send(this, listener); long timeout = getTimeout(); if (timeout <= 0) return listener.get(); try { return listener.get(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | TimeoutException x) { // Differently from the Future, the semantic of this method is that if // the send() is interrupted or times out, we abort the request. abort(x); throw x; } }
@Override public ContentResponse send() throws InterruptedException, TimeoutException, ExecutionException { FutureResponseListener listener = new FutureResponseListener(this); send(this, listener); long timeout = getTimeout(); if (timeout <= 0) return listener.get(); try { return listener.get(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | TimeoutException x) { // Differently from the Future, the semantic of this method is that if // the send() is interrupted or times out, we abort the request. abort(x); throw x; } }
.content(oldRequest.getContent()) .idleTimeout(oldRequest.getIdleTimeout(), TimeUnit.MILLISECONDS) .timeout(oldRequest.getTimeout(), TimeUnit.MILLISECONDS) .followRedirects(oldRequest.isFollowRedirects()); for (HttpField field : oldRequest.getHeaders())