use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.
the class ComponentManagerImpl method _register.
private ComponentInfo _register(ComponentInfo ci) {
ComponentName name = ci.getName();
if (isRegistered(name)) {
SofaLogger.error("Component was already registered: {0}", name);
return getComponentInfo(name);
}
try {
ci.register();
} catch (Exception e) {
SofaLogger.error(e, "Failed to register component: {0}", ci.getName());
return null;
}
SofaLogger.info("Registering component: {0}", ci.getName());
try {
ComponentInfo old = registry.putIfAbsent(ci.getName(), ci);
if (old != null) {
SofaLogger.error("Component was already registered: {0}", name);
return old;
}
if (ci.resolve()) {
_typeRegistry(ci);
ci.activate();
}
} catch (Exception e) {
ci.exception(e);
SofaLogger.error(e, "Failed to create the component {0}", ci.getName());
}
return ci;
}
use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.
the class ServiceAnnotationBeanPostProcessor method processSofaService.
private void processSofaService(Object bean, String beanName) {
final Class<?> beanClass = AopProxyUtils.ultimateTargetClass(bean);
SofaService sofaServiceAnnotation = beanClass.getAnnotation(SofaService.class);
if (sofaServiceAnnotation == null) {
return;
}
Class<?> interfaceType = sofaServiceAnnotation.interfaceType();
if (interfaceType.equals(void.class)) {
Class<?>[] interfaces = beanClass.getInterfaces();
if (interfaces == null || interfaces.length == 0 || interfaces.length > 1) {
throw new ServiceRuntimeException("Bean " + beanName + " does not has any interface or has more than one interface.");
}
interfaceType = interfaces[0];
}
Implementation implementation = new SpringImplementationImpl(beanName, applicationContext);
implementation.setTarget(bean);
Service service = new ServiceImpl(sofaServiceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, bean);
service.addBinding(new JvmBinding());
ComponentInfo componentInfo = new ServiceComponent(implementation, service, sofaRuntimeContext);
sofaRuntimeContext.getComponentManager().register(componentInfo);
}
use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.
the class ServiceFactoryBean method doAfterPropertiesSet.
@Override
protected void doAfterPropertiesSet() throws Exception {
if (hasSofaServiceAnnotation()) {
throw new ServiceRuntimeException("Bean " + beanId + " of type " + ref.getClass() + " has already annotated by @SofaService," + " can not be registered using xml. Please check it.");
}
Implementation implementation = new DefaultImplementation();
implementation.setTarget(ref);
service = buildService();
if (bindings.size() == 0) {
bindings.add(new JvmBinding());
}
for (Binding binding : bindings) {
service.addBinding(binding);
}
ComponentInfo componentInfo = new ServiceComponent(implementation, service, sofaRuntimeContext);
sofaRuntimeContext.getComponentManager().register(componentInfo);
}
use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.
the class ReferenceClientImpl method removeReference.
@Override
public <T> void removeReference(ReferenceParam<T> referenceParam) {
Reference reference = getReferenceFromReferenceParam(referenceParam);
ComponentName referenceComponentName = ComponentNameFactory.createComponentName(ReferenceComponent.REFERENCE_COMPONENT_TYPE, reference.getInterfaceType(), reference.getUniqueId() + "#" + ReferenceRegisterHelper.generateBindingHashCode(reference));
Collection<ComponentInfo> referenceComponents = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
for (ComponentInfo referenceComponent : referenceComponents) {
if (referenceComponent.getName().equals(referenceComponentName)) {
sofaRuntimeContext.getComponentManager().unregister(referenceComponent);
}
}
}
use of com.alipay.sofa.runtime.spi.component.ComponentInfo in project sofa-boot by alipay.
the class ComponentManagerImpl method _typeRegistry.
protected void _typeRegistry(ComponentInfo componentInfo) {
ComponentName name = componentInfo.getName();
if (name != null) {
ComponentType type = name.getType();
Map<ComponentName, ComponentInfo> typesRi = resolvedRegistry.get(type);
if (typesRi == null) {
resolvedRegistry.putIfAbsent(type, new HashMap<ComponentName, ComponentInfo>());
typesRi = resolvedRegistry.get(type);
}
typesRi.put(name, componentInfo);
}
}
Aggregations