Skip to content

Commit b2b89c6

Browse files
authored
Merge pull request #9 from codingapi/tx-lcn-foxdd
Tx lcn foxdd
2 parents 9f08fbf + 97e82fc commit b2b89c6

14 files changed

Lines changed: 90 additions & 25 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/compensate/service/impl/CompensateServiceImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public boolean saveCompensateMsg(TransactionCompensateMsg transactionCompensateM
6767

6868
final String json = JSON.toJSONString(transactionCompensateMsg);
6969

70-
logger.info("补偿->" + json);
70+
logger.info("Compensate->" + json);
7171

7272
final String compensateKey = compensateDao.saveCompensateMsg(transactionCompensateMsg);
7373

@@ -83,9 +83,9 @@ public void run() {
8383
requestJson.put("json", json);
8484

8585
String url = configReader.getCompensateNotifyUrl();
86-
logger.error("补偿回调地址->" + url);
86+
logger.error("Compensate Callback Address->" + url);
8787
String res = HttpUtils.postJson(url, requestJson.toJSONString());
88-
logger.error("补偿回调结果->" + res);
88+
logger.error("Compensate Callback Result->" + res);
8989
if (configReader.isCompensateAuto()) {
9090
//自动补偿,是否自动执行补偿
9191
if (res.contains("success")||res.contains("SUCCESS")) {
@@ -94,7 +94,7 @@ public void run() {
9494
}
9595
}
9696
} catch (Exception e) {
97-
logger.error("补偿回调失败->" + e.getMessage());
97+
logger.error("Compensate Callback Fails->" + e.getMessage());
9898
}
9999
}
100100
});
@@ -109,16 +109,16 @@ public void run() {
109109

110110
public void autoCompensate(final String compensateKey, TransactionCompensateMsg transactionCompensateMsg) {
111111
final String json = JSON.toJSONString(transactionCompensateMsg);
112-
logger.info("自动补偿->" + json);
112+
logger.info("Auto Compensate->" + json);
113113
//自动补偿业务执行...
114114
final int tryTime = configReader.getCompensateTryTime();
115115
boolean autoExecuteRes = false;
116116
try {
117117
int executeCount = 0;
118118
autoExecuteRes = _executeCompensate(json);
119-
logger.info("自动补偿结果->" + autoExecuteRes + ",json->" + json);
119+
logger.info("Automatic Compensate Result->" + autoExecuteRes + ",json->" + json);
120120
while (!autoExecuteRes) {
121-
logger.info("try补偿(补偿失败,进入补偿队列)->" + autoExecuteRes + ",json->" + json);
121+
logger.info("Compensate Failure, Entering Compensate Queue->" + autoExecuteRes + ",json->" + json);
122122
executeCount++;
123123
if(executeCount==3){
124124
autoExecuteRes = false;
@@ -138,7 +138,7 @@ public void autoCompensate(final String compensateKey, TransactionCompensateMsg
138138
}
139139

140140
}catch (Exception e){
141-
logger.error("自动补偿失败,msg:"+e.getLocalizedMessage());
141+
logger.error("Auto Compensate Fails,msg:"+e.getLocalizedMessage());
142142
//推送数据给第三方通知
143143
autoExecuteRes = false;
144144
}
@@ -151,9 +151,9 @@ public void autoCompensate(final String compensateKey, TransactionCompensateMsg
151151
requestJson.put("resState",autoExecuteRes);
152152

153153
String url = configReader.getCompensateNotifyUrl();
154-
logger.error("补偿结果回调地址->" + url);
154+
logger.error("Compensate Result Callback Address->" + url);
155155
String res = HttpUtils.postJson(url, requestJson.toJSONString());
156-
logger.error("补偿结果回调结果->" + res);
156+
logger.error("Compensate Result Callback Result->" + res);
157157

158158
}
159159

@@ -264,7 +264,7 @@ public void reloadCompensate(TxGroup txGroup) {
264264
}
265265
}
266266

267-
logger.info("加载补偿以后->"+JSON.toJSONString(txGroup));
267+
logger.info("Compensate Loaded->"+JSON.toJSONString(txGroup));
268268
}
269269

270270
private TxGroup getCompensateByGroupId(String groupId) {
@@ -283,7 +283,7 @@ public boolean executeCompensate(String path) throws ServiceException {
283283

284284
String json = compensateDao.getCompensate(path);
285285
if (json == null) {
286-
throw new ServiceException("不存在该数据");
286+
throw new ServiceException("no data existing");
287287
}
288288

289289
boolean hasOk = _executeCompensate(json);
@@ -304,7 +304,7 @@ private boolean _executeCompensate(String json) throws ServiceException {
304304

305305
ModelInfo modelInfo = ModelInfoManager.getInstance().getModelByModel(model);
306306
if (modelInfo == null) {
307-
throw new ServiceException("当前模块不在线.");
307+
throw new ServiceException("current model offline.");
308308
}
309309

310310
String data = jsonObject.getString("data");

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
}

0 commit comments

Comments
 (0)