本文整理汇总了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;
}
}
}
示例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();
}
});
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}