mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1363 : Sync spring-cloud-alibaba-sentinel-datasource module
This commit is contained in:
parent
1d9c1975b2
commit
d11f2a0608
@ -17,6 +17,7 @@
|
|||||||
package com.alibaba.cloud.sentinel.datasource.config;
|
package com.alibaba.cloud.sentinel.datasource.config;
|
||||||
|
|
||||||
import com.alibaba.cloud.sentinel.datasource.factorybean.ConsulDataSourceFactoryBean;
|
import com.alibaba.cloud.sentinel.datasource.factorybean.ConsulDataSourceFactoryBean;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,71 +28,70 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class ConsulDataSourceProperties extends AbstractDataSourceProperties {
|
public class ConsulDataSourceProperties extends AbstractDataSourceProperties {
|
||||||
|
|
||||||
public ConsulDataSourceProperties(){
|
public ConsulDataSourceProperties() {
|
||||||
super(ConsulDataSourceFactoryBean.class.getName());
|
super(ConsulDataSourceFactoryBean.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* consul server host.
|
* consul server host.
|
||||||
*/
|
*/
|
||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* consul server port.
|
* consul server port.
|
||||||
*/
|
*/
|
||||||
private int port=8500;
|
private int port = 8500;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* data key in Redis.
|
* data key in Redis.
|
||||||
*/
|
*/
|
||||||
private String ruleKey;
|
private String ruleKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request of query will hang until timeout (in second) or get updated value.
|
* Request of query will hang until timeout (in second) or get updated value.
|
||||||
*/
|
*/
|
||||||
private int waitTimeoutInSecond = 1;
|
private int waitTimeoutInSecond = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preCheck(String dataSourceName) {
|
public void preCheck(String dataSourceName) {
|
||||||
if(StringUtils.isEmpty(host)){
|
if (StringUtils.isEmpty(host)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("ConsulDataSource server-host is empty");
|
||||||
"ConsulDataSource server-host is empty");
|
}
|
||||||
}
|
if (StringUtils.isEmpty(ruleKey)) {
|
||||||
if(StringUtils.isEmpty(ruleKey)){
|
throw new IllegalArgumentException(
|
||||||
throw new IllegalArgumentException(
|
"ConsulDataSource ruleKey can not be empty");
|
||||||
"ConsulDataSource ruleKey can not be empty");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRuleKey() {
|
public String getRuleKey() {
|
||||||
return ruleKey;
|
return ruleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRuleKey(String ruleKey) {
|
public void setRuleKey(String ruleKey) {
|
||||||
this.ruleKey = ruleKey;
|
this.ruleKey = ruleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWaitTimeoutInSecond() {
|
public int getWaitTimeoutInSecond() {
|
||||||
return waitTimeoutInSecond;
|
return waitTimeoutInSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
||||||
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package com.alibaba.cloud.sentinel.datasource.factorybean;
|
|||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
import com.alibaba.csp.sentinel.datasource.consul.ConsulDataSource;
|
import com.alibaba.csp.sentinel.datasource.consul.ConsulDataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,68 +29,63 @@ import org.springframework.beans.factory.FactoryBean;
|
|||||||
*/
|
*/
|
||||||
public class ConsulDataSourceFactoryBean implements FactoryBean<ConsulDataSource> {
|
public class ConsulDataSourceFactoryBean implements FactoryBean<ConsulDataSource> {
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
|
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private String ruleKey;
|
private String ruleKey;
|
||||||
|
|
||||||
private int waitTimeoutInSecond;
|
private int waitTimeoutInSecond;
|
||||||
|
|
||||||
private Converter converter;
|
private Converter converter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConsulDataSource getObject() throws Exception {
|
public ConsulDataSource getObject() throws Exception {
|
||||||
return new ConsulDataSource(
|
return new ConsulDataSource(host, port, ruleKey, waitTimeoutInSecond, converter);
|
||||||
host,
|
}
|
||||||
port,
|
|
||||||
ruleKey,
|
|
||||||
waitTimeoutInSecond,
|
|
||||||
converter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return ConsulDataSource.class;
|
return ConsulDataSource.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void setPort(int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRuleKey() {
|
public String getRuleKey() {
|
||||||
return ruleKey;
|
return ruleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRuleKey(String ruleKey) {
|
public void setRuleKey(String ruleKey) {
|
||||||
this.ruleKey = ruleKey;
|
this.ruleKey = ruleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWaitTimeoutInSecond() {
|
public int getWaitTimeoutInSecond() {
|
||||||
return waitTimeoutInSecond;
|
return waitTimeoutInSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
||||||
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Converter getConverter() {
|
public Converter getConverter() {
|
||||||
return converter;
|
return converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConverter(Converter converter) {
|
public void setConverter(Converter converter) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user