Java Code Examples for org.springframework.boot.ExitCodeGenerator

The following examples show how to use org.springframework.boot.ExitCodeGenerator. These examples are extracted from open source projects. 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 Project: chaos-monkey-spring-boot   Source File: KillAppAssault.java    License: 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 Project: bugsnag-java   Source File: TestCaseRunner.java    License: 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 Project: bugsnag-java   Source File: TestCaseRunner.java    License: 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 Project: AuTe-Framework   Source File: Application.java    License: 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
@Bean
public ExitCodeGenerator exitCodeGenerator() {
    System.out.println("ExitCodeGenerator Bean 创建...");
    return () -> {
        System.out.println("执行退出码(88)生成...");
        return 88;
    };
}
 
Example 6
@Bean
public ExitCodeGenerator exitCodeGenerator() {
    return () -> {
        System.out.println("执行退出码(9)生成...");
        return 9;
    };
}
 
Example 7
Source Project: spring-cloud-task   Source File: TaskLifecycleListener.java    License: 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 Project: java-starthere   Source File: DataSourceConfig.java    License: 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 Project: Flink-Streaming-Spring-Boot   Source File: FlinkExecutor.java    License: 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));
    }
}