class ExitTrappingSecurityManager extends SecurityManager {

	public static void replaceGracefulExitWithHaltIfConfigured(Configuration configuration) {
		if (configuration.get(HALT_ON_FATAL_ERROR)) {
			SecurityManager forcefulShutdownManager = new ExitTrappingSecurityManager(
				status -> Runtime.getRuntime().halt(status),
				System.getSecurityManager());
			try {
				System.setSecurityManager(forcefulShutdownManager);
			} catch (Exception e) {
				throw new IllegalConfigurationException(
					String.format("Could not register forceful shutdown handler. This feature requires the permission to " +
							"set a SecurityManager. Either update your existing SecurityManager to allow setting a SecurityManager " +
							"or disable this feature by updating your Flink config with the following: " +
							"'%s: %s'",
						HALT_ON_FATAL_ERROR.key(),
						HALT_ON_FATAL_ERROR.defaultValue()),
					e);
			}
		}
	}

	public  ExitTrappingSecurityManager(Consumer<Integer> onExitBehavior, @Nullable SecurityManager existingManager);

}