public class SomeClass { private SystemExiter exiter; // inject this or accept in constructor public void someMethod() { // ... exiter.exit(1); } }
/** * Calls {@link #logBeforeExit(ExitLogger)} and then invokes the {@link Exiter}. * @param logger logger the logger. Cannot be {@code null} * @param status the status code to provide to the exiter */ public static void logAndExit(ExitLogger logger, int status) { logBeforeExit(logger); getExiter().exit(status); // If we get here, the exiter didn't really exit. So we // must be embedded or something, or perhaps in a test case // Reset the logged flag so we can log again the next time // someone "exits" logged.set(false); }
/** * Terminates JVM with exit code: 1 - failed termination but not an abort situation. */ private static void fail(){ SystemExiter.abort(ExitCodes.FAILED); }
public void run() { int exitCode = restart ? ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT : ExitCodes.NORMAL; SystemExiter.logAndExit(new SystemExiter.ExitLogger() { @Override public void logExit() { ServerLogger.ROOT_LOGGER.shuttingDownInResponseToManagementRequest(op); } }, exitCode); } });
/** @deprecated use {@link #logAndExit(ExitLogger, int)} or {@link #abort(int)} */ @Deprecated public static void exit(final int status) { getExiter().exit(status); }
} catch (IOException e) { e.printStackTrace(); SystemExiter.abort(ExitCodes.FAILED); throw new IllegalStateException(); // not reached } catch (Throwable t) { t.printStackTrace(initialError); SystemExiter.abort(ExitCodes.FAILED); throw new IllegalStateException(); // not reached } finally { if (caught == null) { SystemExiter.logAndExit(ServerLogger.ROOT_LOGGER::shuttingDownInResponseToProcessControllerSignal, ExitCodes.NORMAL); } else { SystemExiter.abort(ExitCodes.FAILED);
abort(null); } else { SystemExiter.safeAbort();
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // WFLY-2741 -- DO NOT call context.getServiceRegistry(true) as that will trigger blocking for // service container stability and one use case for this op is to recover from a // messed up service container from a previous op. Instead just ask for authorization. // Note that we already have the exclusive lock, so we are just skipping waiting for stability. // If another op that is a step in a composite step with this op needs to modify the container // it will have to wait for container stability, so skipping this only matters for the case // where this step is the only runtime change. // context.getServiceRegistry(true); AuthorizationResult authorizationResult = context.authorize(operation, EnumSet.of(Action.ActionEffect.WRITE_RUNTIME)); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerLogger.ACCESS_LOGGER.unauthorized(operation.get(OP).asString(), PathAddress.pathAddress(operation.get(OP_ADDR)), authorizationResult.getExplanation()); } SystemExiter.logBeforeExit(new SystemExiter.ExitLogger() { @Override public void logExit() { HostControllerLogger.ROOT_LOGGER.shuttingDownInResponseToManagementRequest(getOperationName(operation)); } }); if (restart) { //Add the exit code so that we get respawned domainController.stopLocalHost(ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT); } else { domainController.stopLocalHost(); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }, OperationContext.Stage.RUNTIME);
SystemExiter.initialize(SystemExiter.Exiter.DEFAULT);
/** * Terminates JVM with exit code: 0 - normal termination. */ private static void exit(){ SystemExiter.logAndExit(HostControllerLogger.ROOT_LOGGER::shuttingDownInResponseToProcessControllerSignal, ExitCodes.NORMAL); }
/** @deprecated use {@link #logAndExit(ExitLogger, int)} or {@link #abort(int)} */ @Deprecated public static void exit(final int status) { getExiter().exit(status); }
} catch (IOException e) { e.printStackTrace(); SystemExiter.abort(ExitCodes.FAILED); throw new IllegalStateException(); // not reached } catch (Throwable t) { t.printStackTrace(initialError); SystemExiter.abort(ExitCodes.FAILED); throw new IllegalStateException(); // not reached } finally { if (caught == null) { SystemExiter.logAndExit(ServerLogger.ROOT_LOGGER::shuttingDownInResponseToProcessControllerSignal, ExitCodes.NORMAL); } else { SystemExiter.abort(ExitCodes.FAILED);
abort(null); } else { SystemExiter.safeAbort();
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // WFLY-2741 -- DO NOT call context.getServiceRegistry(true) as that will trigger blocking for // service container stability and one use case for this op is to recover from a // messed up service container from a previous op. Instead just ask for authorization. // Note that we already have the exclusive lock, so we are just skipping waiting for stability. // If another op that is a step in a composite step with this op needs to modify the container // it will have to wait for container stability, so skipping this only matters for the case // where this step is the only runtime change. // context.getServiceRegistry(true); AuthorizationResult authorizationResult = context.authorize(operation, EnumSet.of(Action.ActionEffect.WRITE_RUNTIME)); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerLogger.ACCESS_LOGGER.unauthorized(operation.get(OP).asString(), PathAddress.pathAddress(operation.get(OP_ADDR)), authorizationResult.getExplanation()); } SystemExiter.logBeforeExit(new SystemExiter.ExitLogger() { @Override public void logExit() { HostControllerLogger.ROOT_LOGGER.shuttingDownInResponseToManagementRequest(getOperationName(operation)); } }); if (restart) { //Add the exit code so that we get respawned domainController.stopLocalHost(ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT); } else { domainController.stopLocalHost(); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }, OperationContext.Stage.RUNTIME);
SystemExiter.initialize(SystemExiter.Exiter.DEFAULT);
private static void abort(Throwable t) { try { if (t != null) { t.printStackTrace(System.err); } } finally { SystemExiter.exit(ExitCodes.FAILED); } }
/** * Calls {@link #logBeforeExit(ExitLogger)} and then invokes the {@link Exiter}. * @param logger logger the logger. Cannot be {@code null} * @param status the status code to provide to the exiter */ public static void logAndExit(ExitLogger logger, int status) { logBeforeExit(logger); getExiter().exit(status); // If we get here, the exiter didn't really exit. So we // must be embedded or something, or perhaps in a test case // Reset the logged flag so we can log again the next time // someone "exits" logged.set(false); }
public static void safeAbort() { logAndExit(new ExitLogger() { @Override public void logExit() { // no-op } }, 0); }
public static void exit(int status) { getExiter().exit(status); }
/** * Terminates JVM with exit code: 1 - failed termination but not an abort situation. */ private static void fail(){ SystemExiter.abort(ExitCodes.FAILED); }