use of com.weibo.api.motan.config.BasicRefererInterfaceConfig in project motan by weibocom.
the class AnnotationBean method refer.
/**
* refer proxy
*
* @param reference
* @param referenceClass
* @param <T>
* @return
*/
private <T> Object refer(MotanReferer reference, Class<?> referenceClass) {
String interfaceName;
if (!void.class.equals(reference.interfaceClass())) {
interfaceName = reference.interfaceClass().getName();
} else if (referenceClass.isInterface()) {
interfaceName = referenceClass.getName();
} else {
throw new IllegalStateException("The @Reference undefined interfaceClass or interfaceName, and the property type " + referenceClass.getName() + " is not a interface.");
}
String key = reference.group() + "/" + interfaceName + ":" + reference.version();
RefererConfigBean<T> referenceConfig = referenceConfigs.get(key);
if (referenceConfig == null) {
referenceConfig = new RefererConfigBean<T>();
referenceConfig.setBeanFactory(beanFactory);
if (void.class.equals(reference.interfaceClass()) && referenceClass.isInterface()) {
referenceConfig.setInterface((Class<T>) referenceClass);
} else if (!void.class.equals(reference.interfaceClass())) {
referenceConfig.setInterface((Class<T>) reference.interfaceClass());
}
if (beanFactory != null) {
if (reference.protocol() != null && reference.protocol().length() > 0) {
//多个PROTOCOL
List<ProtocolConfig> protocolConfigs = SpringBeanUtil.getMultiBeans(beanFactory, reference.protocol(), SpringBeanUtil.COMMA_SPLIT_PATTERN, ProtocolConfig.class);
referenceConfig.setProtocols(protocolConfigs);
}
if (reference.directUrl() != null && reference.directUrl().length() > 0) {
referenceConfig.setDirectUrl(reference.directUrl());
}
if (reference.basicReferer() != null && reference.basicReferer().length() > 0) {
BasicRefererInterfaceConfig biConfig = beanFactory.getBean(reference.basicReferer(), BasicRefererInterfaceConfig.class);
if (biConfig != null) {
referenceConfig.setBasicReferer(biConfig);
}
}
if (reference.client() != null && reference.client().length() > 0) {
//TODO?
// referenceConfig.setC(reference.client());
}
if (reference.registry() != null && reference.registry().length() > 0) {
List<RegistryConfig> registryConfigs = SpringBeanUtil.getMultiBeans(beanFactory, reference.registry(), SpringBeanUtil.COMMA_SPLIT_PATTERN, RegistryConfig.class);
referenceConfig.setRegistries(registryConfigs);
}
if (reference.extConfig() != null && reference.extConfig().length() > 0) {
referenceConfig.setExtConfig(beanFactory.getBean(reference.extConfig(), ExtConfig.class));
}
if (reference.application() != null && reference.application().length() > 0) {
referenceConfig.setApplication(reference.application());
}
if (reference.module() != null && reference.module().length() > 0) {
referenceConfig.setModule(reference.module());
}
if (reference.group() != null && reference.group().length() > 0) {
referenceConfig.setGroup(reference.group());
}
if (reference.version() != null && reference.version().length() > 0) {
referenceConfig.setVersion(reference.version());
}
if (reference.proxy() != null && reference.proxy().length() > 0) {
referenceConfig.setProxy(reference.proxy());
}
if (reference.filter() != null && reference.filter().length() > 0) {
referenceConfig.setFilter(reference.filter());
}
if (reference.actives() > 0) {
referenceConfig.setActives(reference.actives());
}
if (reference.async()) {
referenceConfig.setAsync(reference.async());
}
if (reference.mock() != null && reference.mock().length() > 0) {
referenceConfig.setMock(reference.mock());
}
if (reference.shareChannel()) {
referenceConfig.setShareChannel(reference.shareChannel());
}
// if throw exception when call failure,the default value is ture
if (reference.throwException()) {
referenceConfig.setThrowException(reference.throwException());
}
if (reference.requestTimeout() > 0) {
referenceConfig.setRequestTimeout(reference.requestTimeout());
}
if (reference.register()) {
referenceConfig.setRegister(reference.register());
}
if (reference.accessLog()) {
referenceConfig.setAccessLog("true");
}
if (reference.check()) {
referenceConfig.setCheck("true");
}
if (reference.retries() > 0) {
referenceConfig.setRetries(reference.retries());
}
if (reference.usegz()) {
referenceConfig.setUsegz(reference.usegz());
}
if (reference.mingzSize() > 0) {
referenceConfig.setMingzSize(reference.mingzSize());
}
if (reference.codec() != null && reference.codec().length() > 0) {
referenceConfig.setCodec(reference.codec());
}
if (reference.mean() != null && reference.mean().length() > 0) {
referenceConfig.setMean(reference.mean());
}
if (reference.p90() != null && reference.p90().length() > 0) {
referenceConfig.setP90(reference.p90());
}
if (reference.p99() != null && reference.p99().length() > 0) {
referenceConfig.setP99(reference.p99());
}
if (reference.p999() != null && reference.p999().length() > 0) {
referenceConfig.setP999(reference.p999());
}
if (reference.errorRate() != null && reference.errorRate().length() > 0) {
referenceConfig.setErrorRate(reference.errorRate());
}
try {
referenceConfig.afterPropertiesSet();
} catch (RuntimeException e) {
throw (RuntimeException) e;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
referenceConfigs.putIfAbsent(key, referenceConfig);
referenceConfig = referenceConfigs.get(key);
}
return referenceConfig.getRef();
}
use of com.weibo.api.motan.config.BasicRefererInterfaceConfig in project motan by weibocom.
the class RefererConfigBean method checkAndConfigBasicConfig.
/**
* 检查并配置basicConfig
*/
private void checkAndConfigBasicConfig() {
if (getBasicReferer() == null) {
if (MotanNamespaceHandler.basicRefererConfigDefineNames.size() == 0) {
if (beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;
String[] basicRefererConfigNames = listableBeanFactory.getBeanNamesForType(BasicRefererInterfaceConfig.class);
MotanNamespaceHandler.basicRefererConfigDefineNames.addAll(Arrays.asList(basicRefererConfigNames));
}
}
for (String name : MotanNamespaceHandler.basicRefererConfigDefineNames) {
BasicRefererInterfaceConfig biConfig = beanFactory.getBean(name, BasicRefererInterfaceConfig.class);
if (biConfig == null) {
continue;
}
if (MotanNamespaceHandler.basicRefererConfigDefineNames.size() == 1) {
setBasicReferer(biConfig);
} else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) {
setBasicReferer(biConfig);
}
}
}
}
Aggregations