Java 类org.apache.http.conn.ManagedClientConnection 实例源码

项目:lams    文件:DefaultRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a <code>catch</code> block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
    ManagedClientConnection mcc = managedConn;
    if (mcc != null) {
        // we got here as the result of an exception
        // no response will be returned, release the connection
        managedConn = null;
        try {
            mcc.abortConnection();
        } catch (IOException ex) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(ex.getMessage(), ex);
            }
        }
        // ensure the connection manager properly releases this connection
        try {
            mcc.releaseConnection();
        } catch(IOException ignored) {
            this.log.debug("Error releasing connection", ignored);
        }
    }
}
项目:lams    文件:BasicClientConnectionManager.java   
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) {
            return BasicClientConnectionManager.this.getConnection(
                    route, state);
        }

    };
}
项目:lams    文件:SingleClientConnManager.java   
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) {
            return SingleClientConnManager.this.getConnection(
                    route, state);
        }

    };
}
项目:lams    文件:PoolingClientConnectionManager.java   
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    if (route == null) {
        throw new IllegalArgumentException("HTTP route may not be null");
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<HttpPoolEntry> future = this.pool.lease(route, state);

    return new ClientConnectionRequest() {

        public void abortRequest() {
            future.cancel(true);
        }

        public ManagedClientConnection getConnection(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
项目:cloud-meter    文件:JMeterPoolingClientConnectionManager.java   
@Override
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "HTTP route");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<HttpPoolEntry> future = this.pool.lease(route, state);

    return new ClientConnectionRequest() {
        @Override
        public void abortRequest() {
            future.cancel(true);
        }
        @Override
        public ManagedClientConnection getConnection(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
项目:purecloud-iot    文件:DefaultRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a {@code catch} block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
    final ManagedClientConnection mcc = managedConn;
    if (mcc != null) {
        // we got here as the result of an exception
        // no response will be returned, release the connection
        managedConn = null;
        try {
            mcc.abortConnection();
        } catch (final IOException ex) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(ex.getMessage(), ex);
            }
        }
        // ensure the connection manager properly releases this connection
        try {
            mcc.releaseConnection();
        } catch(final IOException ignored) {
            this.log.debug("Error releasing connection", ignored);
        }
    }
}
项目:purecloud-iot    文件:BasicClientConnectionManager.java   
@Override
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        @Override
        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        @Override
        public ManagedClientConnection getConnection(
                final long timeout, final TimeUnit tunit) {
            return BasicClientConnectionManager.this.getConnection(
                    route, state);
        }

    };
}
项目:purecloud-iot    文件:BasicClientConnectionManager.java   
ManagedClientConnection getConnection(final HttpRoute route, final Object state) {
    Args.notNull(route, "Route");
    synchronized (this) {
        assertNotShutdown();
        if (this.log.isDebugEnabled()) {
            this.log.debug("Get connection for route " + route);
        }
        Asserts.check(this.conn == null, MISUSE_MESSAGE);
        if (this.poolEntry != null && !this.poolEntry.getPlannedRoute().equals(route)) {
            this.poolEntry.close();
            this.poolEntry = null;
        }
        if (this.poolEntry == null) {
            final String id = Long.toString(COUNTER.getAndIncrement());
            final OperatedClientConnection opconn = this.connOperator.createConnection();
            this.poolEntry = new HttpPoolEntry(this.log, id, route, opconn, 0, TimeUnit.MILLISECONDS);
        }
        final long now = System.currentTimeMillis();
        if (this.poolEntry.isExpired(now)) {
            this.poolEntry.close();
            this.poolEntry.getTracker().reset();
        }
        this.conn = new ManagedClientConnectionImpl(this, this.connOperator, this.poolEntry);
        return this.conn;
    }
}
项目:purecloud-iot    文件:SingleClientConnManager.java   
@Override
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        @Override
        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        @Override
        public ManagedClientConnection getConnection(
                final long timeout, final TimeUnit tunit) {
            return SingleClientConnManager.this.getConnection(
                    route, state);
        }

    };
}
项目:FMTech    文件:ElegantThreadSafeConnManager.java   
public final ClientConnectionRequest requestConnection(final HttpRoute paramHttpRoute, Object paramObject)
{
  new ClientConnectionRequest()
  {
    public final void abortRequest()
    {
      this.val$poolRequest.abortRequest();
    }

    public final ManagedClientConnection getConnection(long paramAnonymousLong, TimeUnit paramAnonymousTimeUnit)
      throws InterruptedException, ConnectionPoolTimeoutException
    {
      if (paramHttpRoute == null) {
        throw new IllegalArgumentException("Route may not be null.");
      }
      BasicPoolEntry localBasicPoolEntry = this.val$poolRequest.getPoolEntry(paramAnonymousLong, paramAnonymousTimeUnit);
      return new ElegantThreadSafeConnManager.ElegantBasicPooledConnAdapter(ElegantThreadSafeConnManager.this, localBasicPoolEntry);
    }
  };
}
项目:FMTech    文件:jsj.java   
public final void releaseConnection(ManagedClientConnection paramManagedClientConnection, long paramLong, TimeUnit paramTimeUnit)
{
  HttpConnectionMetrics localHttpConnectionMetrics = paramManagedClientConnection.getMetrics();
  if (localHttpConnectionMetrics != null)
  {
    long l1 = localHttpConnectionMetrics.getReceivedBytesCount();
    ArrayList localArrayList1 = (ArrayList)jsm.b.get();
    int i = localArrayList1.size();
    if (i > 0)
    {
      jso localjso2 = (jso)localArrayList1.get(i - 1);
      localjso2.d = (l1 + localjso2.d);
    }
    long l2 = localHttpConnectionMetrics.getSentBytesCount();
    ArrayList localArrayList2 = (ArrayList)jsm.b.get();
    int j = localArrayList2.size();
    if (j > 0)
    {
      jso localjso1 = (jso)localArrayList2.get(j - 1);
      localjso1.e = (l2 + localjso1.e);
    }
  }
  super.releaseConnection(paramManagedClientConnection, paramLong, paramTimeUnit);
}
项目:FullRobolectricTestSample    文件:DefaultRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a <code>catch</code> block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
  ManagedClientConnection mcc = managedConn;
  if (mcc != null) {
    // we got here as the result of an exception
    // no response will be returned, release the connection
    managedConn = null;
    try {
      mcc.abortConnection();
    } catch (IOException ex) {
      if (this.log.isDebugEnabled()) {
        this.log.debug(ex.getMessage(), ex);
      }
    }
    // ensure the connection manager properly releases this connection
    try {
      mcc.releaseConnection();
    } catch(IOException ignored) {
      this.log.debug("Error releasing connection", ignored);
    }
  }
}
项目:cJUnit-mc626    文件:DefaultRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a <code>catch</code> block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
    ManagedClientConnection mcc = managedConn;
    if (mcc != null) {
        // we got here as the result of an exception
        // no response will be returned, release the connection
        managedConn = null;
        try {
            mcc.abortConnection();
        } catch (IOException ex) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(ex.getMessage(), ex);
            }
        }
        // ensure the connection manager properly releases this connection
        try {
            mcc.releaseConnection();
        } catch(IOException ignored) {
            this.log.debug("Error releasing connection", ignored);
        }
    }
}
项目:cJUnit-mc626    文件:SingleClientConnManager.java   
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) {
            return SingleClientConnManager.this.getConnection(
                    route, state);
        }

    };
}
项目:YiBo    文件:LibRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a <code>catch</code> block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
    ManagedClientConnection mcc = managedConn;
    if (mcc != null) {
        // we got here as the result of an exception
        // no response will be returned, release the connection
        managedConn = null;
        try {
            mcc.abortConnection();
        } catch (IOException ex) {
            if (DEBUG) {
                Logger.debug(ex.getMessage(), ex);
            }
        }
        // ensure the connection manager properly releases this connection
        try {
            mcc.releaseConnection();
        } catch (IOException ignored) {
            if (DEBUG) {
                Logger.debug("Error releasing connection", ignored);
            }
        }
    }
}
项目:yibo-library    文件:YiBoRequestDirector.java   
/**
 * Shuts down the connection.
 * This method is called from a <code>catch</code> block in
 * {@link #execute execute} during exception handling.
 */
private void abortConnection() {
    ManagedClientConnection mcc = managedConn;
    if (mcc != null) {
        // we got here as the result of an exception
        // no response will be returned, release the connection
        managedConn = null;
        try {
            mcc.abortConnection();
        } catch (IOException ex) {
            if (Constants.DEBUG) {
                logger.debug(ex.getMessage(), ex);
            }
        }
        // ensure the connection manager properly releases this connection
        try {
            mcc.releaseConnection();
        } catch (IOException ignored) {
            if (Constants.DEBUG) {
                logger.debug("Error releasing connection", ignored);
            }
        }
    }
}
项目:lams    文件:ThreadSafeClientConnManager.java   
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    final PoolEntryRequest poolRequest = pool.requestPoolEntry(
            route, state);

    return new ClientConnectionRequest() {

        public void abortRequest() {
            poolRequest.abortRequest();
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) throws InterruptedException,
                ConnectionPoolTimeoutException {
            if (route == null) {
                throw new IllegalArgumentException("Route may not be null.");
            }

            if (log.isDebugEnabled()) {
                log.debug("Get connection: " + route + ", timeout = " + timeout);
            }

            BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
            return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
        }

    };

}
项目:remote-files-sync    文件:MinimalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:remote-files-sync    文件:InternalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:purecloud-iot    文件:PoolingClientConnectionManager.java   
@Override
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "HTTP route");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<HttpPoolEntry> future = this.pool.lease(route, state);

    return new ClientConnectionRequest() {

        @Override
        public void abortRequest() {
            future.cancel(true);
        }

        @Override
        public ManagedClientConnection getConnection(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
项目:purecloud-iot    文件:ThreadSafeClientConnManager.java   
@Override
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    final PoolEntryRequest poolRequest = pool.requestPoolEntry(
            route, state);

    return new ClientConnectionRequest() {

        @Override
        public void abortRequest() {
            poolRequest.abortRequest();
        }

        @Override
        public ManagedClientConnection getConnection(
                final long timeout, final TimeUnit tunit) throws InterruptedException,
                ConnectionPoolTimeoutException {
            Args.notNull(route, "Route");

            if (log.isDebugEnabled()) {
                log.debug("Get connection: " + route + ", timeout = " + timeout);
            }

            final BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
            return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
        }

    };

}
项目:FMTech    文件:ElegantThreadSafeConnManager.java   
public final void releaseConnection(ManagedClientConnection paramManagedClientConnection, long paramLong, TimeUnit paramTimeUnit)
{
  long l1;
  long l2;
  if (((paramManagedClientConnection instanceof ElegantBasicPooledConnAdapter)) && (paramManagedClientConnection.getRoute() != null))
  {
    ElegantBasicPooledConnAdapter localElegantBasicPooledConnAdapter = (ElegantBasicPooledConnAdapter)paramManagedClientConnection;
    l1 = System.currentTimeMillis() - localElegantBasicPooledConnAdapter.startTime;
    if (!paramManagedClientConnection.getRoute().isSecure()) {
      break label73;
    }
    l2 = 5000L;
  }
  for (;;)
  {
    if (l1 > l2) {}
    try
    {
      paramManagedClientConnection.close();
      label64:
      super.releaseConnection(paramManagedClientConnection, paramLong, paramTimeUnit);
      return;
      label73:
      l2 = 2500L;
    }
    catch (IOException localIOException)
    {
      break label64;
    }
  }
}
项目:FMTech    文件:jsk.java   
public final ManagedClientConnection getConnection(long paramLong, TimeUnit paramTimeUnit)
{
  ManagedClientConnection localManagedClientConnection = this.a.getConnection(paramLong, paramTimeUnit);
  HttpConnectionMetrics localHttpConnectionMetrics = localManagedClientConnection.getMetrics();
  if (localHttpConnectionMetrics != null) {
    localHttpConnectionMetrics.reset();
  }
  return localManagedClientConnection;
}
项目:Visit    文件:MinimalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:Visit    文件:InternalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:cJUnit-mc626    文件:RequestClientConnControl.java   
public void process(final HttpRequest request, final HttpContext context) 
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    // Obtain the client connection (required)
    ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        throw new IllegalStateException("Client connection not specified in HTTP context");
    }

    HttpRoute route = conn.getRoute();

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
项目:cJUnit-mc626    文件:DefaultUserTokenHandler.java   
public Object getUserToken(final HttpContext context) {

    Principal userPrincipal = null;

    AuthState targetAuthState = (AuthState) context.getAttribute(
            ClientContext.TARGET_AUTH_STATE);
    if (targetAuthState != null) {
        userPrincipal = getAuthPrincipal(targetAuthState);
        if (userPrincipal == null) {
            AuthState proxyAuthState = (AuthState) context.getAttribute(
                    ClientContext.PROXY_AUTH_STATE);
            userPrincipal = getAuthPrincipal(proxyAuthState);
        }
    }

    if (userPrincipal == null) {
        ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
                ExecutionContext.HTTP_CONNECTION);
        if (conn.isOpen()) {
            SSLSession sslsession = conn.getSSLSession();
            if (sslsession != null) {
                userPrincipal = sslsession.getLocalPrincipal();
            }
        }
    }

    return userPrincipal;
}
项目:cJUnit-mc626    文件:ThreadSafeClientConnManager.java   
public ClientConnectionRequest requestConnection(
        final HttpRoute route, 
        final Object state) {

    final PoolEntryRequest poolRequest = connectionPool.requestPoolEntry(
            route, state);

    return new ClientConnectionRequest() {

        public void abortRequest() {
            poolRequest.abortRequest();
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) throws InterruptedException,
                ConnectionPoolTimeoutException {
            if (route == null) {
                throw new IllegalArgumentException("Route may not be null.");
            }

            if (log.isDebugEnabled()) {
                log.debug("Get connection: " + route + ", timeout = " + timeout);
            }

            BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
            return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
        }

    };

}
项目:ZTLib    文件:MinimalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:ZTLib    文件:InternalHttpClient.java   
public ClientConnectionManager getConnectionManager() {

        return new ClientConnectionManager() {

            public void shutdown() {
                connManager.shutdown();
            }

            public ClientConnectionRequest requestConnection(
                    final HttpRoute route, final Object state) {
                throw new UnsupportedOperationException();
            }

            public void releaseConnection(
                    final ManagedClientConnection conn,
                    final long validDuration, final TimeUnit timeUnit) {
                throw new UnsupportedOperationException();
            }

            public SchemeRegistry getSchemeRegistry() {
                throw new UnsupportedOperationException();
            }

            public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
                connManager.closeIdleConnections(idletime, tunit);
            }

            public void closeExpiredConnections() {
                connManager.closeExpiredConnections();
            }

        };

    }
项目:lams    文件:BasicClientConnectionManager.java   
public void releaseConnection(final ManagedClientConnection conn, long keepalive, TimeUnit tunit) {
    assertNotShutdown();
    if (!(conn instanceof ManagedClientConnectionImpl)) {
        throw new IllegalArgumentException("Connection class mismatch, " +
             "connection not obtained from this manager");
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Releasing connection " + conn);
    }
    ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    synchronized (managedConn) {
        if (managedConn.getPoolEntry() == null) {
            return; // already released
        }
        ClientConnectionManager manager = managedConn.getManager();
        if (manager != null && manager != this) {
            throw new IllegalStateException("Connection not obtained from this manager");
        }
        synchronized (this) {
            try {
                if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                    try {
                        managedConn.shutdown();
                    } catch (IOException iox) {
                        if (this.log.isDebugEnabled()) {
                            this.log.debug("I/O exception shutting down released connection", iox);
                        }
                    }
                }
                this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                if (this.log.isDebugEnabled()) {
                    String s;
                    if (keepalive > 0) {
                        s = "for " + keepalive + " " + tunit;
                    } else {
                        s = "indefinitely";
                    }
                    this.log.debug("Connection can be kept alive " + s);
                }
            } finally {
                managedConn.detach();
                this.conn = null;
                if (this.poolEntry.isClosed()) {
                    this.poolEntry = null;
                }
            }
        }
    }
}
项目:lams    文件:SingleClientConnManager.java   
/**
 * Obtains a connection.
 *
 * @param route     where the connection should point to
 *
 * @return  a connection that can be used to communicate
 *          along the given route
 */
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
    if (route == null) {
        throw new IllegalArgumentException("Route may not be null.");
    }
    assertStillUp();

    if (log.isDebugEnabled()) {
        log.debug("Get connection for route " + route);
    }

    synchronized (this) {
        if (managedConn != null)
            throw new IllegalStateException(MISUSE_MESSAGE);

        // check re-usability of the connection
        boolean recreate = false;
        boolean shutdown = false;

        // Kill the connection if it expired.
        closeExpiredConnections();

        if (uniquePoolEntry.connection.isOpen()) {
            RouteTracker tracker = uniquePoolEntry.tracker;
            shutdown = (tracker == null || // can happen if method is aborted
                        !tracker.toRoute().equals(route));
        } else {
            // If the connection is not open, create a new PoolEntry,
            // as the connection may have been marked not reusable,
            // due to aborts -- and the PoolEntry should not be reused
            // either.  There's no harm in recreating an entry if
            // the connection is closed.
            recreate = true;
        }

        if (shutdown) {
            recreate = true;
            try {
                uniquePoolEntry.shutdown();
            } catch (IOException iox) {
                log.debug("Problem shutting down connection.", iox);
            }
        }

        if (recreate)
            uniquePoolEntry = new PoolEntry();

        managedConn = new ConnAdapter(uniquePoolEntry, route);

        return managedConn;
    }
}
项目:lams    文件:SingleClientConnManager.java   
public void releaseConnection(
        ManagedClientConnection conn,
        long validDuration, TimeUnit timeUnit) {
    assertStillUp();

    if (!(conn instanceof ConnAdapter)) {
        throw new IllegalArgumentException
            ("Connection class mismatch, " +
             "connection not obtained from this manager.");
    }

    if (log.isDebugEnabled()) {
        log.debug("Releasing connection " + conn);
    }

    ConnAdapter sca = (ConnAdapter) conn;
    synchronized (sca) {
        if (sca.poolEntry == null)
            return; // already released
        ClientConnectionManager manager = sca.getManager();
        if (manager != null && manager != this) {
            throw new IllegalArgumentException
                ("Connection not obtained from this manager.");
        }
        try {
            // make sure that the response has been read completely
            if (sca.isOpen() && (this.alwaysShutDown ||
                                 !sca.isMarkedReusable())
                ) {
                if (log.isDebugEnabled()) {
                    log.debug
                        ("Released connection open but not reusable.");
                }

                // make sure this connection will not be re-used
                // we might have gotten here because of a shutdown trigger
                // shutdown of the adapter also clears the tracked route
                sca.shutdown();
            }
        } catch (IOException iox) {
            if (log.isDebugEnabled())
                log.debug("Exception shutting down released connection.",
                          iox);
        } finally {
            sca.detach();
            synchronized (this) {
                managedConn = null;
                lastReleaseTime = System.currentTimeMillis();
                if(validDuration > 0)
                    connectionExpiresTime = timeUnit.toMillis(validDuration) + lastReleaseTime;
                else
                    connectionExpiresTime = Long.MAX_VALUE;
            }
        }
    }
}
项目:lams    文件:PoolingClientConnectionManager.java   
public void releaseConnection(
        final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {

    if (!(conn instanceof ManagedClientConnectionImpl)) {
        throw new IllegalArgumentException
            ("Connection class mismatch, " +
             "connection not obtained from this manager.");
    }
    ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    if (managedConn.getManager() != this) {
        throw new IllegalStateException("Connection not obtained from this manager.");
    }

    synchronized (managedConn) {
        HttpPoolEntry entry = managedConn.detach();
        if (entry == null) {
            return;
        }
        try {
            if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                try {
                    managedConn.shutdown();
                } catch (IOException iox) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("I/O exception shutting down released connection", iox);
                    }
                }
            }
            entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
            if (this.log.isDebugEnabled()) {
                String s;
                if (keepalive > 0) {
                    s = "for " + keepalive + " " + tunit;
                } else {
                    s = "indefinitely";
                }
                this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
            }
        } finally {
            this.pool.release(entry, managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}
项目:lams    文件:ThreadSafeClientConnManager.java   
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {

        if (!(conn instanceof BasicPooledConnAdapter)) {
            throw new IllegalArgumentException
                ("Connection class mismatch, " +
                 "connection not obtained from this manager.");
        }
        BasicPooledConnAdapter hca = (BasicPooledConnAdapter) conn;
        if ((hca.getPoolEntry() != null) && (hca.getManager() != this)) {
            throw new IllegalArgumentException
                ("Connection not obtained from this manager.");
        }
        synchronized (hca) {
            BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
            if (entry == null) {
                return;
            }
            try {
                // make sure that the response has been read completely
                if (hca.isOpen() && !hca.isMarkedReusable()) {
                    // In MTHCM, there would be a call to
                    // SimpleHttpConnectionManager.finishLastResponse(conn);
                    // Consuming the response is handled outside in 4.0.

                    // make sure this connection will not be re-used
                    // Shut down rather than close, we might have gotten here
                    // because of a shutdown trigger.
                    // Shutdown of the adapter also clears the tracked route.
                    hca.shutdown();
                }
            } catch (IOException iox) {
                if (log.isDebugEnabled())
                    log.debug("Exception shutting down released connection.",
                              iox);
            } finally {
                boolean reusable = hca.isMarkedReusable();
                if (log.isDebugEnabled()) {
                    if (reusable) {
                        log.debug("Released connection is reusable.");
                    } else {
                        log.debug("Released connection is not reusable.");
                    }
                }
                hca.detach();
                pool.freeEntry(entry, reusable, validDuration, timeUnit);
            }
        }
    }
项目:PhET    文件:ManagerConnectDirect.java   
/**
 * Main entry point to this example.
 *
 * @param args      ignored
 */
public final static void main(String[] args)
    throws Exception {

    final HttpHost target = new HttpHost("jakarta.apache.org", 80, "http");

    setup(); // some general setup

    ClientConnectionManager clcm = createManager();

    HttpRequest req = createRequest(target);
    HttpContext ctx = createContext();

    System.out.println("preparing route to " + target);
    HttpRoute route = new HttpRoute
        (target, null, supportedSchemes.getScheme(target).isLayered());

    System.out.println("requesting connection for " + route);
    ClientConnectionRequest connRequest = clcm.requestConnection(route, null);
    ManagedClientConnection conn = connRequest.getConnection(0, null);
    try {
        System.out.println("opening connection");
        conn.open(route, ctx, getParams());

        System.out.println("sending request");
        conn.sendRequestHeader(req);
        // there is no request entity
        conn.flush();

        System.out.println("receiving response header");
        HttpResponse rsp = conn.receiveResponseHeader();

        System.out.println("----------------------------------------");
        System.out.println(rsp.getStatusLine());
        Header[] headers = rsp.getAllHeaders();
        for (int i=0; i<headers.length; i++) {
            System.out.println(headers[i]);
        }
        System.out.println("----------------------------------------");

        System.out.println("closing connection");
        conn.close();

    } finally {

        if (conn.isOpen()) {
            System.out.println("shutting down connection");
            try {
                conn.shutdown();
            } catch (Exception x) {
                System.out.println("problem during shutdown");
                x.printStackTrace(System.out);
            }
        }

        System.out.println("releasing connection");
        clcm.releaseConnection(conn, -1, null);
    }

}
项目:cloud-meter    文件:JMeterPoolingClientConnectionManager.java   
@Override
public void releaseConnection(
        final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {

    Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
        "connection not obtained from this manager");
    final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    Asserts.check(managedConn.getManager() == this, "Connection not obtained from this manager");
    synchronized (managedConn) {
        final HttpPoolEntry entry = managedConn.detach();
        if (entry == null) {
            return;
        }
        try {
            if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                try {
                    managedConn.shutdown();
                } catch (final IOException iox) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("I/O exception shutting down released connection", iox);
                    }
                }
            }
            // Only reusable connections can be kept alive
            if (managedConn.isMarkedReusable()) {
                entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                if (this.log.isDebugEnabled()) {
                    final String s;
                    if (keepalive > 0) {
                        s = "for " + keepalive + " " + tunit;
                    } else {
                        s = "indefinitely";
                    }
                    this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
                }
            }
        } finally {
            this.pool.release(entry, managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}
项目:cloud-meter    文件:MeasuringConnectionManager.java   
@Override
public ManagedClientConnection getConnection(long timeout, TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
    ManagedClientConnection res = handler.getConnection(timeout, tunit);
    return new MeasuredConnection(res);
}
项目:cloud-meter    文件:MeasuringConnectionManager.java   
public MeasuredConnection(ManagedClientConnection res) {
    handler = res;
}
项目:purecloud-iot    文件:BasicClientConnectionManager.java   
@Override
public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
    Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
        "connection not obtained from this manager");
    final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    synchronized (managedConn) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("Releasing connection " + conn);
        }
        if (managedConn.getPoolEntry() == null) {
            return; // already released
        }
        final ClientConnectionManager manager = managedConn.getManager();
        Asserts.check(manager == this, "Connection not obtained from this manager");
        synchronized (this) {
            if (this.shutdown) {
                shutdownConnection(managedConn);
                return;
            }
            try {
                if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                    shutdownConnection(managedConn);
                }
                if (managedConn.isMarkedReusable()) {
                    this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                    if (this.log.isDebugEnabled()) {
                        final String s;
                        if (keepalive > 0) {
                            s = "for " + keepalive + " " + tunit;
                        } else {
                            s = "indefinitely";
                        }
                        this.log.debug("Connection can be kept alive " + s);
                    }
                }
            } finally {
                managedConn.detach();
                this.conn = null;
                if (this.poolEntry.isClosed()) {
                    this.poolEntry = null;
                }
            }
        }
    }
}