com.netflix.governator.guice.LifecycleInjector Java Examples
The following examples show how to use
com.netflix.governator.guice.LifecycleInjector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApolloApplication.java From apollo with Apache License 2.0 | 6 votes |
public void start() { try { logger.info("Starting apollo.."); injector = LifecycleInjector.builder().withModules( new ApolloModule(configurationProvider.get()), new ApolloMyBatisModule(configurationProvider.get().getDatabase()) ).build().createInjector(); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); logger.info("Apollo started"); } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: InjectedWebListener.java From Raigad with Apache License 2.0 | 6 votes |
@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; }
Example #3
Source File: GuiceServletConfig.java From staash with Apache License 2.0 | 6 votes |
@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(); }
Example #4
Source File: NewPaasGuiceServletConfig.java From staash with Apache License 2.0 | 6 votes |
@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(); }
Example #5
Source File: SuroServer.java From suro with Apache License 2.0 | 6 votes |
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()); }
Example #6
Source File: GuiceServletConfig.java From staash with Apache License 2.0 | 6 votes |
@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(); }
Example #7
Source File: SuroClient.java From suro with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: TestSyncSuroClient.java From suro with Apache License 2.0 | 6 votes |
@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(); }
Example #9
Source File: TestAsyncSuroSender.java From suro with Apache License 2.0 | 6 votes |
@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(); }
Example #10
Source File: TestAsyncSuroClientWithNonExistentFilePath.java From suro with Apache License 2.0 | 6 votes |
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(); }
Example #11
Source File: Bootstrap.java From arcusplatform with Apache License 2.0 | 6 votes |
public Injector bootstrap() { try { // Construct the injector LifecycleInjectorBuilder builder = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(@Nullable BootstrapBinder binder) { Preconditions.checkNotNull(binder); binder.bindConfigurationProvider().to(AgentConfigurationProvider.class); } }) .withAdditionalBootstrapModules(boostrapModules); builder.withAdditionalModuleClasses(moduleClasses); if(!modules.isEmpty()) { builder.withAdditionalModules(modules); } LifecycleInjector inj = builder.build(); Injector result = inj.createInjector(); LifeCycleService.setState(LifeCycle.STARTING_UP, LifeCycle.STARTED); return result; } catch(Exception ex) { throw new BootException("error bootstrapping", ex); } }
Example #12
Source File: TestConnectionOutPool.java From suro with Apache License 2.0 | 6 votes |
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); }
Example #13
Source File: DIBase.java From EVCache with Apache License 2.0 | 5 votes |
@BeforeSuite public void setupEnv() { Properties props = getProps(); try { LifecycleInjectorBuilder builder = LifecycleInjector.builder(); builder.withModules( new EurekaClientModule(), new EVCacheModule(), new DIConnectionModule(), new SpectatorModule(), new ArchaiusModule() { protected void configureArchaius() { bindApplicationConfigurationOverride().toInstance(MapConfig.from(props)); }; } ); injector = builder.build().createInjector(); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); injector.getInstance(ApplicationInfoManager.class); final EVCacheModule lib = injector.getInstance(EVCacheModule.class); manager = injector.getInstance(EVCacheClientPoolManager.class); } catch (Throwable e) { e.printStackTrace(); log.error(e.getMessage(), e); } }
Example #14
Source File: TestAsyncSuroClient.java From suro with Apache License 2.0 | 5 votes |
private void setupMemory(final Properties props) throws Exception { 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(); }
Example #15
Source File: KaryonTcpModuleTest.java From karyon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { injector = LifecycleInjector.bootstrap(TestableTcpModule.class); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); server = injector.getInstance(RX_SERVERS_KEY).values().iterator().next(); }
Example #16
Source File: KaryonHttpModuleTest.java From karyon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { injector = LifecycleInjector.bootstrap(TestableHttpModule.class); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); server = injector.getInstance(RX_SERVERS_KEY).values().iterator().next(); }
Example #17
Source File: KaryonWebSocketsModuleTest.java From karyon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { injector = LifecycleInjector.bootstrap(TestableWebSocketsModule.class); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); server = injector.getInstance(RX_SERVERS_KEY).values().iterator().next(); }
Example #18
Source File: EmbeddedMiddleTierForTests.java From recipes-rss with Apache License 2.0 | 5 votes |
public void setUp() throws Exception { System.setProperty("archaius.deployment.applicationId", "middletier"); System.setProperty("archaius.deployment.environment", "ci"); Injector injector = LifecycleInjector.builder().withModules(new RSSModule()).createInjector(); LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); middleTierServer = injector.getInstance(MiddleTierServer.class); middleTierServer.start(); }
Example #19
Source File: TestMessageSetProcessor.java From suro with Apache License 2.0 | 5 votes |
private void testQueue(final Properties props) throws Exception { injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); MessageSetProcessor queue = injector.getInstance(MessageSetProcessor.class); assertEquals(queue.getQueueSize(), 0); assertEquals(queue.getStatus(), ServiceStatus.ALIVE); TMessageSet messageSet = TestConnectionPool.createMessageSet(100); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OK); assertEquals(queue.getQueueSize(), 1); assertEquals(queue.poll(1, TimeUnit.MILLISECONDS), messageSet); assertEquals(queue.getQueueSize(), 0); queue.stopTakingTraffic(); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OTHER_ERROR); queue.startTakingTraffic(); assertEquals(queue.getStatus(), ServiceStatus.ALIVE); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OK); injector.getInstance(LifecycleManager.class).close(); }
Example #20
Source File: TestConnectionPool.java From suro with Apache License 2.0 | 5 votes |
private void createInjector() throws Exception { props.put(ClientConfig.LB_SERVER, createConnectionString(servers)); 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(); }
Example #21
Source File: TestAsyncSuroClient.java From suro with Apache License 2.0 | 5 votes |
private void setupFile(final Properties props) throws Exception { props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.put(ClientConfig.ASYNC_FILEQUEUE_PATH, tempDir.newFolder().getAbsolutePath()); 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(); }
Example #22
Source File: PaasGuiceServletConfig.java From staash with Apache License 2.0 | 5 votes |
@Override protected Injector getInjector() { return LifecycleInjector.builder() .withModules( new AbstractModule() { @Override protected void configure() { bind(String.class).annotatedWith(Names.named("groupName")).toInstance("UnitTest1"); bind(String.class).annotatedWith(Names.named("clustername")).toInstance("localhost"); } }, new CassandraPaasModule(), new MetaModule(), //new EurekaModule(), new PaasModule(), 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(); bind(PaasBootstrap.class).asEagerSingleton(); bind(PaasCassandraBootstrap.class).asEagerSingleton(); } } ) .createInjector(); }
Example #23
Source File: Bootstrap.java From arcusplatform with Apache License 2.0 | 5 votes |
public Injector bootstrap() throws BootstrapException { try { final Properties merged = mergeProperties(); LifecycleInjectorBuilder builder = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { Names.bindProperties(binder, merged); binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(merged)); } }) .withAdditionalBootstrapModules(boostrapModules); if(merged.containsKey(PROP_MODULES)) { String [] classnames = StringUtils.split(merged.getProperty(PROP_MODULES)); Set<Class<? extends Module>> modules = classnamesToClasses(Arrays.asList(classnames)); modules.addAll(moduleClasses); builder.withAdditionalModuleClasses(modules); } else if(!moduleClasses.isEmpty()) { builder.withAdditionalModuleClasses(moduleClasses); } if(!modules.isEmpty()) { builder.withAdditionalModules(modules); } return builder.build().createInjector(); } catch(Exception e) { throw new BootstrapException("Error bootstrapping the injection context", e); } }
Example #24
Source File: TestInputManager.java From suro with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { int statusPort = TestUtils.pickPort(); int serverPort = TestUtils.pickPort(); final Properties props = new Properties(); props.put("SuroServer.statusServerPort", Integer.toString(statusPort)); props.put("SuroServer.port", Integer.toString(serverPort)); Injector injector = LifecycleInjector.builder().withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); } }).withModules( new SuroInputPlugin(), new AbstractModule() { @Override protected void configure() { bind(ObjectMapper.class).to(DefaultObjectMapper.class); } } ).build().createInjector(); LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); InputManager inputManager = new InputManager(); List<SuroInput> inputList = injector.getInstance(ObjectMapper.class).readValue( inputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); inputList = injector.getInstance(ObjectMapper.class).readValue( addInputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); assertNotNull(inputManager.getInput("kafka_topic-kafka2")); inputList = injector.getInstance(ObjectMapper.class).readValue( inputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); }
Example #25
Source File: MainClassBasedServer.java From karyon with Apache License 2.0 | 4 votes |
@Override protected Injector newInjector(BootstrapModule... applicableBootstrapModules) { return LifecycleInjector.bootstrap(mainClass, applicableBootstrapModules); }