ShutdownManager.java revision bcb85423bc6855cb1c7accc69fa051e1771c000a
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: ShutdownManager.java,v 1.7 2008/10/04 00:36:44 veiming Exp $
*
*/
/*
* Portions Copyrighted 2011-2012 ForgeRock Inc
*/
/**
* ShutdownManager is a static instance which is used to trigger all the
* ShutdownListener to call shutdown function.
*/
public class ShutdownManager {
private volatile static ShutdownManager instance;
protected boolean shutdownCalled;
private ShutdownListener appSSOTokenDestroyer;
/**
* Constructor of ShutdownManager.
*/
private ShutdownManager() {
shutdownCalled = false;
for (int i = 0; i < size; i++) {
}
if (hooksEnabled) {
// add the trigger for stand alone application to shutdown.
new Runnable() {
public void run() {
if (acquireValidLock()) {
try {
shutdown();
} finally {
}
}
}
}, "ShutdownThread"));
}
}
/**
* Acquire the lock of this ShutdownManager. The function will block if
* other thread is holding the lock or return false if shutdown is called.
*
* @return a boolean to indicate whether it success.
*/
public boolean acquireValidLock() {
if (shutdownCalled) {
return false;
} else {
}
return true;
}
/**
* Release the lock of this ShutdownManager. IllegalMonitorStateException
* will be thrown if the current thread is not holding the lock.
*/
public void releaseLockAndNotify() throws
}
/**
* Returns the static instance of ShutdownManager in the VM.
*
* @return The static instance of ShutdownManager
*/
public static synchronized ShutdownManager getInstance() {
instance = new ShutdownManager();
}
return instance;
}
/**
* Adds a ShutdownListener to this ShutdownManager.
*
* @param listener The listener to be added
*/
}
/**
* Adds a ShutdownListener to this ShutdownManager with indicated level.
*
* @param listener The listener to be added
* @param priority The priority to shutdown for the shutdown listener
*/
if(rwlock.isWriteLockedByCurrentThread()) {
} else {
throw new IllegalMonitorStateException(
"The calling thread is not the owner of the lock!");
}
}
/**
* Removes a ShutdownListener from this ShutdownManager.
*
* @param listener The listener to be removed
*/
if(rwlock.isWriteLockedByCurrentThread()) {
break;
}
}
} else {
throw new IllegalMonitorStateException(
"The calling thread is not the owner of the lock!");
}
}
/**
* Shuts down all the listeners in this ShutdownManager.
*/
public void shutdown() throws IllegalMonitorStateException {
if(rwlock.isWriteLockedByCurrentThread()) {
shutdownCalled = true;
j.hasNext();) {
// remove the components which have been shutdown to avoid
// problem when the shutdown function is called twice.
j.remove();
}
}
if (appSSOTokenDestroyer != null) {
}
} else {
throw new IllegalMonitorStateException(
"The calling thread is not the owner of the lock!");
}
}
/**
* Adds application single-sign-on token destroyer.
*
* @param listener Listener object.
*/
}
}