net.dclausen.util
Class ExitLogger

java.lang.Object
  extended byjava.lang.SecurityManager
      extended bynet.dclausen.util.ExitLogger

public class ExitLogger
extends SecurityManager

A simple SecurityManager which logs calls to checkExit(int). When an instance of ExitLogger is installed as the System's default SecurityManager, it acts as a trap for System.exit(int) and Runtime.exit(int), because those two functions both call System.getSecurityManager().checkExit() before terminating the JVM.

All permission checks (including checkExit) are forwarded to the System's previous SecurityManager, if one was set.

Use the static install(java.util.logging.Logger, java.util.logging.Level) method to install a new instance of this class as the System's SecurityManager.

See Also:
System.exit(int), Runtime.exit(int), SecurityManager, System.setSecurityManager(SecurityManager), Logger

Field Summary
 
Fields inherited from class java.lang.SecurityManager
inCheck
 
Method Summary
 void checkExit(int status)
          Use stack introspection to identify the calling class/method/line, and log it.
 void checkPermission(Permission perm)
          Delegate the check to the parent SecurityManager, if there is one.
static void install(Logger logger, Level level)
          Install an instance of ExitLogger as the System's SecurityManager.
 
Methods inherited from class java.lang.SecurityManager
checkAccept, checkAccess, checkAccess, checkAwtEventQueueAccess, checkConnect, checkConnect, checkCreateClassLoader, checkDelete, checkExec, checkLink, checkListen, checkMemberAccess, checkMulticast, checkMulticast, checkPackageAccess, checkPackageDefinition, checkPermission, checkPrintJobAccess, checkPropertiesAccess, checkPropertyAccess, checkRead, checkRead, checkRead, checkSecurityAccess, checkSetFactory, checkSystemClipboardAccess, checkTopLevelWindow, checkWrite, checkWrite, classDepth, classLoaderDepth, currentClassLoader, currentLoadedClass, getClassContext, getInCheck, getSecurityContext, getThreadGroup, inClass, inClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

install

public static void install(Logger logger,
                           Level level)
Install an instance of ExitLogger as the System's SecurityManager. The existing SecurityManager, if one exists, will be used as a delegate for all permission checks.

Parameters:
logger - the Logger to use when logging calls to System.exit() and Runtime.exit()
level - the level to use
Throws:
SecurityException - if the current SecurityManager doesn't want to be replaced
See Also:
System.setSecurityManager(java.lang.SecurityManager)

checkPermission

public void checkPermission(Permission perm)
Delegate the check to the parent SecurityManager, if there is one.


checkExit

public void checkExit(int status)
Use stack introspection to identify the calling class/method/line, and log it. This method is called by Runtime.exit(int) before actually stopping the JVM.