Add block(:Enviroment) method predicated on a Spring Enviornment resolvable property to prevent the Apache Geode Locator (i.e. JVM) from shutting down immediately.

An Apache Geode Locator only creates daemon Threads on startup, which will not prevent the JVM process from falling all the way through and shutting down.
This commit is contained in:
John Blum
2020-03-30 14:56:35 -07:00
parent 7df0a6487e
commit 9b3a77d92f

View File

@@ -15,13 +15,17 @@
*/
package example.app.geode.locator;
import java.util.Scanner;
import org.apache.geode.distributed.Locator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.gemfire.GemFireProperties;
import org.springframework.data.gemfire.config.annotation.LocatorApplication;
import org.springframework.data.gemfire.config.annotation.LocatorConfigurer;
@@ -45,7 +49,11 @@ import org.springframework.data.gemfire.config.annotation.LocatorConfigurer;
public class SpringBootApacheGeodeLocatorApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApacheGeodeLocatorApplication.class, args);
ConfigurableApplicationContext applicationContext =
SpringApplication.run(SpringBootApacheGeodeLocatorApplication.class, args);
block(applicationContext.getEnvironment());
}
@Bean
@@ -56,4 +64,12 @@ public class SpringBootApacheGeodeLocatorApplication {
return (beanName, bean) -> bean.getGemFireProperties()
.setProperty(GemFireProperties.LOCATORS.toString(), locators);
}
private static void block(Environment environment) {
if (environment.getProperty("spring.boot.data.geode.locator.prompt-for-shutdown", Boolean.class, false)) {
System.err.println("Press <ENTER> to exit.");
new Scanner(System.in).nextLine();
}
}
}