@Override public void handleEvent(AjpClientRequestClientStreamSinkChannel channel) { if(currentRequest != null) { currentRequest.terminateRequest(); } } };
@Override public void handleEvent(AjpClientResponseStreamSourceChannel channel) { if(currentRequest != null) { currentRequest.terminateResponse(); } } };
@Override public void connect(final ClientCallback<ClientConnection> listener, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { connect(listener, null, uri, ioThread, ssl, bufferPool, options); }
getIoThread().execute(new Runnable() { @Override public void run() { AjpClientResponseStreamSourceChannel response = (AjpClientResponseStreamSourceChannel) result; response.setFinishListener(responseFinishedListener); ClientResponse cr = new ClientResponse(response.getStatusCode(), response.getReasonPhrase(), currentRequest.getRequest().getProtocol(), response.getHeaders()); if (response.getStatusCode() == 100) { currentRequest.setContinueResponse(cr); } else { currentRequest.setResponseChannel(response); currentRequest.setResponse(cr); safeClose(connection); if(currentRequest != null) { currentRequest.setFailed(e instanceof IOException ? (IOException) e : new IOException(e));
private void initiateRequest(AjpClientExchange AjpClientExchange) { currentRequest = AjpClientExchange; ClientRequest request = AjpClientExchange.getRequest(); currentRequest.setRequestChannel(sinkChannel); AjpClientExchange.invokeReadReadyCallback(AjpClientExchange); if (length == 0) { sinkChannel.shutdownWrites(); if (!sinkChannel.flush()) { handleFailedFlush(sinkChannel); handleError((t instanceof IOException) ? (IOException) t : new IOException(t));
void terminateRequest() { state |= REQUEST_TERMINATED; if(!clientConnection.isOpen()) { state |= RESPONSE_TERMINATED; } if (anyAreSet(state, RESPONSE_TERMINATED)) { clientConnection.requestDone(); } }
@Override public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) { if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) { clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState()); return; } final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this); if (currentRequest == null) { initiateRequest(AjpClientExchange); } else { pendingQueue.add(AjpClientExchange); } }
@Override public void handleEvent(AjpClientChannel channel) { log.debugf("connection to %s closed", getPeerAddress()); AjpClientConnection.this.state |= CLOSED; ChannelListeners.invokeChannelListener(AjpClientConnection.this, closeSetter.get()); for(ChannelListener<ClientConnection> listener : closeListeners) { listener.handleEvent(AjpClientConnection.this); } AjpClientExchange pending = pendingQueue.poll(); while (pending != null) { pending.setFailed(new ClosedChannelException()); pending = pendingQueue.poll(); } if(currentRequest != null) { currentRequest.setFailed(new ClosedChannelException()); currentRequest = null; } } });
private void handleConnected(StreamConnection connection, ClientCallback<ClientConnection> listener, URI uri, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { final ClientStatisticsImpl clientStatistics; //first we set up statistics, if required if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) { clientStatistics = new ClientStatisticsImpl(); connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.written += bytes; } })); connection.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(connection.getSourceChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.read += bytes; } })); } else { clientStatistics = null; } listener.completed(new AjpClientConnection(new AjpClientChannel(connection, bufferPool, options), options, bufferPool, clientStatistics)); }
@Override public void run() { if(currentRequest != null) { currentRequest.setFailed(new ClosedChannelException()); } } });
public void close() throws IOException { log.debugf("close called on connection to %s", getPeerAddress()); if (anyAreSet(state, CLOSED)) { return; } state |= CLOSED | CLOSE_REQ; connection.close(); }
/** * Notification that the current request is finished */ public void requestDone() { currentRequest = null; if (anyAreSet(state, CLOSE_REQ)) { safeClose(connection); } else if (anyAreSet(state, UPGRADE_REQUESTED)) { safeClose(connection); //we don't support upgrade, just close the connection to be safe return; } AjpClientExchange next = pendingQueue.poll(); if (next != null) { initiateRequest(next); } }
AjpClientConnection(final AjpClientChannel connection, final OptionMap options, final ByteBufferPool bufferPool, ClientStatistics clientStatistics) { this.clientStatistics = clientStatistics; this.options = options; this.connection = connection; this.bufferPool = bufferPool; connection.addCloseTask(new ChannelListener<AjpClientChannel>() { @Override public void handleEvent(AjpClientChannel channel) { log.debugf("connection to %s closed", getPeerAddress()); AjpClientConnection.this.state |= CLOSED; ChannelListeners.invokeChannelListener(AjpClientConnection.this, closeSetter.get()); for(ChannelListener<ClientConnection> listener : closeListeners) { listener.handleEvent(AjpClientConnection.this); } AjpClientExchange pending = pendingQueue.poll(); while (pending != null) { pending.setFailed(new ClosedChannelException()); pending = pendingQueue.poll(); } if(currentRequest != null) { currentRequest.setFailed(new ClosedChannelException()); currentRequest = null; } } }); connection.getReceiveSetter().set(new ClientReceiveListener()); connection.resumeReceives(); }
void terminateResponse() { state |= RESPONSE_TERMINATED; if(!clientConnection.isOpen()) { state |= REQUEST_TERMINATED; } if (anyAreSet(state, REQUEST_TERMINATED)) { clientConnection.requestDone(); } }
@Override public void handleEvent(AjpClientRequestClientStreamSinkChannel channel) { if(currentRequest != null) { currentRequest.terminateRequest(); } } };
@Override public void connect(final ClientCallback<ClientConnection> listener, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { connect(listener, null, uri, worker, ssl, bufferPool, options); }
@Override public void handleEvent(AjpClientResponseStreamSourceChannel channel) { if(currentRequest != null) { currentRequest.terminateResponse(); } } };
private void handleError(IOException exception) { currentRequest.setFailed(exception); safeClose(connection); }
@Override public void handleEvent(AjpClientRequestClientStreamSinkChannel channel) { if(currentRequest != null) { currentRequest.terminateRequest(); } } };
@Override public void connect(final ClientCallback<ClientConnection> listener, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { connect(listener, null, uri, worker, ssl, bufferPool, options); }