Search in sources :

Example 6 with DefaultImplementation

use of com.alipay.sofa.runtime.spi.component.DefaultImplementation 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 7 with DefaultImplementation

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

the class ServiceFactoryBean method doAfterPropertiesSet.

@Override
protected void doAfterPropertiesSet() {
    if (!apiType && hasSofaServiceAnnotation()) {
        throw new ServiceRuntimeException(ErrorCode.convert("01-00103", beanId, ref.getClass()));
    }
    Implementation implementation = new DefaultImplementation();
    implementation.setTarget(ref);
    service = buildService();
    // default add jvm binding and service jvm binding should set serialize as true
    if (bindings.size() == 0) {
        JvmBindingParam jvmBindingParam = new JvmBindingParam().setSerialize(true);
        bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
    }
    for (Binding binding : bindings) {
        service.addBinding(binding);
    }
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, bindingAdapterFactory, sofaRuntimeContext);
    componentInfo.setApplicationContext(applicationContext);
    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) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 8 with DefaultImplementation

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

the class ExtensionClientImpl method publishExtensionPoint.

@Override
public void publishExtensionPoint(ExtensionPointParam extensionPointParam) {
    Assert.notNull(extensionPointParam, "extensionPointParam can not be null.");
    Assert.notNull(extensionPointParam.getName(), "Extension point name can not be null.");
    Assert.notNull(extensionPointParam.getContributionClass(), "Extension point contribution can not be null.");
    Assert.notNull(extensionPointParam.getTarget(), "Extension point target can not be null.");
    ExtensionPoint extensionPoint = new ExtensionPointImpl(extensionPointParam.getName(), extensionPointParam.getContributionClass());
    Implementation implementation = new DefaultImplementation(extensionPointParam.getTargetName());
    implementation.setTarget(extensionPointParam.getTarget());
    ComponentInfo extensionPointComponent = new ExtensionPointComponent(extensionPoint, sofaRuntimeContext, implementation);
    sofaRuntimeContext.getComponentManager().register(extensionPointComponent);
}
Also used : ExtensionPoint(com.alipay.sofa.service.api.component.ExtensionPoint) ExtensionPointImpl(com.alipay.sofa.runtime.ext.component.ExtensionPointImpl) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ExtensionPointComponent(com.alipay.sofa.runtime.ext.component.ExtensionPointComponent) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation)

Example 9 with DefaultImplementation

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

the class ReferenceComponent method activate.

@Override
public void activate() throws ServiceRuntimeException {
    if (reference.hasBinding()) {
        Binding candidate = null;
        Set<Binding> bindings = reference.getBindings();
        if (bindings.size() == 1) {
            candidate = bindings.iterator().next();
        } else if (bindings.size() > 1) {
            Object backupProxy = null;
            for (Binding binding : bindings) {
                if (JvmBinding.JVM_BINDING_TYPE.getType().equals(binding.getName())) {
                    candidate = binding;
                } else {
                    // Under normal RPC reference (local-first/jvm-first is not set to false) binding,
                    // backup proxy is the RPC proxy, which will be invoked if Jvm service is not found
                    backupProxy = createProxy(reference, binding);
                }
            }
            if (candidate != null) {
                ((JvmBinding) candidate).setBackupProxy(backupProxy);
            }
        }
        Object proxy = null;
        if (candidate != null) {
            proxy = createProxy(reference, candidate);
        }
        this.implementation = new DefaultImplementation();
        implementation.setTarget(proxy);
    }
    super.activate();
    latch.countDown();
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation)

Example 10 with DefaultImplementation

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

the class ExtensionClientImpl method publishExtensionPoint.

@Override
public void publishExtensionPoint(ExtensionPointParam extensionPointParam) {
    Assert.notNull(extensionPointParam, "extensionPointParam can not be null.");
    Assert.notNull(extensionPointParam.getName(), "Extension point name can not be null.");
    Assert.notNull(extensionPointParam.getContributionClass(), "Extension point contribution can not be null.");
    Assert.notNull(extensionPointParam.getTarget(), "Extension point target can not be null.");
    ExtensionPoint extensionPoint = new ExtensionPointImpl(extensionPointParam.getName(), extensionPointParam.getContributionClass());
    Implementation implementation = new DefaultImplementation(extensionPointParam.getTargetName());
    implementation.setTarget(extensionPointParam.getTarget());
    ComponentInfo extensionPointComponent = new ExtensionPointComponent(extensionPoint, sofaRuntimeContext, implementation);
    sofaRuntimeContext.getComponentManager().register(extensionPointComponent);
}
Also used : ExtensionPoint(com.alipay.sofa.service.api.component.ExtensionPoint) ExtensionPointImpl(com.alipay.sofa.runtime.ext.component.ExtensionPointImpl) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ExtensionPointComponent(com.alipay.sofa.runtime.ext.component.ExtensionPointComponent) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation)

Aggregations

DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)12 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)10 Binding (com.alipay.sofa.runtime.spi.binding.Binding)10 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)6 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)5 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)4 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)2 ExtensionPointComponent (com.alipay.sofa.runtime.ext.component.ExtensionPointComponent)2 ExtensionPointImpl (com.alipay.sofa.runtime.ext.component.ExtensionPointImpl)2 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)2 Service (com.alipay.sofa.runtime.service.component.Service)2 ServiceImpl (com.alipay.sofa.runtime.service.component.impl.ServiceImpl)2 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)2 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)2 ExtensionPoint (com.alipay.sofa.service.api.component.ExtensionPoint)2