org.springframework.boot.ExitCodeGenerator Java Examples

The following examples show how to use org.springframework.boot.ExitCodeGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KillAppAssault.java    From chaos-monkey-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
public void attack() {
  try {
    Logger.info("Chaos Monkey - I am killing your Application!");

    if (metricEventPublisher != null) {
      metricEventPublisher.publishMetricEvent(MetricType.KILLAPP_ASSAULT);
    }

    int exit = SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
    Thread.sleep(5000); // wait before kill to deliver some metrics

    System.exit(exit);
  } catch (Exception e) {
    Logger.info("Chaos Monkey - Unable to kill the App, I am not the BOSS!");
  }
}
 
Example #2
Source File: TestCaseRunner.java    From bugsnag-java with MIT License 6 votes vote down vote up
@Override
public void run(String... args) {
    setupBugsnag();

    // Create and run the test case
    LOGGER.info("Creating test case");
    Scenario scenario = testCaseForName(System.getenv("EVENT_TYPE"));
    if (scenario != null) {
        LOGGER.info("running test case");
        scenario.run();
    } else {
        LOGGER.error("No test case found for " + System.getenv("EVENT_TYPE"));
    }

    // Exit the application
    LOGGER.info("Exiting spring");
    System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) new ExitCodeGenerator() {
        @Override
        public int getExitCode() {
            return 0;
        }
    }));
}
 
Example #3
Source File: TestCaseRunner.java    From bugsnag-java with MIT License 6 votes vote down vote up
@Override
public void run(String... args) {
    // Create and run the test case
    LOGGER.info("Creating test case");
    Scenario scenario = testCaseForName(System.getenv("EVENT_TYPE"));
    if (scenario != null) {
        LOGGER.info("running test case");
        scenario.run();
    } else {
        LOGGER.error("No test case found for " + System.getenv("EVENT_TYPE"));
    }

    // Exit the application
    LOGGER.info("Exiting spring");
    System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) new ExitCodeGenerator() {
        @Override
        public int getExitCode() {
            return 0;
        }
    }));
}
 
Example #4
Source File: Application.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
    if (Arrays.asList(args).contains("execute")) {
        int exitCode = SpringApplication.exit(
                context,
                (ExitCodeGenerator) () -> TestRunnerExitCodeContext.getInstance().getExitCode()
        );
        System.exit(exitCode);
    }
}
 
Example #5
Source File: ExitCodeGeneratorBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public ExitCodeGenerator exitCodeGenerator() {
    System.out.println("ExitCodeGenerator Bean 创建...");
    return () -> {
        System.out.println("执行退出码(88)生成...");
        return 88;
    };
}
 
Example #6
Source File: ExitCodeEventOnExitBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public ExitCodeGenerator exitCodeGenerator() {
    return () -> {
        System.out.println("执行退出码(9)生成...");
        return 9;
    };
}
 
Example #7
Source File: TaskLifecycleListener.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private int calcExitStatus() {
	int exitCode = 0;
	if (this.exitCodeEvent != null) {
		exitCode = this.exitCodeEvent.getExitCode();
	}
	else if (this.listenerFailed || this.applicationFailedException != null) {
		Throwable exception = this.listenerException;
		if (exception instanceof TaskExecutionException) {
			TaskExecutionException taskExecutionException = (TaskExecutionException) exception;
			if (taskExecutionException
					.getCause() instanceof InvocationTargetException) {
				InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException
						.getCause();
				if (invocationTargetException != null
						&& invocationTargetException.getTargetException() != null) {
					exception = invocationTargetException.getTargetException();
				}
			}
		}

		if (exception instanceof ExitCodeGenerator) {
			exitCode = ((ExitCodeGenerator) exception).getExitCode();
		}
		else {
			exitCode = 1;
		}
	}

	return exitCode;
}
 
Example #8
Source File: DataSourceConfig.java    From java-starthere with MIT License 4 votes vote down vote up
@Bean(name = "dsCustom")
public DataSource dataSource()
{
    String myUrlString = "";
    String myDriverClass = "";
    String myDBUser = "";
    String myDBPassword = "";

    String dbValue = env.getProperty("local.run.db");

    if (dbValue.equalsIgnoreCase("POSTGRESQL"))
    {
        checkEnvironmentVariable("MYDBHOST");
        checkEnvironmentVariable("MYDBNAME");
        checkEnvironmentVariable("MYDBUSER");
        checkEnvironmentVariable("MYDBPASSWORD");

        if (stop)
        {
            logger.info("Manually shutting down system");
            int exitCode = SpringApplication.exit(appContext,
                                                  (ExitCodeGenerator) () -> 1);
            System.exit(exitCode);
        }

        myUrlString = "jdbc:postgresql://" + System.getenv("MYDBHOST") + ":5432/" + System.getenv("MYDBNAME");
        myDriverClass = "org.postgresql.Driver";
        myDBUser = System.getenv("MYDBUSER");
        myDBPassword = System.getenv("MYDBPASSWORD");
    } else
    {
        // Assumes H2
        myUrlString = "jdbc:h2:mem:testdb";
        myDriverClass = "org.h2.Driver";
        myDBUser = "sa";
        myDBPassword = "";
    }

    logger.info("Database URL is " + myUrlString);
    return DataSourceBuilder.create()
                            .username(myDBUser)
                            .password(myDBPassword)
                            .url(myUrlString)
                            .driverClassName(myDriverClass)
                            .build();
}
 
Example #9
Source File: FlinkExecutor.java    From Flink-Streaming-Spring-Boot with MIT License 4 votes vote down vote up
private void conditionallyExitSpringApp(int exitCode) {
    if (flinkProperties.isTerminate()) {
        log.info("Terminating flink spring application with application code " + exitCode);
        System.exit(SpringApplication.exit(appCtx, (ExitCodeGenerator) () -> exitCode));
    }
}