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