public ResponseFuture sendRequest()

in client/src/main/java/org/apache/ahc/AsyncHttpClient.java [460:509]


    public ResponseFuture sendRequest(HttpRequestMessage message, 
            BlockingQueue<ResponseFuture> queue) {
        if (destroyed) {
            throw new IllegalStateException("AsyncHttpClient has been destroyed and cannot be reused.");
        }
        
        // set the request start time
        message.setRequestStartTime();
        // notify any interesting parties that this is starting 
        notifyMonitoringListeners(MonitoringEvent.REQUEST_STARTED, message); 
        
        // we need to provide a new result future and associate it with the
        // request unless it already exists (i.e. sendRequest() is called
        // multiple times for the request)
        if (message.getResponseFuture() == null) {
            message.setResponseFuture(new ResponseFuture(message, queue));
        }
        
        // *IF* connection reuse is enabled, we should see if we have a pooled 
        // connection first; if not, always open a new one
        ConnectFuture future = null;
        if (!message.isProxyEnabled()) {
        	ConnectionPool connectionPool = getConnectionPool(); 
        	if (connectionPool != null) {
        		future = getPooledConnection(message);
        	} else {
        		// add the Connection close header explicitly
        		message.setHeader(HttpDecoder.CONNECTION, HttpDecoder.CLOSE);
        	}
        }
        
        // if no pooled connection is found or keep-alive is disabled, force a
        // new connection
        if (future == null) {
            // set the connect start time
            message.setConnectStartTime();
            // NB:  We broadcast this here rather than in open connection to avoid 
            // having a connection retry result in both a CONNECTION_ATTEMPTED and 
            // CONNECTION_RETRIED event getting dispatched. 
            notifyMonitoringListeners(MonitoringEvent.CONNECTION_ATTEMPTED, message); 
            future = openConnection(message);
        }
        ResponseFuture response = message.getResponseFuture();
        FutureListener listener = 
                message.isProxyEnabled() ? 
                        new ProxyFutureListener(message, response) :
                        new FutureListener(message, response);
        future.addListener(listener);
        return response;
    }