Search in sources :

Example 6 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 7 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 8 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)

Example 9 with ShutdownListener

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

the class IdCachedServicesImpl method getInstance.

protected static synchronized IdServices getInstance() {
    if (instance == null) {
        DEBUG.message("IdCachedServicesImpl.getInstance(): " + "Creating new Instance of IdCachedServicesImpl()");
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        //the instance should be created before acquiring the lock to
        //prevent possible deadlocks by using Stats
        instance = new IdCachedServicesImpl();
        shutdownMan.addShutdownListener(new ShutdownListener() {

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

Example 10 with ShutdownListener

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

the class ThreadMonitorTest method shouldRespondToShutdownSignalBeforeExecute.

@Test
public void shouldRespondToShutdownSignalBeforeExecute() {
    // Given
    Runnable mockRunnable = mock(Runnable.class);
    /**
         * Setup the shutdownManager so that when addListener is invoked, it will in the same
         * thread, call the shutdown listener.
         *
         * For the test this will then move the WatchDog into a completed state before the
         * Thread has had a chance to execute, therefore preventing execution of the runnable.
         */
    doAnswer(new Answer() {

        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ShutdownListener listener = (ShutdownListener) invocationOnMock.getArguments()[0];
            listener.shutdown();
            return null;
        }
    }).when(mockShutdownWrapper).addShutdownListener(any(ShutdownListener.class));
    // When
    monitor.watchThread(immediateExecutor(), mockRunnable);
    // Then
    verify(mockRunnable, times(0)).run();
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.testng.annotations.Test)

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