/subprojects/s4-core/src/main/java/io/s4/core/Server.java

https://github.com/adamwojtuniak/s4-piper · Java · 99 lines · 38 code · 22 blank · 39 comment · 0 complexity · e8719b90cd0582b96f76d96d4ecac1a7 MD5 · raw file

  1. package io.s4.core;
  2. import java.io.File;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import ch.qos.logback.classic.Level;
  6. import com.google.inject.AbstractModule;
  7. import com.google.inject.Guice;
  8. import com.google.inject.Inject;
  9. import com.google.inject.Injector;
  10. import com.google.inject.name.Named;
  11. /**
  12. * The Server instance coordinates activities in a cluster node including
  13. * loading and unloading of applications and instantiating the communication
  14. * layer.
  15. */
  16. class Server {
  17. final private String moduleName;
  18. final private String logLevel;
  19. final private FrameworkLauncher fwkLauncher;
  20. /**
  21. *
  22. */
  23. @Inject
  24. public Server(@Named("comm.module") String moduleName,
  25. @Named("s4.logger_level") String logLevel, FrameworkLauncher fwkLauncher) {
  26. this.moduleName = moduleName;
  27. this.logLevel = logLevel;
  28. this.fwkLauncher = fwkLauncher;
  29. }
  30. private static final Logger logger = LoggerFactory.getLogger(Server.class);
  31. public void start() throws Exception {
  32. /* Set up logger basic configuration. */
  33. ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
  34. .getLogger(Logger.ROOT_LOGGER_NAME);
  35. root.setLevel(Level.toLevel(logLevel));
  36. Injector injector;
  37. AbstractModule module = null;
  38. /* Initialize communication layer module. */
  39. try {
  40. module = (AbstractModule) Class.forName(moduleName).newInstance();
  41. } catch (Exception e) {
  42. logger.error("Unable to instantiate communication layer module.", e);
  43. }
  44. /* After some indirection we get the injector. */
  45. injector = Guice.createInjector(module);
  46. fwkLauncher.launch();
  47. // HERE WE SHOULD LOOP TO CHECK IF WE NEED TO LOAD OR UNLOAD APPS.
  48. logger.trace("Load HelloApp");
  49. /* The root dir for the modules is called "modules". */
  50. // File repoRoot = new File(getClass().getClassLoader()
  51. // .getResource("modules").toURI());
  52. /* Create a module loader using the root. */
  53. // ModuleLoader moduleLoader = new LocalModuleLoader(new File[]
  54. // {repoRoot});
  55. /* Load teh module and run! */
  56. // moduleLoader.loadModule(ModuleIdentifier.fromString("helloapp")).run(new
  57. // String[] {});
  58. // org.jboss.modules.Module mod =
  59. // moduleLoader.loadModule(ModuleIdentifier.fromString("modules.helloapp"));
  60. // System.out.println(mod.toString());
  61. // System.out.println(mod.getClassLoader().toString());
  62. // mod.run(new String[] {});
  63. // /*
  64. // * Create the Event Generator objects using injection. The generators
  65. // * will be serialized and sent to remote hosts.
  66. // */
  67. // List<EventGenerator> generators = injector.getInstance(Key
  68. // .get(new TypeLiteral<List<EventGenerator>>() {
  69. // }));
  70. //
  71. // /*
  72. // * The communicator interface hides the implementation details of how
  73. // * the EventGenerator instance is sent to remote hosts.
  74. // */
  75. // Communicator comm = injector.getInstance(Communicator.class);
  76. }
  77. }