Search in sources :

Example 6 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext in project sofa-boot by sofastack.

the class ComponentManagerShutdownTest method initComponentManager.

private ComponentManager initComponentManager() {
    AnnotationConfigApplicationContext rootContext = new AnnotationConfigApplicationContext(ComponentManagerTestConfiguration.class);
    SofaRuntimeContext sofaRuntimeContext = rootContext.getBean(SofaRuntimeContext.class);
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ComponentName serviceComponentName = ComponentNameFactory.createComponentName(SERVICE_COMPONENT_TYPE, SampleService.class, "");
    ComponentInfo serviceComponentInfo = componentManager.getComponentInfo(serviceComponentName);
    componentManager.register(serviceComponentInfo);
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    ComponentName springComponentName = ComponentNameFactory.createComponentName(SPRING_COMPONENT_TYPE, "testModule");
    ComponentInfo springComponentInfo = new SpringContextComponent(springComponentName, new SpringContextImplementation(applicationContext), sofaRuntimeContext);
    applicationContext.refresh();
    componentManager.register(springComponentInfo);
    return componentManager;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) SofaRuntimeContext(com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)

Aggregations

SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)6 ComponentHealthChecker (com.alipay.sofa.healthcheck.impl.ComponentHealthChecker)4 StandardSofaRuntimeManager (com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager)4 SofaRuntimeManager (com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)2 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)2 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)2 SpringContextImplementation (com.alipay.sofa.runtime.spring.SpringContextImplementation)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2