Search in sources :

Example 1 with ComponentLifeCycle

use of com.alipay.sofa.runtime.api.component.ComponentLifeCycle in project sofa-boot by alipay.

the class ExtensionPointComponent method deactivate.

@Override
public void deactivate() throws ServiceRuntimeException {
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    for (ComponentInfo componentInfo : componentManager.getComponents()) {
        if (componentInfo.getType().equals(ExtensionComponent.EXTENSION_COMPONENT_TYPE)) {
            ExtensionComponent extensionComponent = (ExtensionComponent) componentInfo;
            if (extensionComponent.getExtension().getTargetComponentName().equals(componentName)) {
                componentManager.unregister(componentInfo);
            }
        }
    }
    if (componentStatus != ComponentStatus.ACTIVATED) {
        return;
    }
    // skip deactivate SpringImplementationImpl because it's already deactivated
    if (this.implementation != null && !(implementation instanceof SpringImplementationImpl)) {
        Object target = this.implementation.getTarget();
        if (target instanceof ComponentLifeCycle) {
            ((ComponentLifeCycle) target).deactivate();
        }
    }
    componentStatus = ComponentStatus.RESOLVED;
}
Also used : ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ComponentLifeCycle(com.alipay.sofa.runtime.api.component.ComponentLifeCycle) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)

Example 2 with ComponentLifeCycle

use of com.alipay.sofa.runtime.api.component.ComponentLifeCycle in project sofa-boot by sofastack.

the class ExtensionPointComponent method deactivate.

@Override
public void deactivate() throws ServiceRuntimeException {
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    for (ComponentInfo componentInfo : componentManager.getComponents()) {
        if (componentInfo.getType().equals(ExtensionComponent.EXTENSION_COMPONENT_TYPE)) {
            ExtensionComponent extensionComponent = (ExtensionComponent) componentInfo;
            if (extensionComponent.getExtension().getTargetComponentName().equals(componentName)) {
                componentManager.unregister(componentInfo);
            }
        }
    }
    if (componentStatus != ComponentStatus.ACTIVATED) {
        return;
    }
    // skip deactivate SpringImplementationImpl because it's already deactivated
    if (this.implementation != null && !(implementation instanceof SpringImplementationImpl)) {
        Object target = this.implementation.getTarget();
        if (target instanceof ComponentLifeCycle) {
            ((ComponentLifeCycle) target).deactivate();
        }
    }
    componentStatus = ComponentStatus.RESOLVED;
}
Also used : ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ComponentLifeCycle(com.alipay.sofa.runtime.api.component.ComponentLifeCycle) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)

Aggregations

ComponentLifeCycle (com.alipay.sofa.runtime.api.component.ComponentLifeCycle)2 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)2 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)2 SpringImplementationImpl (com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)2