Search in sources :

Example 6 with ComponentManager

use of com.alipay.sofa.runtime.spi.component.ComponentManager in project sofa-boot by sofastack.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, BindingAdapterFactory bindingAdapterFactory, SofaRuntimeContext sofaRuntimeContext, ApplicationContext applicationContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && !SofaRuntimeProperties.isDisableJvmFirst(sofaRuntimeContext) && reference.isJvmFirst()) {
        // as rpc invocation would be serialized, so here would Not ignore serialized
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), bindingAdapterFactory, sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    componentInfo.setApplicationContext(applicationContext);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 7 with ComponentManager

use of com.alipay.sofa.runtime.spi.component.ComponentManager in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, SofaRuntimeContext sofaRuntimeContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (reference.jvmService() && binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE)) {
        throw new ServiceRuntimeException("jvm-service=\"true\" can not be used with JVM binding.");
    }
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && isLocalFirst(reference, sofaRuntimeContext)) {
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 8 with ComponentManager

use of com.alipay.sofa.runtime.spi.component.ComponentManager in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, BindingAdapterFactory bindingAdapterFactory, SofaRuntimeContext sofaRuntimeContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && !SofaRuntimeProperties.isDisableJvmFirst(sofaRuntimeContext) && reference.isJvmFirst()) {
        // as rpc invocation would be serialized, so here would Not ignore serialized
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), bindingAdapterFactory, sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 9 with ComponentManager

use of com.alipay.sofa.runtime.spi.component.ComponentManager in project sofa-boot by alipay.

the class ReferenceRegisterHelper method registerReference.

public static Object registerReference(Reference reference, BindingAdapterFactory bindingAdapterFactory, SofaRuntimeContext sofaRuntimeContext, ApplicationContext applicationContext) {
    Binding binding = (Binding) reference.getBindings().toArray()[0];
    if (!binding.getBindingType().equals(JvmBinding.JVM_BINDING_TYPE) && !SofaRuntimeProperties.isDisableJvmFirst(sofaRuntimeContext) && reference.isJvmFirst()) {
        // as rpc invocation would be serialized, so here would Not ignore serialized
        reference.addBinding(new JvmBinding());
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent referenceComponent = new ReferenceComponent(reference, new DefaultImplementation(), bindingAdapterFactory, sofaRuntimeContext);
    if (componentManager.isRegistered(referenceComponent.getName())) {
        return componentManager.getComponentInfo(referenceComponent.getName()).getImplementation().getTarget();
    }
    ComponentInfo componentInfo = componentManager.registerAndGet(referenceComponent);
    componentInfo.setApplicationContext(applicationContext);
    return componentInfo.getImplementation().getTarget();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 10 with ComponentManager

use of com.alipay.sofa.runtime.spi.component.ComponentManager in project sofa-boot by alipay.

the class ExtensionComponent method resolve.

@Override
public boolean resolve() {
    if (componentStatus != ComponentStatus.REGISTERED) {
        return false;
    }
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ComponentName extensionPointComponentName = extension.getTargetComponentName();
    ComponentInfo extensionPointComponentInfo = componentManager.getComponentInfo(extensionPointComponentName);
    if (extensionPointComponentInfo != null && extensionPointComponentInfo.isActivated()) {
        componentStatus = ComponentStatus.RESOLVED;
        return true;
    }
    return false;
}
Also used : ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Aggregations

ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)31 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)26 Test (org.junit.Test)14 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)6 Binding (com.alipay.sofa.runtime.spi.binding.Binding)4 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)4 SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)4 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)3 ComponentLifeCycle (com.alipay.sofa.runtime.api.component.ComponentLifeCycle)2 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)2 SpringImplementationImpl (com.alipay.sofa.runtime.spi.spring.SpringImplementationImpl)2 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)2 SpringContextImplementation (com.alipay.sofa.runtime.spring.SpringContextImplementation)2 SampleService (com.alipay.sofa.runtime.test.beans.facade.SampleService)2 DefaultSampleService (com.alipay.sofa.runtime.test.beans.service.DefaultSampleService)2