Environment

Environment由Reactor的使用者(或者扩展模块,例如:@Spring)来创建和终止的。它自动从META_INF/reactor/reactor-environment.properties路径下读取配置文件。

Properties文件可在运行时被修改,通过提供一个放置于classpath路径下META-INF/reactor中的新Properties文件。

运行时默认配置的切换是通过修改以下的环境变量来实现:reactor.profiles.active。

  1. java - jar reactor-app.jar -Dreactor.profiles.active=turbo

启动和终止Environment

  1. Environment env = Environment.initialize();
  2. //Current registered environment is the same than the one initialized
  3. Assert.isTrue(Environment.get() == env);
  4. //Find a dispatcher named "shared"
  5. Dispatcher d = Environment.dispatcher("shared");
  6. //get the Timer bound to this environment
  7. Timer timer = Environment.timer();
  8. //Shutdown registered Dispatchers and Timers that might run non-daemon threads
  9. Environment.terminate();
  10. //An option could be to register a shutdownHook to automatically invoke terminate.

在一个JVM应用中最好只有一个Environment。大多数情况下可以使用Environment.initializeIfEmpty()