Search in sources :

Example 21 with ShutdownListener

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

the class ShutdownManager method shutdown.

/**
     * Shuts down all the listeners in this ShutdownManager.
     */
public void shutdown() throws IllegalMonitorStateException {
    if (acquireValidLock()) {
        try {
            shutdownCalled = true;
            List<ShutdownPriority> priorities = ShutdownPriority.getPriorities();
            for (ShutdownPriority i : priorities) {
                for (Iterator<ShutdownListener> j = listeners[i.getIntValue() - 1].iterator(); j.hasNext(); ) {
                    j.next().shutdown();
                    // remove the components which have been shutdown to avoid
                    // problem when the shutdown function is called twice.
                    j.remove();
                }
            }
            if (appSSOTokenDestroyer != null) {
                appSSOTokenDestroyer.shutdown();
                appSSOTokenDestroyer = null;
            }
            instance = null;
        } catch (RuntimeException t) {
            Debug.getInstance("amUtil").error("Error during shutdown", t);
            throw t;
        } finally {
            releaseLockAndNotify();
        }
    } else {
        throw new IllegalMonitorStateException("Failed to acquire lock during shutdown.");
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownPriority(org.forgerock.util.thread.listener.ShutdownPriority)

Example 22 with ShutdownListener

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

the class UpgradeUtils method getLDAPConnectionFactory.

private static ConnectionFactory getLDAPConnectionFactory(String hostname, int port, Options options) {
    if (factory == null) {
        factory = new LDAPConnectionFactory(hostname, port, options);
        ShutdownManager.getInstance().addShutdownListener(new ShutdownListener() {

            @Override
            public void shutdown() {
                if (factory != null) {
                    factory.close();
                }
            }
        });
    }
    return factory;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory)

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