Package org.apache.hadoop.util
Class ExitUtil
java.lang.Object
org.apache.hadoop.util.ExitUtil
Facilitates hooking process termination for tests, debugging
and embedding.
Hadoop code that attempts to call
System.exit(int)
or Runtime.halt(int) MUST invoke it via these methods.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn exception raised when a call toterminate(int)was called and system exits were blocked.static classAn exception raised when a call toterminate(int)was called and system halts were blocked. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDisable the use of System.exit for testing.static voidDisable the use ofRuntime.getRuntime().halt()for testing.static voidEnable the use of System.exit for testing.static ExitUtil.ExitExceptionstatic ExitUtil.HaltExceptionstatic voidhalt(int status) Forcibly terminates the currently running Java virtual machine.static voidForcibly terminates the currently running Java virtual machine.static voidForcibly terminates the currently running Java virtual machine.static voidHalts the JVM if halt is enabled, rethrow provided exception or any raised error otherwise.static booleanstatic voidHandler for out of memory events -no attempt is made here to cleanly shutdown or support halt blocking; a robust printing of the event to stderr is all that can be done.static voidReset the tracking of process termination.static voidReset the tracking of process termination.static voidterminate(int status) Liketerminate(int, Throwable)without a message.static voidTerminate the current process.static voidLiketerminate(int, String)but uses the given throwable to build the message to display or throw as anExitUtil.ExitException.static voidExits the JVM if exit is enabled, rethrow provided exception or any raised error otherwise.static boolean
-
Field Details
-
EXIT_EXCEPTION_MESSAGE
Message raised from an exit exception if none were provided: "ExitException".- See Also:
-
HALT_EXCEPTION_MESSAGE
Message raised from a halt exception if none were provided: "HaltException".- See Also:
-
-
Method Details
-
disableSystemExit
public static void disableSystemExit()Disable the use of System.exit for testing. -
enableSystemExit
public static void enableSystemExit()Enable the use of System.exit for testing. -
disableSystemHalt
public static void disableSystemHalt()Disable the use ofRuntime.getRuntime().halt()for testing. -
terminateCalled
public static boolean terminateCalled()- Returns:
- true if terminate has been called.
-
haltCalled
public static boolean haltCalled()- Returns:
- true if halt has been called.
-
getFirstExitException
- Returns:
- the first
ExitExceptionthrown, null if none thrown yet.
-
getFirstHaltException
- Returns:
- the first
HaltExceptionthrown, null if none thrown yet.
-
resetFirstExitException
public static void resetFirstExitException()Reset the tracking of process termination. This is for use in unit tests where one test in the suite expects an exit but others do not. -
resetFirstHaltException
public static void resetFirstHaltException()Reset the tracking of process termination. This is for use in unit tests where one test in the suite expects a halt but others do not. -
terminate
Exits the JVM if exit is enabled, rethrow provided exception or any raised error otherwise. Inner termination: either exit with the exception's exit code, or, if system exits are disabled, rethrow the exception.- Parameters:
ee- exit exception- Throws:
ExitUtil.ExitException- ifSystem.exit(int)is disabled and not suppressed by an ErrorError- ifSystem.exit(int)is disabled and one Error arise, suppressing anything else, evenee
-
halt
Halts the JVM if halt is enabled, rethrow provided exception or any raised error otherwise. If halt is disabled, this method throws either the exception argument if no error arise, the first error if at least one arise, suppressinghe. If halt is enabled, all throwables are caught, even errors.- Parameters:
he- the exception containing the status code, message and any stack trace.- Throws:
ExitUtil.HaltException- ifRuntime.halt(int)is disabled and not suppressed by an ErrorError- ifRuntime.halt(int)is disabled and one Error arise, suppressing anyuthing else, evenhe
-
terminate
Liketerminate(int, String)but uses the given throwable to build the message to display or throw as anExitUtil.ExitException.- Parameters:
status- exit code to use if the exception is not an ExitException.t- throwable which triggered the termination. If this exception is anExitUtil.ExitExceptionits status overrides that passed in.- Throws:
ExitUtil.ExitException- ifSystem.exit(int)is disabled.
-
halt
Forcibly terminates the currently running Java virtual machine.- Parameters:
status- exit code to use if the exception is not a HaltException.t- throwable which triggered the termination. If this exception is aExitUtil.HaltExceptionits status overrides that passed in.- Throws:
ExitUtil.HaltException- ifSystem.exit(int)is disabled.
-
terminate
Liketerminate(int, Throwable)without a message.- Parameters:
status- exit code- Throws:
ExitUtil.ExitException- ifSystem.exit(int)is disabled.
-
terminate
Terminate the current process. Note that terminate is the *only* method that should be used to terminate the daemon processes.- Parameters:
status- exit codemsg- message used to create theExitException- Throws:
ExitUtil.ExitException- ifSystem.exit(int)is disabled.
-
halt
Forcibly terminates the currently running Java virtual machine.- Parameters:
status- status code- Throws:
ExitUtil.HaltException- ifRuntime.halt(int)is disabled.
-
halt
Forcibly terminates the currently running Java virtual machine.- Parameters:
status- status codemessage- message- Throws:
ExitUtil.HaltException- ifRuntime.halt(int)is disabled.
-
haltOnOutOfMemory
Handler for out of memory events -no attempt is made here to cleanly shutdown or support halt blocking; a robust printing of the event to stderr is all that can be done.- Parameters:
oome- out of memory event
-