Search in sources :

Example 1 with IdleConnectionTimeoutThread

use of org.apache.commons.httpclient.util.IdleConnectionTimeoutThread in project carbon-business-process by wso2.

the class BPELServerImpl method initHttpConnectionManager.

private void initHttpConnectionManager() throws Exception {
    httpConnectionManager = new MultiThreadedHttpConnectionManager();
    int maxConnectionsPerHost = bpelServerConfiguration.getMaxConnectionsPerHost();
    int maxTotalConnections = bpelServerConfiguration.getMaxTotalConnections();
    if (log.isDebugEnabled()) {
        log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + maxConnectionsPerHost);
        log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + maxTotalConnections);
    }
    if (maxConnectionsPerHost < 1 || maxTotalConnections < 1) {
        String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + " and " + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + " must be positive integers!";
        log.error(errmsg);
        throw new Exception(errmsg);
    }
    httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
    httpConnectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
    // TODO: Modify this and move configuration to bps.xml
    // Register the connection manager to a idle check thread
    idleConnectionTimeoutThread = new IdleConnectionTimeoutThread();
    idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread");
    long idleConnectionTimeout = Long.parseLong(odeConfigurationProperties.getProperty("http.idle.connection.timeout", "30000"));
    long idleConnectionCheckInterval = Long.parseLong(odeConfigurationProperties.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();
}
Also used : IdleConnectionTimeoutThread(org.apache.commons.httpclient.util.IdleConnectionTimeoutThread) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) BpelEngineException(org.apache.ode.bpel.iapi.BpelEngineException)

Example 2 with IdleConnectionTimeoutThread

use of org.apache.commons.httpclient.util.IdleConnectionTimeoutThread in project ecf by eclipse.

the class TestIdleConnectionTimeout method testTimeoutThread.

/**
 * Tests that the IdleConnectionTimeoutThread works correctly.
 */
public void testTimeoutThread() {
    TimeoutHttpConnectionManager cm = new TimeoutHttpConnectionManager();
    IdleConnectionTimeoutThread timeoutThread = new IdleConnectionTimeoutThread();
    timeoutThread.addConnectionManager(cm);
    timeoutThread.setTimeoutInterval(100);
    timeoutThread.start();
    synchronized (this) {
        try {
            this.wait(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    assertTrue("closeIdleConnections() not called", cm.closed);
    timeoutThread.removeConnectionManager(cm);
    cm.closed = false;
    synchronized (this) {
        try {
            this.wait(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    assertFalse("closeIdleConnections() called", cm.closed);
    timeoutThread.shutdown();
}
Also used : IdleConnectionTimeoutThread(org.apache.commons.httpclient.util.IdleConnectionTimeoutThread)

Example 3 with IdleConnectionTimeoutThread

use of org.apache.commons.httpclient.util.IdleConnectionTimeoutThread in project nimbus by nimbus-org.

the class HttpClientFactoryService method startService.

/**
 * サービスの開始処理を行う。<p>
 *
 * @exception Exception サービスの開始に失敗した場合
 */
public void startService() throws Exception {
    if (journalServiceName != null) {
        journal = (Journal) ServiceManagerFactory.getServiceObject(journalServiceName);
    }
    if (sequenceServiceName != null) {
        sequence = (Sequence) ServiceManagerFactory.getServiceObject(sequenceServiceName);
    }
    if (threadContextServiceName != null) {
        threadContext = (Context) ServiceManagerFactory.getServiceObject(threadContextServiceName);
    }
    if (semaphoreServiceName != null) {
        semaphore = (Semaphore) ServiceManagerFactory.getServiceObject(semaphoreServiceName);
        semaphore.accept();
    }
    if (performanceRecorderServiceName != null) {
        performanceRecorder = (PerformanceRecorder) ServiceManagerFactory.getServiceObject(performanceRecorderServiceName);
    }
    if (httpConnectionManagerClass != null) {
        httpConnectionManager = (HttpConnectionManager) httpConnectionManagerClass.newInstance();
        if (idleConnectionTimeout > 0) {
            idleConnectionTimeoutThread = new IdleConnectionTimeoutThread();
            idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager);
            idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout);
            if (idleConnectionCheckInterval > 0) {
                idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval);
            }
            idleConnectionTimeoutThread.start();
        }
    }
}
Also used : IdleConnectionTimeoutThread(org.apache.commons.httpclient.util.IdleConnectionTimeoutThread)

Aggregations

IdleConnectionTimeoutThread (org.apache.commons.httpclient.util.IdleConnectionTimeoutThread)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 BpelEngineException (org.apache.ode.bpel.iapi.BpelEngineException)1