Search in sources :

Example 1 with Extensible

use of com.alipay.sofa.service.api.component.Extensible in project sofa-boot by sofastack.

the class ExtensionComponent method activate.

@Override
public void activate() throws ServiceRuntimeException {
    if (componentStatus != ComponentStatus.RESOLVED) {
        return;
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ComponentName extensionPointComponentName = extension.getTargetComponentName();
    ComponentInfo extensionPointComponentInfo = componentManager.getComponentInfo(extensionPointComponentName);
    if (extensionPointComponentInfo == null || !extensionPointComponentInfo.isActivated()) {
        return;
    }
    loadContributions(((ExtensionPointComponent) extensionPointComponentInfo).getExtensionPoint(), extension);
    Object target = extensionPointComponentInfo.getImplementation().getTarget();
    try {
        if (target instanceof Extensible) {
            ((Extensible) target).registerExtension(extension);
        } else {
            Method method = ReflectionUtils.findMethod(target.getClass(), "registerExtension", Extension.class);
            if (method == null) {
                throw new RuntimeException(ErrorCode.convert("01-01001", target.getClass().getCanonicalName()));
            }
            ReflectionUtils.invokeMethod(method, target, extension);
        }
    } catch (Throwable t) {
        throw new ServiceRuntimeException(ErrorCode.convert("01-01000", extensionPointComponentInfo.getName()), t);
    }
    componentStatus = ComponentStatus.ACTIVATED;
}
Also used : Extensible(com.alipay.sofa.service.api.component.Extensible) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Method(java.lang.reflect.Method) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 2 with Extensible

use of com.alipay.sofa.service.api.component.Extensible in project sofa-boot by alipay.

the class ExtensionComponent method activate.

@Override
public void activate() throws ServiceRuntimeException {
    if (componentStatus != ComponentStatus.RESOLVED) {
        return;
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ComponentName extensionPointComponentName = extension.getTargetComponentName();
    ComponentInfo extensionPointComponentInfo = componentManager.getComponentInfo(extensionPointComponentName);
    if (extensionPointComponentInfo == null || !extensionPointComponentInfo.isActivated()) {
        return;
    }
    loadContributions(((ExtensionPointComponent) extensionPointComponentInfo).getExtensionPoint(), extension);
    Object target = extensionPointComponentInfo.getImplementation().getTarget();
    try {
        if (target instanceof Extensible) {
            ((Extensible) target).registerExtension(extension);
        } else {
            Method method = ReflectionUtils.findMethod(target.getClass(), "registerExtension", Extension.class);
            if (method == null) {
                throw new RuntimeException(ErrorCode.convert("01-01001", target.getClass().getCanonicalName()));
            }
            ReflectionUtils.invokeMethod(method, target, extension);
        }
    } catch (Throwable t) {
        throw new ServiceRuntimeException(ErrorCode.convert("01-01000", extensionPointComponentInfo.getName()), t);
    }
    componentStatus = ComponentStatus.ACTIVATED;
}
Also used : Extensible(com.alipay.sofa.service.api.component.Extensible) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Method(java.lang.reflect.Method) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)2 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 Extensible (com.alipay.sofa.service.api.component.Extensible)2 Method (java.lang.reflect.Method)2