PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/gentoo-console-bootstrap/src/main/java/com/dowdandassociates/gentoo/console/bootstrap/Main.java

https://bitbucket.org/edowd/gentoo_bootstrap_java
Java | 103 lines | 53 code | 18 blank | 32 comment | 3 complexity | 7e60c9aa34f4068ee9ddb7f091dacfb4 MD5 | raw file
  1. /*
  2. *
  3. * Main.java
  4. *
  5. *-----------------------------------------------------------------------------
  6. * Copyright 2013 Dowd and Associates
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *-----------------------------------------------------------------------------
  20. *
  21. */
  22. package com.dowdandassociates.gentoo.console.bootstrap;
  23. import java.util.Properties;
  24. import com.google.inject.Guice;
  25. import com.google.inject.Injector;
  26. import com.netflix.blitz4j.LoggingConfiguration;
  27. import com.netflix.config.DynamicPropertyFactory;
  28. import com.netflix.config.DynamicStringProperty;
  29. import com.netflix.governator.guice.LifecycleInjector;
  30. import com.netflix.governator.lifecycle.LifecycleManager;
  31. import org.slf4j.Logger;
  32. import org.slf4j.LoggerFactory;
  33. import com.dowdandassociates.gentoo.bootstrap.HvmBootstrapModule;
  34. import com.dowdandassociates.gentoo.bootstrap.Hvm1BootstrapModule;
  35. import com.dowdandassociates.gentoo.bootstrap.ParavirtualBootstrapModule;
  36. import com.dowdandassociates.gentoo.bootstrap.Bootstrapper;
  37. public class Main
  38. {
  39. private static Logger log = LoggerFactory.getLogger(Main.class);
  40. public static void main(String[] args)
  41. {
  42. /*
  43. Properties props = new Properties();
  44. props.setProperty("log4j.rootCategory", "DEBUG,stdout");
  45. props.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
  46. props.setProperty("log4j.appender.stdout.layout", "com.netflix.logging.log4jAdapter.NFPatternLayout");
  47. props.setProperty("log4j.appender.stdout.layout.ConversionPattern", "%d %-5p %C:%L [%t] [%M] %m%n");
  48. props.setProperty("log4j.logger.asyncAppenders", "DEBUG,stdout");
  49. LoggingConfiguration.getInstance().configure(props);
  50. */
  51. DynamicStringProperty virtualizationType = DynamicPropertyFactory.getInstance().getStringProperty("com.dowdandassociates.gentoo.bootstrap.Image.virtualizationType", "hvm");
  52. LoggingConfiguration.getInstance().configure();
  53. try
  54. {
  55. // Injector injector = Guice.createInjector(new Amd64MinimalBootstrapModule());
  56. // Injector injector = LifecycleInjector.builder().withBootstrapModule(new GentooBootstrapModule()).createInjector();
  57. Injector injector;
  58. if ("hvm".equals(virtualizationType.get()))
  59. {
  60. injector = LifecycleInjector.builder().withBootstrapModule(new HvmBootstrapModule()).createInjector();
  61. }
  62. else if ("hvm1".equals(virtualizationType.get()))
  63. {
  64. injector = LifecycleInjector.builder().withBootstrapModule(new Hvm1BootstrapModule()).createInjector();
  65. }
  66. else
  67. {
  68. injector = LifecycleInjector.builder().withBootstrapModule(new ParavirtualBootstrapModule()).createInjector();
  69. }
  70. LifecycleManager manager = injector.getInstance(LifecycleManager.class);
  71. manager.start();
  72. Bootstrapper bootstrapper = injector.getInstance(Bootstrapper.class);
  73. bootstrapper.execute();
  74. manager.close();
  75. }
  76. catch (Throwable t)
  77. {
  78. log.error(t.getMessage(), t);
  79. }
  80. finally
  81. {
  82. LoggingConfiguration.getInstance().stop();
  83. }
  84. }
  85. }