@Override public void messageComplete(long contextLength) throws IOException { HttpExchange exchange = _exchange; if (exchange!=null) exchange.setStatus(HttpExchange.STATUS_COMPLETED); }
public void reset() { // TODO - this should do a cancel and wakeup everybody that was waiting. // might need a version number concept synchronized (this) { _timeoutTask = null; _onRequestCompleteDone = false; _onResponseCompleteDone = false; _onDone = false; setStatus(STATUS_START); } }
/** * Initiates the cancelling of this exchange. The status of the exchange is set to {@link #STATUS_CANCELLING}. Cancelling the exchange is an asynchronous * operation with respect to the request/response, and as such checking the request/response status of a cancelled exchange may return undefined results * (for example it may have only some of the response headers being sent by the server). The cancelling of the exchange is completed when the exchange * status (see {@link #getStatus()}) is {@link #STATUS_CANCELLED}, and this can be waited using {@link #waitForDone()}. */ public void cancel() { setStatus(STATUS_CANCELLING); abort(); }
AbstractHttpConnection disassociate() { AbstractHttpConnection result = _connection; this._connection = null; if (getStatus() == STATUS_CANCELLING) setStatus(STATUS_CANCELLED); return result; }
@Override protected void onException(Throwable x) { HttpExchange exchange = null; synchronized (HttpDestination.this) { if (!_exchanges.isEmpty()) exchange = _exchanges.remove(0); } if (exchange != null && exchange.setStatus(STATUS_EXCEPTED)) exchange.getEventListener().onException(x); }
public void onException(Throwable throwable) { synchronized (this) { _pendingConnections--; if (_exchanges.size() > 0) { HttpExchange ex = _exchanges.remove(0); if (ex.setStatus(HttpExchange.STATUS_EXCEPTED)) ex.getEventListener().onException(throwable); } } }
@Override protected void onExpire() { HttpExchange exchange = null; synchronized (HttpDestination.this) { if (!_exchanges.isEmpty()) exchange = _exchanges.remove(0); } if (exchange != null && exchange.setStatus(STATUS_EXPIRED)) exchange.getEventListener().onExpire(); } }
@Override public void headerComplete() throws IOException { HttpExchange exchange = _exchange; if (exchange!=null) { exchange.setStatus(HttpExchange.STATUS_PARSING_CONTENT); if (HttpMethods.CONNECT.equalsIgnoreCase(exchange.getMethod())) _parser.setPersistent(true); } }
public void onResponseComplete() throws IOException { _exchange.setEventListener(_next); _exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_RESPONSE); _parser.reset(); }
protected void expire(HttpDestination destination) { AbstractHttpConnection connection = _connection; int status = getStatus(); if (status < STATUS_COMPLETED || status == STATUS_SENDING_PARSING_HEADERS || status == STATUS_SENDING_PARSING_CONTENT || status == STATUS_SENDING_COMPLETED) setStatus(STATUS_EXPIRED); destination.exchangeExpired(this); if (connection != null) connection.exchangeExpired(this); }
if (ex.setStatus(HttpExchange.STATUS_EXCEPTED)) ex.getEventListener().onConnectionFailed(throwable);
@Override public void earlyEOF() { HttpExchange exchange = _exchange; if (exchange!=null) { if (!exchange.isDone()) { if (exchange.setStatus(HttpExchange.STATUS_EXCEPTED)) exchange.getEventListener().onException(new EofException("early EOF")); } } } }
public void send(HttpExchange ex) throws IOException ex.setStatus(HttpExchange.STATUS_WAITING_FOR_CONNECTION);
public boolean send(HttpExchange ex) throws IOException { LOG.debug("Send {} on {}",ex,this); synchronized (this) { if (_exchange != null) { if (_pipeline != null) throw new IllegalStateException(this + " PIPELINED!!! _exchange=" + _exchange); _pipeline = ex; return true; } _exchange = ex; _exchange.associate(this); // The call to associate() may have closed the connection, check if it's the case if (!_endp.isOpen()) { _exchange.disassociate(); _exchange = null; return false; } _exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_COMMIT); adjustIdleTimeout(); return true; } }
@Override public void startResponse(Buffer version, int status, Buffer reason) throws IOException { HttpExchange exchange = _exchange; if (exchange==null) { LOG.warn("No exchange for response"); _endp.close(); return; } switch(status) { case HttpStatus.CONTINUE_100: case HttpStatus.PROCESSING_102: // TODO check if appropriate expect was sent in the request. exchange.setEventListener(new NonFinalResponseListener(exchange)); break; case HttpStatus.OK_200: // handle special case for CONNECT 200 responses if (HttpMethods.CONNECT.equalsIgnoreCase(exchange.getMethod())) _parser.setHeadResponse(true); break; } _http11 = HttpVersions.HTTP_1_1_BUFFER.equals(version); _status=status; exchange.getEventListener().onResponseStatus(version,status,reason); exchange.setStatus(HttpExchange.STATUS_PARSING_HEADERS); }
throw new IllegalStateException(); _exchange.setStatus(HttpExchange.STATUS_SENDING_REQUEST); _generator.setVersion(_exchange.getVersion()); _generator.completeHeader(requestHeaders,false); _generator.addContent(new View(requestContent),true); _exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_RESPONSE); _exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_RESPONSE);
String exch= exchange.toString(); String reason = _endp.isOpen()?(_endp.isInputShutdown()?"half closed: ":"local close: "):"closed: "; if (exchange.setStatus(HttpExchange.STATUS_EXCEPTED)) exchange.getEventListener().onException(new EofException(reason+exch));
_generator.complete(); if (exchange.getStatus() < HttpExchange.STATUS_WAITING_FOR_RESPONSE) exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_RESPONSE); _generator.addContent(chunk,_requestContentChunk==null); if (_requestContentChunk==null) exchange.setStatus(HttpExchange.STATUS_WAITING_FOR_RESPONSE); !exchange.isDone()) if (exchange.setStatus(HttpExchange.STATUS_EXCEPTED)) exchange.getEventListener().onException(e);