Search in sources :

Example 1 with TopElement

use of com.ctrip.xpipe.api.lifecycle.TopElement in project x-pipe by ctripcorp.

the class SpringComponentRegistry method lifecycleCallable.

@Override
public List<Lifecycle> lifecycleCallable() {
    List<Lifecycle> result = new LinkedList<>();
    Map<String, Lifecycle> beans = applicationContext.getBeansOfType(Lifecycle.class);
    for (Entry<String, Lifecycle> entry : beans.entrySet()) {
        @SuppressWarnings("unused") String name = entry.getKey();
        Lifecycle bean = entry.getValue();
        if (bean instanceof TopElement) {
            result.add((Lifecycle) bean);
        }
    }
    return sort(result);
}
Also used : TopElement(com.ctrip.xpipe.api.lifecycle.TopElement) Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) LinkedList(java.util.LinkedList)

Example 2 with TopElement

use of com.ctrip.xpipe.api.lifecycle.TopElement 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

Lifecycle (com.ctrip.xpipe.api.lifecycle.Lifecycle)2 TopElement (com.ctrip.xpipe.api.lifecycle.TopElement)2 AbstractTest (com.ctrip.xpipe.AbstractTest)1 ComponentRegistry (com.ctrip.xpipe.api.lifecycle.ComponentRegistry)1 SpringComponentRegistry (com.ctrip.xpipe.lifecycle.SpringComponentRegistry)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1