Search in sources :

Example 1 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by sofastack.

the class XsdTimeoutTest method testBindingMethod.

/**
 * @see RpcBindingConverter#parseMethod
 */
@Test
public void testBindingMethod() {
    // service
    ServiceComponent component = (ServiceComponent) sofaRuntimeContext.getComponentManager().getComponentInfo(new ComponentName(ServiceComponent.SERVICE_COMPONENT_TYPE, MethodElementInterface.class.getName()));
    RpcBinding binding = (RpcBinding) component.getService().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
    Assert.assertEquals(1, binding.getRpcBindingParam().getMethodInfos().size());
    Assert.assertEquals("service", binding.getRpcBindingParam().getMethodInfos().get(0).getName());
    Assert.assertEquals(10000, binding.getRpcBindingParam().getMethodInfos().get(0).getTimeout().intValue());
    // reference
    Collection<ComponentInfo> componentInfos = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : componentInfos) {
        if (componentInfo instanceof ReferenceComponent) {
            ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
            if (referenceComponent.getReference().getInterfaceType().equals(MethodElementInterface.class)) {
                RpcBinding refBinding = (RpcBinding) referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
                Assert.assertEquals(1, refBinding.getRpcBindingParam().getMethodInfos().size());
                Assert.assertEquals("service", refBinding.getRpcBindingParam().getMethodInfos().get(0).getName());
            }
        }
    }
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent 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 3 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent 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 4 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent 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 5 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent 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)

Aggregations

ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)10 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)6 Binding (com.alipay.sofa.runtime.spi.binding.Binding)6 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 RpcBinding (com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)4 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)4 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)2 SampleService (com.alipay.sofa.runtime.test.beans.facade.SampleService)2 DefaultSampleService (com.alipay.sofa.runtime.test.beans.service.DefaultSampleService)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)1