예제 #1
0
  /**
   * Closes connections that have been idle for at least the given amount of time.
   *
   * @param idleTime the minimum idle time, in milliseconds, for connections to be closed
   */
  public void closeIdleConnections(final long idleTime) {

    // the latest time for which connections will be closed
    final long idleTimeout = System.currentTimeMillis() - idleTime;

    if (log.isDebugEnabled()) {
      log.debug("Checking for connections, idle timeout: " + idleTimeout);
    }

    for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
      final HttpConnection conn = entry.getKey();
      final TimeValues times = entry.getValue();
      final long connectionTime = times.timeAdded;
      if (connectionTime <= idleTimeout) {
        if (log.isDebugEnabled()) {
          log.debug("Closing idle connection, connection time: " + connectionTime);
        }
        try {
          conn.close();
        } catch (final IOException ex) {
          log.debug("I/O error closing connection", ex);
        }
      }
    }
  }
예제 #2
0
  public void closeExpiredConnections() {
    final long now = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
      log.debug("Checking for expired connections, now: " + now);
    }

    for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
      final HttpConnection conn = entry.getKey();
      final TimeValues times = entry.getValue();
      if (times.timeExpires <= now) {
        if (log.isDebugEnabled()) {
          log.debug("Closing connection, expired @: " + times.timeExpires);
        }
        try {
          conn.close();
        } catch (final IOException ex) {
          log.debug("I/O error closing connection", ex);
        }
      }
    }
  }