@@ -116,15 +116,16 @@ public BranchStatus branchCommit(BranchType branchType, String xid, long branchI
116
116
if (targetTCCBean == null || commitMethod == null ) {
117
117
throw new ShouldNeverHappenException (String .format ("TCC resource is not available, resourceId: %s" , resourceId ));
118
118
}
119
+ BusinessActionContext businessActionContext = null ;
119
120
try {
120
121
//BusinessActionContext
121
- BusinessActionContext businessActionContext = BusinessActionContextUtil .getBusinessActionContext (xid , branchId , resourceId ,
122
+ businessActionContext = BusinessActionContextUtil .getBusinessActionContext (xid , branchId , resourceId ,
122
123
applicationData );
123
124
124
125
Object [] args = this .getTwoPhaseCommitArgs (tccResource , businessActionContext );
125
126
//share actionContext implicitly
126
127
BusinessActionContextUtil .setContext (businessActionContext );
127
- doBeforeTccCommit (xid , branchId , tccResource .getActionName ());
128
+ doBeforeTccCommit (xid , branchId , tccResource .getActionName (), businessActionContext );
128
129
Object ret ;
129
130
boolean result ;
130
131
// add idempotent and anti hanging
@@ -153,7 +154,7 @@ public BranchStatus branchCommit(BranchType branchType, String xid, long branchI
153
154
LOGGER .error (msg , ExceptionUtil .unwrap (t ));
154
155
return BranchStatus .PhaseTwo_CommitFailed_Retryable ;
155
156
} finally {
156
- doAfterTccCommit (xid , branchId , tccResource .getActionName ());
157
+ doAfterTccCommit (xid , branchId , tccResource .getActionName (), businessActionContext );
157
158
// clear the action context
158
159
BusinessActionContextUtil .clear ();
159
160
}
@@ -182,14 +183,15 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
182
183
if (targetTCCBean == null || rollbackMethod == null ) {
183
184
throw new ShouldNeverHappenException (String .format ("TCC resource is not available, resourceId: %s" , resourceId ));
184
185
}
186
+ BusinessActionContext businessActionContext = null ;
185
187
try {
186
188
//BusinessActionContext
187
- BusinessActionContext businessActionContext = BusinessActionContextUtil .getBusinessActionContext (xid , branchId , resourceId ,
189
+ businessActionContext = BusinessActionContextUtil .getBusinessActionContext (xid , branchId , resourceId ,
188
190
applicationData );
189
191
Object [] args = this .getTwoPhaseRollbackArgs (tccResource , businessActionContext );
190
192
//share actionContext implicitly
191
193
BusinessActionContextUtil .setContext (businessActionContext );
192
- doBeforeTccRollback (xid , branchId , tccResource .getActionName ());
194
+ doBeforeTccRollback (xid , branchId , tccResource .getActionName (), businessActionContext );
193
195
Object ret ;
194
196
boolean result ;
195
197
// add idempotent and anti hanging
@@ -219,7 +221,7 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
219
221
LOGGER .error (msg , ExceptionUtil .unwrap (t ));
220
222
return BranchStatus .PhaseTwo_RollbackFailed_Retryable ;
221
223
} finally {
222
- doAfterTccRollback (xid , branchId , tccResource .getActionName ());
224
+ doAfterTccRollback (xid , branchId , tccResource .getActionName (), businessActionContext );
223
225
// clear the action context
224
226
BusinessActionContextUtil .clear ();
225
227
}
@@ -230,15 +232,16 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
230
232
* @param xid the xid
231
233
* @param branchId the branchId
232
234
* @param actionName the actionName
235
+ * @param context the business action context
233
236
*/
234
- private void doBeforeTccRollback (String xid , long branchId , String actionName ) {
237
+ private void doBeforeTccRollback (String xid , long branchId , String actionName , BusinessActionContext context ) {
235
238
List <TccHook > hooks = TccHookManager .getHooks ();
236
239
if (hooks .isEmpty ()) {
237
240
return ;
238
241
}
239
242
for (TccHook hook : hooks ) {
240
243
try {
241
- hook .beforeTccRollback (xid , branchId , actionName );
244
+ hook .beforeTccRollback (xid , branchId , actionName , context );
242
245
} catch (Exception e ) {
243
246
LOGGER .error ("Failed execute beforeTccRollback in hook {}" , e .getMessage (), e );
244
247
}
@@ -250,15 +253,16 @@ private void doBeforeTccRollback(String xid, long branchId, String actionName) {
250
253
* @param xid the xid
251
254
* @param branchId the branchId
252
255
* @param actionName the actionName
256
+ * @param context the business action context
253
257
*/
254
- private void doAfterTccRollback (String xid , long branchId , String actionName ) {
258
+ private void doAfterTccRollback (String xid , long branchId , String actionName , BusinessActionContext context ) {
255
259
List <TccHook > hooks = TccHookManager .getHooks ();
256
260
if (hooks .isEmpty ()) {
257
261
return ;
258
262
}
259
263
for (TccHook hook : hooks ) {
260
264
try {
261
- hook .afterTccRollback (xid , branchId , actionName );
265
+ hook .afterTccRollback (xid , branchId , actionName , context );
262
266
} catch (Exception e ) {
263
267
LOGGER .error ("Failed execute afterTccRollback in hook {}" , e .getMessage (), e );
264
268
}
@@ -270,15 +274,16 @@ private void doAfterTccRollback(String xid, long branchId, String actionName) {
270
274
* @param xid the xid
271
275
* @param branchId the branchId
272
276
* @param actionName the actionName
277
+ * @param context the business action context
273
278
*/
274
- private void doBeforeTccCommit (String xid , long branchId , String actionName ) {
279
+ private void doBeforeTccCommit (String xid , long branchId , String actionName , BusinessActionContext context ) {
275
280
List <TccHook > hooks = TccHookManager .getHooks ();
276
281
if (hooks .isEmpty ()) {
277
282
return ;
278
283
}
279
284
for (TccHook hook : hooks ) {
280
285
try {
281
- hook .beforeTccCommit (xid , branchId , actionName );
286
+ hook .beforeTccCommit (xid , branchId , actionName , context );
282
287
} catch (Exception e ) {
283
288
LOGGER .error ("Failed execute beforeTccCommit in hook {}" , e .getMessage (), e );
284
289
}
@@ -290,15 +295,16 @@ private void doBeforeTccCommit(String xid, long branchId, String actionName) {
290
295
* @param xid the xid
291
296
* @param branchId the branchId
292
297
* @param actionName the actionName
298
+ * @param context the business action context
293
299
*/
294
- private void doAfterTccCommit (String xid , long branchId , String actionName ) {
300
+ private void doAfterTccCommit (String xid , long branchId , String actionName , BusinessActionContext context ) {
295
301
List <TccHook > hooks = TccHookManager .getHooks ();
296
302
if (hooks .isEmpty ()) {
297
303
return ;
298
304
}
299
305
for (TccHook hook : hooks ) {
300
306
try {
301
- hook .afterTccCommit (xid , branchId , actionName );
307
+ hook .afterTccCommit (xid , branchId , actionName , context );
302
308
} catch (Exception e ) {
303
309
LOGGER .error ("Failed execute afterTccCommit in hook {}" , e .getMessage (), e );
304
310
}
0 commit comments