com.netflix.governator.lifecycle.LifecycleManager Java Examples
The following examples show how to use
com.netflix.governator.lifecycle.LifecycleManager.
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: GuiceServiceLocator.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public void init() { // TODO: this really feels like it should be part of bootstrap, but if that is done // then @WarmUp, @PostConstruct cannot use the ServiceLocator try { LifecycleManager manager = getInstance(LifecycleManager.class); if(manager != null) { LOGGER.info("Starting up all modules..."); try { manager.start(); LOGGER.info("Started up"); } catch(Exception e) { LOGGER.error("Failure to startup the injection context", e); throw new RuntimeException("Failure to startup the injection context", e); } } } catch (Exception ex) { // ignore } }
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: SuroServerExternalResource.java From suro with Apache License 2.0 | 6 votes |
@Override protected void before() throws Exception { statusPort = TestUtils.pickPort(); serverPort = TestUtils.pickPort(); Properties props = new Properties(); props.put("SuroServer.statusServerPort", Integer.toString(statusPort)); props.put("SuroServer.port", Integer.toString(serverPort)); props.put(DynamicPropertySinkConfigurator.SINK_PROPERTY, sinkDesc); props.put(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY, inputConfig); if (mapDesc != null) { props.put(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY, mapDesc); } SuroServer.create(injector, props, new SuroPlugin() { @Override protected void configure() { this.addSinkType("TestSink", TestMessageRouter.TestMessageRouterSink.class); } }); injector.get().getInstance(LifecycleManager.class).start(); injector.get().getInstance(StatusServer.class).waitUntilStarted(); }
Example #7
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 #8
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 #9
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 #10
Source File: TestSuroService.java From suro with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { AtomicReference<Injector> injector = new AtomicReference<Injector>(); Properties properties = new Properties(); properties.setProperty(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY, "{}"); properties.setProperty(DynamicPropertySinkConfigurator.SINK_PROPERTY, "{\n" + " \"default\": {\n" + " \"type\": \"testsuroservice\"\n" + " }\n" + " }\n" + "}"); properties.setProperty(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY, "[\n" + " {\n" + " \"type\": \"testsuroservice\"\n" + " }\n" + "]"); SuroServer.create(injector, properties, new SuroPlugin() { @Override protected void configure() { addInputType("testsuroservice", TestSuroServiceInput.class); addSinkType("testsuroservice", TestSuroServiceSink.class); } }); injector.get().getInstance(LifecycleManager.class).start(); latch.await(5000, TimeUnit.MILLISECONDS); assertTrue(inputOpened.get()); assertTrue(sinkOpened.get()); }
Example #11
Source File: GuiceServiceLocator.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public void destroy() { try { LifecycleManager manager = getInstance(LifecycleManager.class); if(manager != null) { manager.close(); } } catch (Exception ex) { // ignore } }
Example #12
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 #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: AbstractKaryonServer.java From karyon with Apache License 2.0 | 5 votes |
protected void startLifecycleManager() { lifecycleManager = injector.getInstance(LifecycleManager.class); try { lifecycleManager.start(); } catch (Exception e) { throw new RuntimeException(e); // So that this does not pollute the API. } }
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: TestConnectionPool.java From suro with Apache License 2.0 | 5 votes |
@After public void tearDown() throws Exception { shutdownServers(servers); injector.getInstance(LifecycleManager.class).close(); props.clear(); }
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: 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 #23
Source File: TestAsyncSuroClientWithNonExistentFilePath.java From suro with Apache License 2.0 | 5 votes |
@After public void tearDown() throws Exception { FileUtils.deleteDirectory(new File(NON_EXISTENT_PATH)); FileUtils.deleteQuietly(new File(TEMP_FILE)); TestConnectionPool.shutdownServers(servers); injector.getInstance(LifecycleManager.class).close(); assertFalse(String.format("The directory %s should be deleted", NON_EXISTENT_PATH), new File(NON_EXISTENT_PATH).exists()); }
Example #24
Source File: SuroServerExternalResource.java From suro with Apache License 2.0 | 4 votes |
@Override protected void after() { injector.get().getInstance(LifecycleManager.class).close(); }
Example #25
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 #26
Source File: TestAsyncSuroClient.java From suro with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { TestConnectionPool.shutdownServers(servers); injector.getInstance(LifecycleManager.class).close(); }
Example #27
Source File: TestAsyncSuroSender.java From suro with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { TestConnectionPool.shutdownServers(servers); injector.getInstance(LifecycleManager.class).close(); }
Example #28
Source File: TestSyncSuroClient.java From suro with Apache License 2.0 | 4 votes |
@After public void tearDown() throws Exception { TestConnectionPool.shutdownServers(servers); injector.getInstance(LifecycleManager.class).close(); }
Example #29
Source File: SuroClient.java From suro with Apache License 2.0 | 4 votes |
public void shutdown() { injector.getInstance(LifecycleManager.class).close(); }