use of com.ctrip.xpipe.api.lifecycle.ComponentRegistry in project x-pipe by ctripcorp.
the class KeeperContainerApplication method main.
public static void main(String[] args) throws Exception {
SpringApplication application = new SpringApplication(KeeperContainerApplication.class);
application.setRegisterShutdownHook(false);
final ConfigurableApplicationContext context = application.run(args);
final ComponentRegistry registry = initComponentRegistry(context);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
try {
logger.info("[run][shutdown][stop]");
registry.stop();
} catch (Exception e) {
logger.error("[run][shutdown][stop]", e);
}
try {
logger.info("[run][shutdown][dispose]");
registry.dispose();
} catch (Exception e) {
logger.error("[run][shutdown][dispose]", e);
}
try {
logger.info("[run][shutdown][destroy]");
registry.destroy();
} catch (Exception e) {
logger.error("[run][shutdown][destroy]", e);
}
}
}));
}
use of com.ctrip.xpipe.api.lifecycle.ComponentRegistry in project x-pipe by ctripcorp.
the class AppTest method initComponentRegistry.
private void initComponentRegistry(ConfigurableApplicationContext context) throws Exception {
ComponentRegistry registry = new DefaultRegistry(new CreatedComponentRedistry(), new SpringComponentRegistry(context));
registry.initialize();
registry.start();
ComponentRegistryHolder.initializeRegistry(registry);
}
use of com.ctrip.xpipe.api.lifecycle.ComponentRegistry in project x-pipe by ctripcorp.
the class KeeperContainerApplication method initComponentRegistry.
private static ComponentRegistry initComponentRegistry(ConfigurableApplicationContext context) throws Exception {
final ComponentRegistry registry = new DefaultRegistry(new CreatedComponentRedistry(), new SpringComponentRegistry(context));
registry.initialize();
registry.start();
ComponentRegistryHolder.initializeRegistry(registry);
return registry;
}
use of com.ctrip.xpipe.api.lifecycle.ComponentRegistry in project x-pipe by ctripcorp.
the class SpringComponentRegistryTest method test.
@Test
public void test() throws Exception {
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(TestFactory.class);
ComponentRegistry componentRegistry = new SpringComponentRegistry(applicationContext);
componentRegistry.initialize();
componentRegistry.start();
Map<String, Lifecycle> objects = componentRegistry.getComponents(Lifecycle.class);
for (Lifecycle lifecycle : objects.values()) {
if (lifecycle instanceof TopElement) {
Assert.assertTrue(lifecycle.getLifecycleState().isStarted());
} else {
Assert.assertTrue(lifecycle.getLifecycleState().isEmpty());
}
}
}
Aggregations