Example usage for org.apache.http.nio.protocol HttpAsyncRequestExecutor HTTP_HANDLER

List of usage examples for org.apache.http.nio.protocol HttpAsyncRequestExecutor HTTP_HANDLER

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol HttpAsyncRequestExecutor HTTP_HANDLER.

Prototype

String HTTP_HANDLER

To view the source code for org.apache.http.nio.protocol HttpAsyncRequestExecutor HTTP_HANDLER.

Click Source Link

Usage

From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java

final void releaseConnection() {
    final NHttpClientConnection localConn = this.managedConnRef.getAndSet(null);
    if (localConn != null) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("[exchange: " + this.id + "] releasing connection");
        }//from w w w .  j  a v a2s . c o m
        localConn.getContext().removeAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER);
        final Long validDuration = this.validDurationRef.get();
        if (validDuration != null) {
            final Object userToken = this.localContext.getUserToken();
            this.connmgr.releaseConnection(localConn, userToken, validDuration, TimeUnit.MILLISECONDS);
        } else {
            try {
                localConn.close();
                if (this.log.isDebugEnabled()) {
                    this.log.debug("[exchange: " + this.id + "] connection discarded");
                }
            } catch (final IOException ex) {
                if (this.log.isDebugEnabled()) {
                    this.log.debug(ex.getMessage(), ex);
                }
            } finally {
                this.connmgr.releaseConnection(localConn, null, 0, TimeUnit.MILLISECONDS);
            }
        }
    }
}

From source file:org.apache.http.impl.nio.client.AbstractClientExchangeHandler.java

private void connectionAllocated(final NHttpClientConnection managedConn) {
    try {/*from w ww.  j a  v a  2 s.  c  om*/
        if (this.log.isDebugEnabled()) {
            this.log.debug("[exchange: " + this.id + "] Connection allocated: " + managedConn);
        }
        this.managedConnRef.set(managedConn);

        if (this.closed.get()) {
            discardConnection();
            return;
        }

        managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this);
        managedConn.requestOutput();
        if (managedConn.isStale()) {
            failed(new ConnectionClosedException("Connection closed"));
        }
    } catch (final RuntimeException runex) {
        failed(runex);
        throw runex;
    }
}

From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java

private void releaseConnection() {
    if (this.managedConn != null) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("[exchange: " + this.id + "] releasing connection " + this.managedConn);
        }//from  w w w  .j  ava2  s .  co m
        try {
            this.managedConn.getContext().removeAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER);
            this.managedConn.releaseConnection();
        } catch (final IOException ioex) {
            this.log.debug("I/O error releasing connection", ioex);
        }
        this.managedConn = null;
    }
}

From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java

private synchronized void connectionRequestCompleted(final ManagedClientAsyncConnection conn) {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + this.id + "] Connection allocated: " + conn);
    }/*from  w  w  w . j a  va 2  s.  c o m*/
    this.connRequestCallback = null;
    try {
        this.managedConn = conn;
        if (this.closed) {
            conn.releaseConnection();
            return;
        }
        final HttpRoute route = this.mainRequest.getRoute();
        if (!conn.isOpen()) {
            conn.open(route, this.localContext, this.params);
        }
        conn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this);
        conn.requestOutput();
        this.routeEstablished = route.equals(conn.getRoute());
        if (!conn.isOpen()) {
            throw new ConnectionClosedException("Connection closed");
        }
    } catch (final IOException ex) {
        failed(ex);
    } catch (final RuntimeException runex) {
        failed(runex);
        throw runex;
    }
}