Skip to content

Commit 97e82fc

Browse files
committed
将maxTimeOut放入txManager配置
1 parent e867e8a commit 97e82fc

13 files changed

Lines changed: 77 additions & 12 deletions

File tree

transaction-dubbo/src/main/java/com/codingapi/tx/dubbo/service/impl/TimeOutServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class TimeOutServiceImpl implements TimeOutService {
1818

1919

2020
@Override
21-
public void loadOutTime() {
22-
int timeOut = providerConfig.getTimeout();
23-
Constants.maxOutTime = timeOut;
21+
public void loadOutTime(int timeOut) {
22+
int finalTimeOut = (null != providerConfig.getTimeout()) ? providerConfig.getTimeout() : timeOut;
23+
Constants.maxOutTime = finalTimeOut;
2424
}
2525
}

transaction-motan/src/main/java/com/codingapi/tx/motan/service/impl/TimeOutServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class TimeOutServiceImpl implements TimeOutService {
2020
private BasicServiceConfigBean basicServiceConfigBean;
2121

2222

23-
public void loadOutTime() {
24-
int timeOut = basicServiceConfigBean.getRequestTimeout();
23+
public void loadOutTime(int timeOut) {
24+
int finalTimeOut = (null != basicServiceConfigBean.getRequestTimeout() ? basicServiceConfigBean.getRequestTimeout() : timeOut);
2525
Constants.maxOutTime = timeOut;
2626
}
2727
}

transaction-springcloud/src/main/java/com/codingapi/tx/springcloud/service/impl/TimeOutServiceImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ public class TimeOutServiceImpl implements TimeOutService {
1212

1313

1414
@Override
15-
public void loadOutTime() {
15+
public void loadOutTime(int timeOut) {
1616
//todo 暂时写死
17-
int timeOut = 20*1000;
18-
Constants.maxOutTime = timeOut;
17+
/*int timeOut = 20*1000;
18+
Constants.maxOutTime = timeOut;*/
19+
//从txManager取
20+
if(timeOut < 0){
21+
Constants.maxOutTime = 20*1000;
22+
} else {
23+
Constants.maxOutTime = timeOut*1000;
24+
}
1925
}
2026
}

tx-client/src/main/java/com/codingapi/tx/listener/service/TimeOutService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66
public interface TimeOutService {
77

8-
void loadOutTime();
8+
void loadOutTime(int timeOut);
99
}

tx-client/src/main/java/com/codingapi/tx/listener/service/impl/InitServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void start() {
4141
nettyService.start();
4242
logger.info("socket-start..");
4343

44-
timeOutService.loadOutTime();
44+
//timeOutService.loadOutTime();
4545

4646

4747
}

tx-client/src/main/java/com/codingapi/tx/model/TxServer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class TxServer {
1212
private String host;
1313
private int heart;
1414
private int delay;
15+
private int autoCompensateLimit;
1516

1617
public int getPort() {
1718
return port;
@@ -45,10 +46,18 @@ public int getDelay() {
4546
public void setDelay(int delay) {
4647
this.delay = delay;
4748
}
49+
50+
public int getAutoCompensateLimit() {
51+
return autoCompensateLimit;
52+
}
4853

49-
@Override
54+
public void setAutoCompensateLimit(int autoCompensateLimit) {
55+
this.autoCompensateLimit = autoCompensateLimit;
56+
}
57+
58+
@Override
5059
public String toString() {
51-
return "host:" + host + ",port:" + port + ",heart:" + heart + ",delay:" + delay;
60+
return "host:" + host + ",port:" + port + ",heart:" + heart + ",delay:" + delay + "autoCompensateLimit:" + autoCompensateLimit;
5261
}
5362

5463
public static TxServer parser(String json) {
@@ -59,6 +68,7 @@ public static TxServer parser(String json) {
5968
txServer.setHost(jsonObject.getString("ip"));
6069
txServer.setHeart(jsonObject.getInteger("heart"));
6170
txServer.setDelay(jsonObject.getInteger("delay"));
71+
txServer.setAutoCompensateLimit(jsonObject.getInteger("autoCompensateLimit"));
6272
return txServer;
6373
} catch (Exception e) {
6474
e.printStackTrace();

tx-client/src/main/java/com/codingapi/tx/netty/service/impl/NettyServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.tx.Constants;
44
import com.codingapi.tx.framework.utils.SocketManager;
5+
import com.codingapi.tx.listener.service.TimeOutService;
56
import com.codingapi.tx.netty.handler.TransactionHandler;
67
import com.codingapi.tx.netty.service.NettyControlService;
78
import com.codingapi.tx.netty.service.NettyDistributeService;
@@ -34,6 +35,9 @@ public class NettyServiceImpl implements NettyService {
3435

3536
@Autowired
3637
private NettyControlService nettyControlService;
38+
39+
@Autowired
40+
private TimeOutService timeOutService;
3741

3842
private EventLoopGroup workerGroup;
3943

@@ -55,8 +59,11 @@ public synchronized void start() {
5559
int port = Constants.txServer.getPort();
5660
final int heart = Constants.txServer.getHeart();
5761
int delay = Constants.txServer.getDelay();
62+
int autoCompensateLimit = Constants.txServer.getAutoCompensateLimit();
5863

5964
final TransactionHandler transactionHandler = new TransactionHandler(nettyControlService, delay);
65+
66+
timeOutService.loadOutTime(autoCompensateLimit);
6067
workerGroup = new NioEventLoopGroup();
6168
try {
6269
Bootstrap b = new Bootstrap(); // (1)

tx-manager/src/main/java/com/codingapi/tm/config/ConfigReader.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class ConfigReader {
3535

3636
@Value("${tm.compensate.tryTime}")
3737
private int compensateTryTime;
38+
39+
@Value("${tm.auto.compensate.limit}")
40+
private int autoCompensateLimit;
3841

3942

4043

@@ -97,4 +100,10 @@ public boolean isCompensateAuto() {
97100
public int getCompensateTryTime() {
98101
return compensateTryTime;
99102
}
103+
104+
public int getAutoCompensateLimit() {
105+
return autoCompensateLimit;
106+
}
107+
108+
100109
}

tx-manager/src/main/java/com/codingapi/tm/manager/service/impl/EurekaServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public TxState getState() {
8585
state.setNotifyUrl(configReader.getCompensateNotifyUrl());
8686
state.setCompensate(configReader.isCompensateAuto());
8787
state.setCompensateTryTime(configReader.getCompensateTryTime());
88+
state.setAutoCompensateLimit(configReader.getAutoCompensateLimit());
8889
state.setSlbList(getServices());
8990
return state;
9091
}

tx-manager/src/main/java/com/codingapi/tm/model/TxServer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class TxServer {
99
private int port;
1010
private int heart;
1111
private int delay;
12+
private int autoCompensateLimit;
1213

1314
public static TxServer format(TxState state) {
1415
TxServer txServer = new TxServer();
@@ -52,4 +53,16 @@ public int getDelay() {
5253
public void setDelay(int delay) {
5354
this.delay = delay;
5455
}
56+
57+
58+
public int getAutoCompensateLimit() {
59+
return autoCompensateLimit;
60+
}
61+
62+
63+
public void setAutoCompensateLimit(int autoCompensateLimit) {
64+
this.autoCompensateLimit = autoCompensateLimit;
65+
}
66+
67+
5568
}

0 commit comments

Comments
 (0)