Search in sources :

Example 1 with ProcessorContainer

use of com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer in project sofa-boot by alipay.

the class RpcBindingAdapter method inBinding.

/**
 * in binding, in binding means reference service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public Object inBinding(Object contract, RpcBinding binding, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ConsumerConfigHelper consumerConfigHelper = applicationContext.getBean(ConsumerConfigHelper.class);
    ConsumerConfigContainer consumerConfigContainer = applicationContext.getBean(ConsumerConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    ConsumerConfig consumerConfig = consumerConfigHelper.getConsumerConfig((Contract) contract, binding);
    processorContainer.processorConsumer(consumerConfig);
    if (MockMode.LOCAL.equalsIgnoreCase(binding.getRpcBindingParam().getMockMode())) {
        consumerConfig.setMockRef(consumerConfigHelper.getMockRef(binding, applicationContext));
    }
    consumerConfigContainer.addConsumerConfig(binding, consumerConfig);
    try {
        Object result = consumerConfig.refer();
        binding.setConsumerConfig(consumerConfig);
        return result;
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_CONSUME_FAIL), e);
    }
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) ApplicationContext(org.springframework.context.ApplicationContext) ConsumerConfigHelper(com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ConsumerConfigContainer(com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 2 with ProcessorContainer

use of com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer in project sofa-boot by alipay.

the class RpcBindingAdapter method outBinding.

/**
 * out binding, out binding means provide service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 * @return binding result
 */
@Override
public Object outBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ProviderConfigContainer providerConfigContainer = applicationContext.getBean(ProviderConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    String uniqueName = providerConfigContainer.createUniqueName((Contract) contract, binding);
    ProviderConfig providerConfig = providerConfigContainer.getProviderConfig(uniqueName);
    processorContainer.processorProvider(providerConfig);
    if (providerConfig == null) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.INFO_SERVICE_METADATA_IS_NULL, uniqueName));
    }
    try {
        providerConfig.export();
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
    }
    if (providerConfigContainer.isAllowPublish()) {
        providerConfig.setRegister(true);
        List<RegistryConfig> registrys = providerConfig.getRegistry();
        for (RegistryConfig registryConfig : registrys) {
            Registry registry = RegistryFactory.getRegistry(registryConfig);
            registry.init();
            registry.start();
            registry.register(providerConfig);
        }
    }
    return Boolean.TRUE;
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ApplicationContext(org.springframework.context.ApplicationContext) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ProviderConfigContainer(com.alipay.sofa.rpc.boot.container.ProviderConfigContainer) Registry(com.alipay.sofa.rpc.registry.Registry) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 3 with ProcessorContainer

use of com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer in project sofa-boot by sofastack.

the class RpcBindingAdapter method inBinding.

/**
 * in binding, in binding means reference service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public Object inBinding(Object contract, RpcBinding binding, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ConsumerConfigHelper consumerConfigHelper = applicationContext.getBean(ConsumerConfigHelper.class);
    ConsumerConfigContainer consumerConfigContainer = applicationContext.getBean(ConsumerConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    ConsumerConfig consumerConfig = consumerConfigHelper.getConsumerConfig((Contract) contract, binding);
    processorContainer.processorConsumer(consumerConfig);
    if (MockMode.LOCAL.equalsIgnoreCase(binding.getRpcBindingParam().getMockMode())) {
        consumerConfig.setMockRef(consumerConfigHelper.getMockRef(binding, applicationContext));
    }
    consumerConfigContainer.addConsumerConfig(binding, consumerConfig);
    try {
        Object result = consumerConfig.refer();
        binding.setConsumerConfig(consumerConfig);
        return result;
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_CONSUME_FAIL), e);
    }
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) ApplicationContext(org.springframework.context.ApplicationContext) ConsumerConfigHelper(com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ConsumerConfigContainer(com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 4 with ProcessorContainer

use of com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer in project sofa-boot by sofastack.

the class RpcBindingAdapter method outBinding.

/**
 * out binding, out binding means provide service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 * @return binding result
 */
@Override
public Object outBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
    ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
    ProviderConfigContainer providerConfigContainer = applicationContext.getBean(ProviderConfigContainer.class);
    ProcessorContainer processorContainer = applicationContext.getBean(ProcessorContainer.class);
    String uniqueName = providerConfigContainer.createUniqueName((Contract) contract, binding);
    ProviderConfig providerConfig = providerConfigContainer.getProviderConfig(uniqueName);
    processorContainer.processorProvider(providerConfig);
    if (providerConfig == null) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.INFO_SERVICE_METADATA_IS_NULL, uniqueName));
    }
    try {
        providerConfig.export();
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
    }
    if (providerConfigContainer.isAllowPublish()) {
        providerConfig.setRegister(true);
        List<RegistryConfig> registrys = providerConfig.getRegistry();
        for (RegistryConfig registryConfig : registrys) {
            Registry registry = RegistryFactory.getRegistry(registryConfig);
            registry.init();
            registry.start();
            registry.register(providerConfig);
        }
    }
    return Boolean.TRUE;
}
Also used : ProcessorContainer(com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer) RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ApplicationContext(org.springframework.context.ApplicationContext) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ProviderConfigContainer(com.alipay.sofa.rpc.boot.container.ProviderConfigContainer) Registry(com.alipay.sofa.rpc.registry.Registry) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Aggregations

ProcessorContainer (com.alipay.sofa.rpc.boot.runtime.adapter.processor.ProcessorContainer)4 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ConsumerConfigContainer (com.alipay.sofa.rpc.boot.container.ConsumerConfigContainer)2 ProviderConfigContainer (com.alipay.sofa.rpc.boot.container.ProviderConfigContainer)2 ConsumerConfigHelper (com.alipay.sofa.rpc.boot.runtime.adapter.helper.ConsumerConfigHelper)2 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)2 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)2 Registry (com.alipay.sofa.rpc.registry.Registry)2