Search in sources :

Example 6 with ComponentInfo

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;
}
Also used : ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 7 with ComponentInfo

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);
}
Also used : ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ServiceImpl(com.alipay.sofa.runtime.service.component.impl.ServiceImpl) Service(com.alipay.sofa.runtime.service.component.Service) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SofaService(com.alipay.sofa.runtime.api.annotation.SofaService) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) SpringImplementationImpl(com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 8 with 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);
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 9 with 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);
        }
    }
}
Also used : Reference(com.alipay.sofa.runtime.service.component.Reference) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Example 10 with ComponentInfo

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);
    }
}
Also used : ComponentType(com.alipay.sofa.runtime.model.ComponentType) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Aggregations

ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)11 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)6 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)4 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 Binding (com.alipay.sofa.runtime.spi.binding.Binding)3 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)3 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)3 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 Service (com.alipay.sofa.runtime.service.component.Service)2 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)2 SofaService (com.alipay.sofa.runtime.api.annotation.SofaService)1 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)1 Property (com.alipay.sofa.runtime.api.component.Property)1 Reference (com.alipay.sofa.runtime.service.component.Reference)1 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)1 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)1 HealthResult (com.alipay.sofa.runtime.spi.health.HealthResult)1 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)1 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)1