当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleInjector类代码示例

本文整理汇总了Java中com.netflix.governator.guice.LifecycleInjector的典型用法代码示例。如果您正苦于以下问题:Java LifecycleInjector类的具体用法?Java LifecycleInjector怎么用?Java LifecycleInjector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LifecycleInjector类属于com.netflix.governator.guice包,在下文中一共展示了LifecycleInjector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
/**
 * Sets the injector wrapped through netflix Governator
 */
private static void prepareInjector() {
    if (!error) {
        injector = LifecycleInjector.builder()
                .withModules(getModules())
                .usingBasePackages(".")
                .build()
                .createInjector();
        
        try {
            injector.getInstance(LifecycleManager.class).start();
        } catch (Exception e) {
            LOG.error("Failed to start Governator LifecycleManager", e);
            error = true;
        } 
    }
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:20,代码来源:Application.java

示例2: main

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public static void main(String args[]) {
    final Logger logger = LoggerFactory.getLogger(Main.class);
    LifecycleInjectorBuilder lifecycleInjectorBuilder = LifecycleInjector.builder().withAdditionalModules(new MainModule());
    new ServiceLoaderSuite().configure(lifecycleInjectorBuilder);
    Injector injector = lifecycleInjectorBuilder.build().createInjector();

    final LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
    try {
        lifecycleManager.start();
    } catch (Exception e) {
        logger.error("Lifecycle Manager could not be started and hence not starting up");
        System.exit(1);
    }


    final PluginManager pluginManager = injector.getInstance(PluginManager.class);
    pluginManager.startPlugins();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            logger.info("Stopping services");
            lifecycleManager.close();
            pluginManager.stopPlugins();
        }
    });
}
 
开发者ID:diptanu,项目名称:Artemis,代码行数:27,代码来源:Main.java

示例3: inject

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
@Test
public void inject() throws Exception {
  Assume.assumeTrue("requires java 8", isJava8());
  // On JDK 9:
  // Caused by: java.lang.ClassNotFoundException: javax.annotation.Resource
  // at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
  // at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
  // at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
  Injector injector = LifecycleInjector.builder()
      .usingBasePackages("com.netflix")
      .build()
      .createInjector();
  LifecycleManager lcMgr = injector.getInstance(LifecycleManager.class);
  lcMgr.start();
  Assert.assertNotNull(injector.getInstance(Plugin.class));
  lcMgr.close();
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:18,代码来源:AutoPluginTest.java

示例4: getInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
@Override
protected Injector getInjector() {
    List<Module> moduleList = new ArrayList<>();
    moduleList.add(new JaxServletModule());
    moduleList.add(new RaigadGuiceModule());
    Injector injector;

    try {
        injector = LifecycleInjector.builder().withModules(moduleList).build().createInjector();
        startJobs(injector);

        LifecycleManager manager = injector.getInstance(LifecycleManager.class);
        manager.start();
    }
    catch (Exception e) {
        logger.error(e.getMessage(),e);
        throw new RuntimeException(e.getMessage(), e);
    }

    return injector;
}
 
开发者ID:Netflix,项目名称:Raigad,代码行数:22,代码来源:InjectedWebListener.java

示例5: run

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public static void run(Class<? extends AbstractModule> moduleClass, String appName) throws Exception {
    Injector injector = LifecycleInjector.builder()
            .withModuleClass(moduleClass)
            .withBootstrapModule(new ConfigModule(appName))
            .usingBasePackages("com.widowcrawler")
            .build()
            .createInjector();

    LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
    lifecycleManager.start();

    Dispatcher dispatcher = injector.getInstance(Dispatcher.class);
    boolean cont = true;

    while (cont) {
        logger.info("Dispatching...");
        cont = dispatcher.dispatch();
    }

    lifecycleManager.close();
}
 
开发者ID:ScottMansfield,项目名称:widow,代码行数:22,代码来源:AppRunner.java

示例6: main

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public static void main(String[] args) throws Exception {


        final Injector injector = LifecycleInjector.builder()
                .withBootstrapModule(new BootstrapModule() {
                    @Override
                    public void configure(BootstrapBinder binder) {
                        try {
                            binder.bindConfigurationProvider().toInstance(getConfigurationProvider());
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                })
                .withModules(new MqttBotModule()).createInjector();

        LifecycleManager manager = injector.getInstance(LifecycleManager.class);
        manager.start();

        final BotController instance = injector.getInstance(BotController.class);

        instance.startAndWait();

    }
 
开发者ID:dobermai,项目名称:mqtt-irc-bot,代码行数:25,代码来源:Main.java

示例7: getInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
@Override
protected Injector getInjector() {
    return LifecycleInjector.builder()
            .withModules(
                new EurekaModule(),
                 new PaasPropertiesModule(),   
                new JerseyServletModule() {
                    @Override
                    protected void configureServlets() {
                        bind(GuiceContainer.class).asEagerSingleton();
                        bind(StaashAdminResourceImpl.class);
                        bind(StaashDataResourceImpl.class);
                        serve("/*").with(GuiceContainer.class);
                    }
                }
            )
            .createInjector();
}
 
开发者ID:Netflix,项目名称:staash,代码行数:19,代码来源:GuiceServletConfig.java

示例8: getInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
@Override
protected Injector getInjector() {
    return LifecycleInjector.builder()
        .withModules(
            new MetaModule(),
            //new EurekaModule(),
            new JerseyServletModule() {
                @Override
                protected void configureServlets() {
                    // Route all requests through GuiceContainer
                    bind(GuiceContainer.class).asEagerSingleton();
                    serve("/*").with(GuiceContainer.class);
                }
            },
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(MetaCassandraBootstrap.class).asEagerSingleton();
                 }
            }
        )
        .createInjector();
}
 
开发者ID:Netflix,项目名称:staash,代码行数:24,代码来源:NewPaasGuiceServletConfig.java

示例9: createInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
private Injector createInjector(final Properties properties) {
    injector = LifecycleInjector
            .builder()
            .withBootstrapModule(
                new BootstrapModule() {
                    @Override
                    public void configure(BootstrapBinder binder) {
                        binder.bindConfigurationProvider().toInstance(
                                new PropertiesConfigurationProvider(properties));
                    }
                }
            )
            .withModules(new SuroClientModule())
            .build().createInjector();
    LifecycleManager manager = injector.getInstance(LifecycleManager.class);

    try {
        manager.start();
    } catch (Exception e) {
        throw new RuntimeException("LifecycleManager cannot start with an exception: " + e.getMessage(), e);
    }
    return injector;
}
 
开发者ID:Netflix,项目名称:suro,代码行数:24,代码来源:SuroClient.java

示例10: setup

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    servers = TestConnectionPool.startServers(3);

    final Properties props = new Properties();
    props.setProperty(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers));
    props.setProperty(ClientConfig.MINIMUM_RECONNECT_TIME_INTERVAL, "1");
    props.setProperty(ClientConfig.RECONNECT_INTERVAL, "1");
    props.setProperty(ClientConfig.RECONNECT_TIME_INTERVAL, "1");
    props.setProperty(ClientConfig.APP, "app");

    injector = LifecycleInjector.builder()
            .withBootstrapModule(new BootstrapModule() {
                @Override
                public void configure(BootstrapBinder binder) {
                    binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props));
                    binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class);
                }
            }).build().createInjector();
    injector.getInstance(LifecycleManager.class).start();
}
 
开发者ID:Netflix,项目名称:suro,代码行数:22,代码来源:TestSyncSuroClient.java

示例11: setupFile

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
private void setupFile(final Properties props, String filePath) throws Exception {
    servers = TestConnectionPool.startServers(3);

    props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers));

    props.put(ClientConfig.ASYNC_FILEQUEUE_PATH, filePath);
    props.put(ClientConfig.ASYNC_QUEUE_TYPE, "file");

    injector = LifecycleInjector.builder()
            .withBootstrapModule(new BootstrapModule() {
                @Override
                public void configure(BootstrapBinder binder) {
                    binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props));
                    binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class);
                }
            }).build().createInjector();
    injector.getInstance(LifecycleManager.class).start();
}
 
开发者ID:Netflix,项目名称:suro,代码行数:19,代码来源:TestAsyncSuroClientWithNonExistentFilePath.java

示例12: setup

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public void setup() throws Exception {
    servers = TestConnectionPool.startServers(1);

    props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers));
    props.put(ClientConfig.CONNECTION_TIMEOUT, Integer.toString(Integer.MAX_VALUE));

    injector = LifecycleInjector.builder()
            .withBootstrapModule(new BootstrapModule() {
                @Override
                public void configure(BootstrapBinder binder) {
                    binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props));
                }
            })
            .withAdditionalModules(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ILoadBalancer.class).to(StaticLoadBalancer.class);
                }
            })
            .build().createInjector();
    injector.getInstance(LifecycleManager.class).start();

    pool = injector.getInstance(ConnectionPool.class);
    assertEquals(pool.getPoolSize(), 1);
}
 
开发者ID:Netflix,项目名称:suro,代码行数:26,代码来源:TestConnectionOutPool.java

示例13: create

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public static void create(AtomicReference<Injector> injector, final Properties properties, Module... modules) throws Exception {
    // Create the injector
    injector.set(LifecycleInjector.builder()
            .withBootstrapModule(
                    new BootstrapModule() {
                        @Override
                        public void configure(BootstrapBinder binder) {
                            binder.bindConfigurationProvider().toInstance(
                                    new PropertiesConfigurationProvider(properties));
                        }
                    }
            )
            .withModules(
                    new RoutingPlugin(),
                    new ServerSinkPlugin(),
                    new SuroInputPlugin(),
                    new SuroDynamicPropertyModule(),
                    new SuroModule(),
                    StatusServer.createJerseyServletModule()
            )
            .withAdditionalModules(modules)
            .build().createInjector());
}
 
开发者ID:Netflix,项目名称:suro,代码行数:24,代码来源:SuroServer.java

示例14: getEurekaClient

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
private EurekaClient getEurekaClient(){
	if (eurekaClient==null){
		LifecycleInjectorBuilder builder = LifecycleInjector.builder();
		Injector injector = builder.build().createInjector();
		eurekaClient = injector.getInstance(EurekaClient.class);
	}
	return eurekaClient;
}
 
开发者ID:diegopacheco,项目名称:Building_Effective_Microservices,代码行数:9,代码来源:BaseRibbonTemplate.java

示例15: lifeCycleInjector

import com.netflix.governator.guice.LifecycleInjector; //导入依赖的package包/类
public static Injector lifeCycleInjector(String secretPath, Map<String, String> variableValues) throws Exception {
    Injector injector = LifecycleInjector.builder().
            withBootstrapModule(bootStrapModule(secretPath, variableValues)).
            withModules(new TestModule()).
            requiringExplicitBindings().
            build().
            createInjector();

    LifecycleManager manager = injector.getInstance(LifecycleManager.class);
    manager.start();
    return injector;
}
 
开发者ID:sheinbergon,项目名称:governator-vault,代码行数:13,代码来源:InitalizationUtils.java


注:本文中的com.netflix.governator.guice.LifecycleInjector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。