PageRenderTime 139ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/embulk-core/src/main/java/org/embulk/EmbulkService.java

https://gitlab.com/CORP-RESELLER/embulk
Java | 76 lines | 63 code | 13 blank | 0 comment | 1 complexity | b626aaac454e82716bc172a10981fc38 MD5 | raw file
  1. package org.embulk;
  2. import java.util.List;
  3. import com.google.common.collect.ImmutableList;
  4. import com.google.inject.Guice;
  5. import com.google.inject.Injector;
  6. import com.google.inject.Module;
  7. import org.embulk.config.ConfigSource;
  8. import org.embulk.exec.SystemConfigModule;
  9. import org.embulk.exec.ExecModule;
  10. import org.embulk.exec.ExtensionServiceLoaderModule;
  11. import org.embulk.plugin.PluginClassLoaderModule;
  12. import org.embulk.plugin.BuiltinPluginSourceModule;
  13. import org.embulk.jruby.JRubyScriptingModule;
  14. import static com.google.common.base.Preconditions.checkState;
  15. @Deprecated
  16. public class EmbulkService
  17. {
  18. private final ConfigSource systemConfig;
  19. protected Injector injector;
  20. private boolean initialized;
  21. public EmbulkService(ConfigSource systemConfig)
  22. {
  23. this.systemConfig = systemConfig;
  24. }
  25. protected Iterable<? extends Module> getAdditionalModules(ConfigSource systemConfig)
  26. {
  27. return ImmutableList.of();
  28. }
  29. protected Iterable<? extends Module> overrideModules(Iterable<? extends Module> modules, ConfigSource systemConfig)
  30. {
  31. return modules;
  32. }
  33. static List<Module> standardModuleList(ConfigSource systemConfig)
  34. {
  35. return ImmutableList.of(
  36. new SystemConfigModule(systemConfig),
  37. new ExecModule(),
  38. new ExtensionServiceLoaderModule(systemConfig),
  39. new PluginClassLoaderModule(systemConfig),
  40. new BuiltinPluginSourceModule(),
  41. new JRubyScriptingModule(systemConfig));
  42. }
  43. public Injector initialize()
  44. {
  45. checkState(!initialized, "Already initialized");
  46. ImmutableList.Builder<Module> builder = ImmutableList.builder();
  47. builder.addAll(standardModuleList(systemConfig));
  48. builder.addAll(getAdditionalModules(systemConfig));
  49. Iterable<? extends Module> modules = builder.build();
  50. modules = overrideModules(modules, systemConfig);
  51. injector = Guice.createInjector(modules);
  52. initialized = true;
  53. return injector;
  54. }
  55. @Deprecated
  56. public synchronized Injector getInjector()
  57. {
  58. if (initialized) {
  59. return injector;
  60. }
  61. return initialize();
  62. }
  63. }