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);
}
}
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;
}
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);
}
}
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;
}
Aggregations