use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by sofastack.
the class ProviderRegisterProcessorTest method test.
@Test
public void test() {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setRegister(true);
providerRegisterProcessor.processorProvider(providerConfig);
Assert.assertTrue(providerConfig.isRegister());
System.setProperty("sofa.rpc.registry.disablePub", "true");
providerRegisterProcessor.processorProvider(providerConfig);
Assert.assertFalse(providerConfig.isRegister());
System.clearProperty("sofa.rpc.registry.disablePub");
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by sofastack.
the class RpcBindingAdapter method preOutBinding.
/**
* pre out binding
*
* @param contract binding contract
* @param binding binding object
* @param target binding target
* @param sofaRuntimeContext sofa runtime context
*/
@Override
public void preOutBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
ProviderConfigContainer providerConfigContainer = applicationContext.getBean(ProviderConfigContainer.class);
String uniqueName = providerConfigContainer.createUniqueName((Contract) contract, binding);
ProviderConfigHelper providerConfigHelper = applicationContext.getBean(ProviderConfigHelper.class);
ProviderConfig providerConfig = providerConfigHelper.getProviderConfig((Contract) contract, binding, target);
try {
providerConfigContainer.addProviderConfig(uniqueName, providerConfig);
} catch (Exception e) {
throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
}
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.
the class RpcBindingAdapter method preUnoutBinding.
/**
* pre unout binding
*
* @param contract binding contract
* @param binding binding object
* @param target binding target
* @param sofaRuntimeContext sofa runtime context
*/
@Override
public void preUnoutBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
ApplicationContext applicationContext = sofaRuntimeContext.getSofaRuntimeManager().getRootApplicationContext();
ProviderConfigContainer providerConfigContainer = applicationContext.getBean(ProviderConfigContainer.class);
String key = providerConfigContainer.createUniqueName((Contract) contract, binding);
ProviderConfig providerConfig = providerConfigContainer.getProviderConfig(key);
try {
providerConfig.unExport();
} catch (Exception e) {
throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PRE_UNPUBLISH_FAIL), e);
}
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.
the class ProviderConfigHelper method getProviderConfig.
/**
* 获取 ProviderConfig
*
* @param contract the Contract
* @param binding the RpcBinding
* @param target 服务实例
* @return the ProviderConfig
* @throws SofaBootRpcRuntimeException
*/
public ProviderConfig getProviderConfig(Contract contract, RpcBinding binding, Object target) throws SofaBootRpcRuntimeException {
RpcBindingParam param = binding.getRpcBindingParam();
String id = binding.getBeanId();
String interfaceId = contract.getInterfaceType().getName();
Object ref = target;
String uniqueId = contract.getUniqueId();
Integer timeout = param.getTimeout();
Integer weight = param.getWeight();
Integer warmupTime = param.getWarmUpTime();
Integer warmupWeight = param.getWarmUpWeight();
UserThreadPool threadPool = param.getUserThreadPool();
String serialization = param.getSerialization();
List<Filter> filters = param.getFilters();
List<MethodConfig> methodConfigs = convertToMethodConfig(param.getMethodInfos());
ServerConfig serverConfig = serverConfigContainer.getServerConfig(binding.getBindingType().getType());
ProviderConfig providerConfig = new ProviderConfig();
if (StringUtils.hasText(appName)) {
providerConfig.setApplication(new ApplicationConfig().setAppName(appName));
}
if (StringUtils.hasText(id)) {
providerConfig.setId(id);
}
if (StringUtils.hasText(interfaceId)) {
providerConfig.setInterfaceId(interfaceId);
}
if (contract.getInterfaceType() != null) {
providerConfig.setProxyClass(contract.getInterfaceType());
}
if (ref != null) {
providerConfig.setRef(ref);
}
if (StringUtils.hasText(uniqueId)) {
providerConfig.setUniqueId(uniqueId);
}
if (timeout != null) {
providerConfig.setTimeout(timeout);
}
if (weight != null) {
providerConfig.setWeight(weight);
}
if (warmupTime != null) {
providerConfig.setParameter(ProviderInfoAttrs.ATTR_WARMUP_TIME, String.valueOf(warmupTime));
}
if (warmupWeight != null) {
providerConfig.setParameter(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT, String.valueOf(warmupWeight));
}
if (!CollectionUtils.isEmpty(filters)) {
providerConfig.setFilterRef(filters);
}
if (!CollectionUtils.isEmpty(methodConfigs)) {
providerConfig.setMethods(methodConfigs);
}
if (threadPool != null) {
UserThreadPoolManager.registerUserThread(ConfigUniqueNameGenerator.getUniqueName(providerConfig), threadPool);
}
providerConfig.setServer(serverConfig);
String protocol = binding.getBindingType().getType();
// http protocol use default protocol
if (!SofaBootRpcConfigConstants.RPC_PROTOCOL_HTTP.equals(protocol)) {
providerConfig.setBootstrap(protocol);
}
if (StringUtils.hasText(serialization)) {
providerConfig.setSerialization(serialization);
}
if (param.getParameters() != null) {
providerConfig.setParameters(param.getParameters());
}
if (param.getRegistrys() != null && param.getRegistrys().size() > 0) {
List<String> registrys = param.getRegistrys();
for (String registryAlias : registrys) {
RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig(registryAlias);
providerConfig.setRegistry(registryConfig);
}
} else if (registryConfigContainer.isMeshEnabled(protocol)) {
RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_MESH);
providerConfig.setRegistry(registryConfig);
} else {
RegistryConfig registryConfig = registryConfigContainer.getRegistryConfig();
providerConfig.setRegistry(registryConfig);
}
providerConfig.setRegister(false);
return providerConfig;
}
use of com.alipay.sofa.rpc.config.ProviderConfig 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;
}
Aggregations