1
1
/*
2
2
* MIT License
3
3
*
4
- * Copyright (c) 2022 yedf
4
+ * Copyright (c) 2022 dtm-labs
5
5
*
6
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
* of this software and associated documentation files (the "Software"), to deal
30
30
import pub .dtm .client .constant .ParamFieldConstants ;
31
31
import pub .dtm .client .enums .TransTypeEnum ;
32
32
import pub .dtm .client .exception .FailureException ;
33
- import pub .dtm .client .interfaces .communication . IDtmCommunicationClient ;
33
+ import pub .dtm .client .interfaces .stub . IDtmServerStub ;
34
34
import pub .dtm .client .interfaces .dtm .DtmConsumer ;
35
35
import pub .dtm .client .model .dtm .TransBase ;
36
36
import pub .dtm .client .model .feign .ServiceMessage ;
@@ -68,16 +68,16 @@ public class Tcc extends TransBase {
68
68
/**
69
69
* feign client
70
70
*/
71
- private IDtmCommunicationClient dtmCommunicationClient ;
71
+ private IDtmServerStub dtmServerStub ;
72
72
73
- public Tcc (String gid , IDtmCommunicationClient dtmCommunicationClient ) {
73
+ public Tcc (String gid , IDtmServerStub dtmServerStub ) {
74
74
super (gid , TransTypeEnum .TCC , false );
75
75
this .branchIdGenerator = new BranchIdGenerator (Constants .EMPTY_STRING );
76
- this .dtmCommunicationClient = dtmCommunicationClient ;
76
+ this .dtmServerStub = dtmServerStub ;
77
77
}
78
78
79
- public void setdtmCommunicationClient ( IDtmCommunicationClient dtmCommunicationClient ) {
80
- this .dtmCommunicationClient = dtmCommunicationClient ;
79
+ public void setDtmServerStub ( IDtmServerStub dtmServerStub ) {
80
+ this .dtmServerStub = dtmServerStub ;
81
81
}
82
82
83
83
/**
@@ -89,23 +89,23 @@ public void setdtmCommunicationClient(IDtmCommunicationClient dtmCommunicationCl
89
89
public String tccGlobalTransaction (DtmConsumer <Tcc > consumer ) throws Exception {
90
90
// if tcc's gid is empty, need to request a new gid from dtm svr
91
91
if (StringUtils .isEmpty (this .getGid ())) {
92
- this .setGid (FeignUtils .parseGid (dtmCommunicationClient .newGid ()));
92
+ this .setGid (FeignUtils .parseGid (dtmServerStub .newGid ()));
93
93
}
94
94
log .info ("the tcc transaction's gid is {}" , this .getGid ());
95
95
96
96
OperatorParam operatorParam = new OperatorParam (this .getGid (), TransTypeEnum .TCC );
97
- DtmResponse resp = dtmCommunicationClient .prepare (operatorParam );
97
+ DtmResponse resp = dtmServerStub .prepare (operatorParam );
98
98
log .info ("prepare response: {}" , resp );
99
99
if (!Constants .SUCCESS_RESULT .equals (resp .getDtmResult ())) {
100
100
log .error ("TCC transaction prepare fail. returned dtm_result is: {}, transaction gid: {}" , resp .getDtmResult (), this .getGid ());
101
101
throw new FailureException ("TCC Transaction prepare fail" );
102
102
}
103
103
try {
104
104
consumer .accept (this );
105
- dtmCommunicationClient .submit (operatorParam );
105
+ dtmServerStub .submit (operatorParam );
106
106
} catch (Exception e ) {
107
107
log .error ("TCC transaction submit fail, start abort it. transaction gid: {}" , this .getGid ());
108
- dtmCommunicationClient .abort (operatorParam );
108
+ dtmServerStub .abort (operatorParam );
109
109
throw new FailureException (e );
110
110
}
111
111
return this .getGid ();
@@ -128,7 +128,7 @@ public feign.Response callBranch(Object body, ServiceMessage tryMessage, Service
128
128
129
129
TccOperatorParam operatorParam = new TccOperatorParam (this .getGid (), TransTypeEnum .TCC , branchId , Constants .DEFAULT_STATUS ,
130
130
JsonUtils .toJson (body ), FeignUtils .generatorURI (confirmMessage , false ), FeignUtils .generatorURI (cancelMessage , false ));
131
- DtmResponse resp = dtmCommunicationClient .registerBranch (operatorParam );
131
+ DtmResponse resp = dtmServerStub .registerBranch (operatorParam );
132
132
if (!Constants .SUCCESS_RESULT .equals (resp .getDtmResult ())) {
133
133
log .error ("TCC transaction register branch fail. transaction gid: {}" , this .getGid ());
134
134
throw new FailureException ("TCC Transaction register branch fail" );
@@ -140,7 +140,7 @@ public feign.Response callBranch(Object body, ServiceMessage tryMessage, Service
140
140
paramsMap .put (ParamFieldConstants .BRANCH_ID , branchId );
141
141
paramsMap .put (ParamFieldConstants .OP , OP );
142
142
143
- feign .Response response = dtmCommunicationClient .busiPost (new URI (FeignUtils .generatorURI (tryMessage , true )),
143
+ feign .Response response = dtmServerStub .busiPost (new URI (FeignUtils .generatorURI (tryMessage , true )),
144
144
tryMessage .getPath (), paramsMap , body );
145
145
log .info ("busi post is: {}" , response );
146
146
FeignUtils .checkResult (response );
@@ -163,7 +163,7 @@ public Response callBranch(Object body, String tryUrl, String confirmUrl, String
163
163
164
164
TccOperatorParam operatorParam = new TccOperatorParam (this .getGid (), TransTypeEnum .TCC , branchId , Constants .DEFAULT_STATUS ,
165
165
JsonUtils .toJson (body ), confirmUrl , cancelUrl );
166
- DtmResponse resp = dtmCommunicationClient .registerBranch (operatorParam );
166
+ DtmResponse resp = dtmServerStub .registerBranch (operatorParam );
167
167
if (!Constants .SUCCESS_RESULT .equals (resp .getDtmResult ())) {
168
168
log .error ("TCC transaction register branch fail. transaction gid: {}" , this .getGid ());
169
169
throw new FailureException ("TCC Transaction register branch fail" );
0 commit comments