Search in sources :

Example 1 with ComponentRegistry

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);
            }
        }
    }));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) SpringApplication(org.springframework.boot.SpringApplication)

Example 2 with ComponentRegistry

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);
}
Also used : SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) DefaultRegistry(com.ctrip.xpipe.lifecycle.DefaultRegistry)

Example 3 with ComponentRegistry

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;
}
Also used : SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) DefaultRegistry(com.ctrip.xpipe.lifecycle.DefaultRegistry)

Example 4 with ComponentRegistry

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());
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TopElement(com.ctrip.xpipe.api.lifecycle.TopElement) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

ComponentRegistry (com.ctrip.xpipe.api.lifecycle.ComponentRegistry)4 SpringComponentRegistry (com.ctrip.xpipe.lifecycle.SpringComponentRegistry)4 CreatedComponentRedistry (com.ctrip.xpipe.lifecycle.CreatedComponentRedistry)2 DefaultRegistry (com.ctrip.xpipe.lifecycle.DefaultRegistry)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 AbstractTest (com.ctrip.xpipe.AbstractTest)1 Lifecycle (com.ctrip.xpipe.api.lifecycle.Lifecycle)1 TopElement (com.ctrip.xpipe.api.lifecycle.TopElement)1 Test (org.junit.Test)1 SpringApplication (org.springframework.boot.SpringApplication)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1