Exits the JVM with the given status code. This method will call all registered interceptors before exiting. If any interceptor returns false, the exit will be canceled. @param status The status code to exit with
(int status)
| 39 | * @param status The status code to exit with |
| 40 | */ |
| 41 | public static void exit(int status) |
| 42 | { |
| 43 | try |
| 44 | { |
| 45 | lock.lock(); |
| 46 | LOG.log(Level.FINEST, () -> MessageFormat.format( |
| 47 | "Started exiting with the status {0}. There are {1} interceptors.", status, |
| 48 | interceptors.size())); |
| 49 | isShuttingDown = true; |
| 50 | |
| 51 | boolean shouldExit = interceptors.stream() |
| 52 | .map((ExitInterceptor interceptor) -> { |
| 53 | boolean intercepted = interceptor.intercept(status); |
| 54 | LOG.log(Level.FINEST, |
| 55 | MessageFormat.format("Intercepted exit: {0} from registered interceptor: {1}", |
| 56 | intercepted, interceptor.getClass().getName())); |
| 57 | return intercepted; |
| 58 | }) |
| 59 | .filter(Predicate.isEqual(Boolean.FALSE)) |
| 60 | .findAny() |
| 61 | .orElse(Boolean.TRUE); |
| 62 | |
| 63 | if (shouldExit) |
| 64 | { |
| 65 | LOG.info(() -> MessageFormat.format("Exiting gracefully with status {0}", status)); |
| 66 | exitFunction.exit(status); |
| 67 | } |
| 68 | } finally |
| 69 | { |
| 70 | isShuttingDown = false; |
| 71 | lock.unlock(); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Adds an interceptor to the list of interceptors. This method can be called before or after shutdown has started, |