Esempio n. 1
0
  private void initHttpConnectionManager() throws ServletException {
    httpConnectionManager = new MultiThreadedHttpConnectionManager();
    // settings may be overridden from ode-axis2.properties using the same properties as HttpClient
    // /!\ If the size of the conn pool is smaller than the size of the thread pool, the thread pool
    // might get starved.
    int max_per_host =
        Integer.parseInt(
            _odeConfig.getProperty(
                HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
                "" + _odeConfig.getPoolMaxSize()));
    int max_total =
        Integer.parseInt(
            _odeConfig.getProperty(
                HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
                "" + _odeConfig.getPoolMaxSize()));
    if (__log.isDebugEnabled()) {
      __log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + max_per_host);
      __log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + max_total);
    }
    if (max_per_host < 1 || max_total < 1) {
      String errmsg =
          HttpConnectionManagerParams.MAX_HOST_CONNECTIONS
              + " and "
              + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS
              + " must be positive integers!";
      __log.error(errmsg);
      throw new ServletException(errmsg);
    }
    httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(max_per_host);
    httpConnectionManager.getParams().setMaxTotalConnections(max_total);

    // Register the connection manager to a idle check thread
    idleConnectionTimeoutThread = new IdleConnectionTimeoutThread();
    idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread");
    long idleConnectionTimeout =
        Long.parseLong(_odeConfig.getProperty("http.idle.connection.timeout", "30000"));
    long idleConnectionCheckInterval =
        Long.parseLong(_odeConfig.getProperty("http.idle.connection.check.interval", "30000"));

    if (__log.isDebugEnabled()) {
      __log.debug("http.idle.connection.timeout=" + idleConnectionTimeout);
      __log.debug("http.idle.connection.check.interval=" + idleConnectionCheckInterval);
    }
    idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout);
    idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval);

    idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager);
    idleConnectionTimeoutThread.start();
  }