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);
}
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations