Search in sources :

Example 11 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager in project OpenAM by OpenRock.

the class SMSThreadPool method initialize.

static synchronized void initialize(boolean reinit) {
    // Check if already initialized
    if (reinit) {
        initialized = false;
    }
    if (initialized) {
        return;
    }
    int newPoolSize = DEFAULT_POOL_SIZE;
    try {
        if (SystemProperties.isServerMode()) {
            newPoolSize = Integer.parseInt(SystemProperties.get(Constants.SM_THREADPOOL_SIZE));
        } else {
            // For clients and CLIs, it is hardcoded to 3
            newPoolSize = 2;
        }
    } catch (Exception e) {
        newPoolSize = DEFAULT_POOL_SIZE;
    }
    if (newPoolSize == poolSize) {
        // No change in the pool size, return
        return;
    } else {
        poolSize = newPoolSize;
    }
    if (debug.messageEnabled()) {
        debug.message("SMSThreadPool: poolSize=" + poolSize);
    }
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    if (thrdPool != null) {
        // Create a new thread pool
        thrdPool = new ThreadPool("smIdmThreadPool", poolSize, DEFAULT_TRESHOLD, false, debug);
        // Create the shutdown hook
        ShutdownListener newShutdownListener = new ShutdownListener() {

            public void shutdown() {
                thrdPool.shutdown();
            }
        };
        // Register to shutdown hook
        shutdownMan.replaceShutdownListener(shutdownListener, newShutdownListener, null);
    } else {
        // Create a new thread pool
        thrdPool = new ThreadPool("smIdmThreadPool", poolSize, DEFAULT_TRESHOLD, false, debug);
        // Create the shutdown hook
        shutdownListener = new ShutdownListener() {

            public void shutdown() {
                thrdPool.shutdown();
            }
        };
        // Register to shutdown hook
        shutdownMan.addShutdownListener(shutdownListener);
    }
    initialized = true;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ThreadPool(com.iplanet.am.util.ThreadPool) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) ThreadPoolException(com.iplanet.am.util.ThreadPoolException)

Aggregations

ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)11 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)10 ThreadPool (com.iplanet.am.util.ThreadPool)2 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)2 ServerInstance (com.iplanet.services.ldap.ServerInstance)2 IOException (java.io.IOException)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)2 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 ServerGroup (com.iplanet.services.ldap.ServerGroup)1 XMLException (com.iplanet.services.util.XMLException)1 SSOException (com.iplanet.sso.SSOException)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 ConfiguratorException (com.sun.identity.setup.ConfiguratorException)1 FileNotFoundException (java.io.FileNotFoundException)1 LoginException (javax.security.auth.login.LoginException)1