Search in sources :

Example 1 with ShutdownListener

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

the class AuditServiceProviderImpl method registerListeners.

private void registerListeners() {
    configProvider.addConfigurationListener(new AuditServiceConfigurationListener() {

        @Override
        public void globalConfigurationChanged() {
            refreshDefaultAuditService();
        }

        @Override
        public void realmConfigurationChanged(String realm) {
            refreshRealmAuditService(realm);
        }

        @Override
        public void realmConfigurationRemoved(String realm) {
            removeRealmAuditService(realm);
        }
    });
    shutdownManager.addShutdownListener(new ShutdownListener() {

        @Override
        public void shutdown() {
            closeAuditServices();
        }
    });
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) AuditServiceConfigurationListener(org.forgerock.openam.audit.configuration.AuditServiceConfigurationListener)

Example 2 with ShutdownListener

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

the class DataLayer method initLdapPool.

/**
     * Initialize the pool shared by all DataLayer object(s).
     */
private synchronized void initLdapPool() throws UMSException {
    // Don't do anything if pool is already initialized
    if (_ldapPool != null)
        return;
    /*
         * Initialize the pool with minimum and maximum connections settings
         * retrieved from configuration
         */
    ServerInstance svrCfg = null;
    String hostName = null;
    try {
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        hostName = dsCfg.getHostName("default");
        baseFactory = dsCfg.getNewProxyConnectionFactory();
        svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_PROXY);
    } catch (LDAPServiceException ex) {
        debug.error("Error initializing connection pool " + ex.getMessage());
    }
    // Check if svrCfg was successfully obtained
    if (svrCfg == null) {
        debug.error("Error getting server config.");
        String[] args = new String[1];
        args[0] = hostName == null ? "default" : hostName;
        throw new UMSException(i18n.getString(IUMSConstants.NEW_INSTANCE_FAILED, args));
    }
    int poolMin = svrCfg.getMinConnections();
    int poolMax = svrCfg.getMaxConnections();
    m_releaseConnectionBeforeSearchCompletes = svrCfg.getBooleanValue(LDAP_RELEASECONNBEFORESEARCH, false);
    if (debug.messageEnabled()) {
        debug.message("Creating ldap connection pool with: poolMin {}, poolMax {}", poolMin, poolMax);
    }
    int idleTimeout = SystemProperties.getAsInt(Constants.LDAP_CONN_IDLE_TIME_IN_SECS, 0);
    if (idleTimeout == 0) {
        debug.warning("Idle timeout not set. Defaulting to 0.");
    }
    _ldapPool = Connections.newCachedConnectionPool(Connections.newNamedConnectionFactory(baseFactory, "DataLayer"), poolMin, poolMax, idleTimeout, TimeUnit.SECONDS);
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    shutdownMan.addShutdownListener(new ShutdownListener() {

        public void shutdown() {
            if (_ldapPool != null) {
                _ldapPool.close();
            }
        }
    });
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ByteString(org.forgerock.opendj.ldap.ByteString) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 3 with ShutdownListener

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

the class IdServicesImpl method getInstance.

protected static synchronized IdServices getInstance() {
    if (_instance == null) {
        DEBUG.message("IdServicesImpl.getInstance(): " + "Creating new Instance of IdServicesImpl()");
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        _instance = new IdServicesImpl();
        shutdownMan.addShutdownListener(new ShutdownListener() {

            public void shutdown() {
                synchronized (_instance) {
                    shutdownCalled = true;
                }
                _instance.clearIdRepoPlugins();
            }
        });
    }
    return _instance;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager)

Example 4 with ShutdownListener

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

the class SystemTimerPool method getTimerPool.

/**
     * Create and return the system timer pool.
     */
public static synchronized TimerPool getTimerPool() {
    if (instance == null) {
        ShutdownManager shutdownMan = ShutdownManager.getInstance();
        // Don't load the Debug object in static block as it can
        // cause issues when doing a container restart.
        instance = new TimerPool("SystemTimerPool", poolSize, false, Debug.getInstance("SystemTimerPool"));
        try {
            shutdownMan.addShutdownListener(new ShutdownListener() {

                public void shutdown() {
                    instance.shutdown();
                    instance = null;
                }
            });
        } catch (IllegalMonitorStateException e) {
            instance.shutdown();
            instance = null;
            throw e;
        }
    }
    return instance;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener)

Example 5 with ShutdownListener

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

the class SystemTimer method getTimer.

/**
     * Create and return the system timer.
     */
public static synchronized TimerPool getTimer() {
    if (instance == null) {
        ShutdownManager shutdownMan = ShutdownManager.getInstance();
        // Don't load the Debug object in static block as it can
        // cause issues when doing a container restart.
        instance = new TimerPool("SystemTimer", 1, false, Debug.getInstance("SystemTimer"));
        shutdownMan.addShutdownListener(new ShutdownListener() {

            public void shutdown() {
                instance.shutdown();
                instance = null;
            }
        });
    }
    return instance;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener)

Aggregations

ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)22 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)10 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)6 Options (org.forgerock.util.Options)4 Duration (org.forgerock.util.time.Duration)4 ShutdownManager (com.sun.identity.common.ShutdownManager)3 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)3 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)3 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 PolicyException (com.sun.identity.policy.PolicyException)2 IOException (java.io.IOException)2 ByteString (org.forgerock.opendj.ldap.ByteString)2 LdapException (org.forgerock.opendj.ldap.LdapException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 Test (org.testng.annotations.Test)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1