void disassociate(HttpChannel channel) { boolean abort = false; synchronized (this) { if (_channel != channel || requestState != State.TERMINATED || responseState != State.TERMINATED) abort = true; _channel = null; } if (abort) request.abort(new IllegalStateException(toString())); }
/** * <p>Associates the given {@code channel} to this exchange.</p> * <p>Works in strict collaboration with {@link HttpChannel#associate(HttpExchange)}.</p> * * @param channel the channel to associate to this exchange * @return true if the channel could be associated, false otherwise */ boolean associate(HttpChannel channel) { boolean result = false; boolean abort = false; synchronized (this) { // Only associate if the exchange state is initial, // as the exchange could be already failed. if (requestState == State.PENDING && responseState == State.PENDING) { abort = _channel != null; if (!abort) { _channel = channel; result = true; } } } if (abort) request.abort(new IllegalStateException(toString())); return result; }
/** * Aborts all the {@link HttpExchange}s queued in this destination. * * @param cause the abort cause */ public void abort(Throwable cause) { // Copy the queue of exchanges and fail only those that are queued at this moment. // The application may queue another request from the failure/complete listener // and we don't want to fail it immediately as if it was queued before the failure. // The call to Request.abort() will remove the exchange from the exchanges queue. for (HttpExchange exchange : new ArrayList<>(exchanges)) exchange.getRequest().abort(cause); if (exchanges.isEmpty()) tryRemoveIdleDestination(); }
protected boolean abort(Throwable failure) { HttpExchange exchange = channel.getHttpExchange(); return exchange != null && exchange.getRequest().abort(failure); }
@Override public void onReset(Stream stream, ResetFrame frame) { HttpExchange exchange = getHttpExchange(); if (exchange == null) return; int error = frame.getError(); exchange.getRequest().abort(new IOException(ErrorCode.toString(error, "reset_code_" + error))); }
private void abort(Throwable failure) { for (HttpChannel channel : activeChannels) { HttpExchange exchange = channel.getHttpExchange(); if (exchange != null) exchange.getRequest().abort(failure); } activeChannels.clear(); HttpChannel channel = idleChannels.poll(); while (channel!=null) { channel.destroy(); channel = idleChannels.poll(); } }
@Override public void send(Request request, Response.CompleteListener listener) { HttpRequest httpRequest = (HttpRequest)request; ArrayList<Response.ResponseListener> listeners = new ArrayList<>(httpRequest.getResponseListeners()); httpRequest.sent(); if (listener != null) listeners.add(listener); HttpExchange exchange = new HttpExchange(getHttpDestination(), httpRequest, listeners); SendFailure result = send(exchange); if (result != null) httpRequest.abort(result.failure); }
@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); }
request.abort(new RejectedExecutionException(client + " is stopping")); request.abort(new RejectedExecutionException("Max requests queued per destination " + client.getMaxRequestsQueuedPerDestination() + " exceeded for " + this)); request.abort(new RejectedExecutionException(client + " is stopped"));
exchange.getRequest().abort(new UnsupportedOperationException("Pipelined requests not supported"));
@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; } }
stats.recordRequestFailed(); requestLogger.log(requestInfo, ResponseInfo.failed(Optional.empty(), Optional.of(e))); jettyRequest.abort(e); Thread.currentThread().interrupt(); return responseHandler.handleException(request, e); stats.recordRequestFailed(); requestLogger.log(requestInfo, ResponseInfo.failed(Optional.empty(), Optional.of(e))); jettyRequest.abort(e); return responseHandler.handleException(request, e);