Search in sources :

Example 1 with SpringContextComponent

use of com.alipay.sofa.runtime.spring.SpringContextComponent in project sofa-boot by sofastack.

the class ComponentManagerImpl method shutdown.

@Override
public void shutdown() {
    if (SofaRuntimeProperties.isSkipAllComponentShutdown(appClassLoader)) {
        return;
    }
    List<ComponentInfo> elems = new ArrayList<>(registry.values());
    // shutdown spring contexts first
    List<ComponentInfo> springContextComponents = elems.stream().filter(componentInfo -> componentInfo instanceof SpringContextComponent).collect(Collectors.toList());
    for (ComponentInfo ri : springContextComponents) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    if (!springContextComponents.isEmpty()) {
        elems.removeAll(springContextComponents);
    }
    if (SofaRuntimeProperties.isSkipCommonComponentShutdown(appClassLoader)) {
        return;
    }
    // shutdown remaining components
    for (ComponentInfo ri : elems) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    try {
        if (registry != null) {
            registry.clear();
        }
        if (resolvedRegistry != null) {
            resolvedRegistry.clear();
        }
        clientFactoryInternal = null;
    } catch (Throwable t) {
        SofaLogger.error(ErrorCode.convert("01-03000"), t);
    }
}
Also used : ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) Collection(java.util.Collection) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) HashMap(java.util.HashMap) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentStatus(com.alipay.sofa.runtime.model.ComponentStatus) ComponentType(com.alipay.sofa.runtime.model.ComponentType) Map(java.util.Map) SofaLogger(com.alipay.sofa.runtime.log.SofaLogger) ErrorCode(com.alipay.sofa.boot.error.ErrorCode) SofaRuntimeProperties(com.alipay.sofa.runtime.SofaRuntimeProperties) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ArrayList(java.util.ArrayList) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent)

Example 2 with SpringContextComponent

use of com.alipay.sofa.runtime.spring.SpringContextComponent in project sofa-boot by alipay.

the class SpringContextInstallStage method publishContextAsSofaComponent.

private void publishContextAsSofaComponent(DeploymentDescriptor deployment, ApplicationRuntimeModel application, ApplicationContext context) {
    ComponentName componentName = ComponentNameFactory.createComponentName(SpringContextComponent.SPRING_COMPONENT_TYPE, deployment.getModuleName());
    Implementation implementation = new SpringContextImplementation(context);
    ComponentInfo componentInfo = new SpringContextComponent(componentName, implementation, application.getSofaRuntimeContext());
    application.getSofaRuntimeContext().getComponentManager().register(componentInfo);
}
Also used : SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation)

Example 3 with SpringContextComponent

use of com.alipay.sofa.runtime.spring.SpringContextComponent in project sofa-boot by alipay.

the class ComponentManagerImpl method shutdown.

@Override
public void shutdown() {
    if (SofaRuntimeProperties.isSkipAllComponentShutdown(appClassLoader)) {
        return;
    }
    List<ComponentInfo> elems = new ArrayList<>(registry.values());
    // shutdown spring contexts first
    List<ComponentInfo> springContextComponents = elems.stream().filter(componentInfo -> componentInfo instanceof SpringContextComponent).collect(Collectors.toList());
    for (ComponentInfo ri : springContextComponents) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    if (!springContextComponents.isEmpty()) {
        elems.removeAll(springContextComponents);
    }
    if (SofaRuntimeProperties.isSkipCommonComponentShutdown(appClassLoader)) {
        return;
    }
    // shutdown remaining components
    for (ComponentInfo ri : elems) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    try {
        if (registry != null) {
            registry.clear();
        }
        if (resolvedRegistry != null) {
            resolvedRegistry.clear();
        }
        clientFactoryInternal = null;
    } catch (Throwable t) {
        SofaLogger.error(ErrorCode.convert("01-03000"), t);
    }
}
Also used : ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) Collection(java.util.Collection) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) HashMap(java.util.HashMap) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentStatus(com.alipay.sofa.runtime.model.ComponentStatus) ComponentType(com.alipay.sofa.runtime.model.ComponentType) Map(java.util.Map) SofaLogger(com.alipay.sofa.runtime.log.SofaLogger) ErrorCode(com.alipay.sofa.boot.error.ErrorCode) SofaRuntimeProperties(com.alipay.sofa.runtime.SofaRuntimeProperties) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ArrayList(java.util.ArrayList) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent)

Example 4 with SpringContextComponent

use of com.alipay.sofa.runtime.spring.SpringContextComponent in project sofa-boot by alipay.

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)

Example 5 with SpringContextComponent

use of com.alipay.sofa.runtime.spring.SpringContextComponent in project sofa-boot by sofastack.

the class SpringContextInstallStage method publishContextAsSofaComponent.

private void publishContextAsSofaComponent(DeploymentDescriptor deployment, ApplicationRuntimeModel application, ApplicationContext context) {
    ComponentName componentName = ComponentNameFactory.createComponentName(SpringContextComponent.SPRING_COMPONENT_TYPE, deployment.getModuleName());
    Implementation implementation = new SpringContextImplementation(context);
    ComponentInfo componentInfo = new SpringContextComponent(componentName, implementation, application.getSofaRuntimeContext());
    application.getSofaRuntimeContext().getComponentManager().register(componentInfo);
}
Also used : SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation)

Aggregations

ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)6 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)6 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)6 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)4 SpringContextImplementation (com.alipay.sofa.runtime.spring.SpringContextImplementation)4 ErrorCode (com.alipay.sofa.boot.error.ErrorCode)2 SofaRuntimeProperties (com.alipay.sofa.runtime.SofaRuntimeProperties)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)2 SofaLogger (com.alipay.sofa.runtime.log.SofaLogger)2 ComponentStatus (com.alipay.sofa.runtime.model.ComponentStatus)2 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 ClientFactoryInternal (com.alipay.sofa.runtime.spi.client.ClientFactoryInternal)2 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)2 SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2