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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations