/** 私有的构造方法 */
  private HttpProtocolHandler() {
    // 创建一个线程安全的HTTP连接池
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);
    connectionManager.getParams().setMaxTotalConnections(defaultMaxTotalConn);

    IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
    ict.addConnectionManager(connectionManager);
    ict.setConnectionTimeout(defaultIdleConnTimeout);

    ict.start();
  }
Exemple #2
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();
  }
Exemple #3
0
  /**
   * Shutdown the service engine. This performs cleanup before the BPE is terminated. Once this
   * method has been called, init() must be called before the transformation engine can be started
   * again with a call to start().
   *
   * @throws AxisFault if the engine is unable to shut down.
   */
  public void shutDown() throws AxisFault {

    ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
      if (_poller != null)
        try {
          __log.debug("shutting down poller");
          _poller.stop();
          _poller = null;
        } catch (Throwable t) {
          __log.debug("Error stopping poller.", t);
        }

      if (_bpelServer != null)
        try {
          __log.debug("shutting down ODE server.");
          _bpelServer.shutdown();
          _bpelServer = null;
        } catch (Throwable ex) {
          __log.debug("Error stopping services.", ex);
        }

      if (_cronScheduler != null) {
        try {
          __log.debug("shutting down cron scheduler.");
          _cronScheduler.shutdown();
          _cronScheduler = null;
        } catch (Exception ex) {
          __log.debug("Cron scheduler couldn't be shutdown.", ex);
        }
      }

      if (_scheduler != null)
        try {
          __log.debug("shutting down scheduler.");
          _scheduler.shutdown();
          _scheduler = null;
        } catch (Exception ex) {
          __log.debug("Scheduler couldn't be shutdown.", ex);
        }

      if (_store != null)
        try {
          _store.shutdown();
          _store = null;
        } catch (Throwable t) {
          __log.debug("Store could not be shutdown.", t);
        }

      if (_daoCF != null)
        try {
          _daoCF.shutdown();
        } catch (Throwable ex) {
          __log.debug("DOA shutdown failed.", ex);
        } finally {
          _daoCF = null;
        }

      if (_db != null)
        try {
          _db.shutdown();

        } catch (Throwable ex) {
          __log.debug("DB shutdown failed.", ex);
        } finally {
          _db = null;
        }

      if (_txMgr != null) {
        __log.debug("shutting down transaction manager.");
        _txMgr = null;
      }

      if (_connector != null) {
        try {
          __log.debug("shutdown BpelConnector");
          _connector.shutdown();
          _connector = null;
        } catch (Throwable t) {
          __log.error("Unable to cleanup temp files.", t);
        }
      }
      if (httpConnectionManager != null) {
        __log.debug("shutting down HTTP connection manager.");
        try {
          httpConnectionManager.shutdown();
          httpConnectionManager = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down HTTP connection manager.", t);
        }
      }
      if (idleConnectionTimeoutThread != null) {
        __log.debug("shutting down Idle Connection Timeout Thread.");
        try {
          idleConnectionTimeoutThread.shutdown();
          idleConnectionTimeoutThread = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down Idle Connection Timeout Thread.", t);
        }
      }
      try {
        __log.debug("cleaning up temporary files.");
        TempFileManager.cleanup();
      } catch (Throwable t) {
        __log.error("Unable to cleanup temp files.", t);
      }

      if (_executorService != null) {
        _executorService.shutdownNow();
        _executorService = null;
      }

      __log.info(__msgs.msgOdeShutdownCompleted());
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }