22
22
import java .lang .reflect .UndeclaredThrowableException ;
23
23
import java .util .Collections ;
24
24
import java .util .HashMap ;
25
+ import java .util .List ;
25
26
import java .util .Map ;
26
27
27
28
import org .apache .seata .common .Constants ;
32
33
import org .apache .seata .common .util .NetUtil ;
33
34
import org .apache .seata .core .context .RootContext ;
34
35
import org .apache .seata .integration .tx .api .fence .DefaultCommonFenceHandler ;
36
+ import org .apache .seata .integration .tx .api .fence .hook .TccHook ;
37
+ import org .apache .seata .integration .tx .api .fence .hook .TccHookManager ;
35
38
import org .apache .seata .integration .tx .api .util .JsonUtil ;
36
39
import org .apache .seata .rm .DefaultResourceManager ;
37
40
import org .apache .seata .rm .tcc .api .BusinessActionContext ;
@@ -87,7 +90,7 @@ public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBus
87
90
try {
88
91
//share actionContext implicitly
89
92
BusinessActionContextUtil .setContext (actionContext );
90
-
93
+ doBeforeTccPrepare ( xid , branchId , actionName , actionContext );
91
94
if (businessActionParam .getUseCommonFence ()) {
92
95
try {
93
96
// Use common Fence, and return the business result
@@ -105,6 +108,7 @@ public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBus
105
108
}
106
109
} finally {
107
110
try {
111
+ doAfterTccPrepare (xid , branchId , actionName , actionContext );
108
112
//to report business action context finally if the actionContext.getUpdated() is true
109
113
BusinessActionContextUtil .reportContext (actionContext );
110
114
} finally {
@@ -119,6 +123,40 @@ public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBus
119
123
}
120
124
}
121
125
126
+ /**
127
+ * to do some business operations before tcc prepare
128
+ * @param xid the xid
129
+ * @param branchId the branchId
130
+ * @param actionName the actionName
131
+ * @param context the business action context
132
+ */
133
+ private void doBeforeTccPrepare (String xid , String branchId , String actionName , BusinessActionContext context ) {
134
+ List <TccHook > hooks = TccHookManager .getHooks ();
135
+ if (hooks .isEmpty ()) {
136
+ return ;
137
+ }
138
+ for (TccHook hook : hooks ) {
139
+ hook .beforeTccPrepare (xid , Long .valueOf (branchId ), actionName , context );
140
+ }
141
+ }
142
+
143
+ /**
144
+ * to do some business operations after tcc prepare
145
+ * @param xid the xid
146
+ * @param branchId the branchId
147
+ * @param actionName the actionName
148
+ * @param context the business action context
149
+ */
150
+ private void doAfterTccPrepare (String xid , String branchId , String actionName , BusinessActionContext context ) {
151
+ List <TccHook > hooks = TccHookManager .getHooks ();
152
+ if (hooks .isEmpty ()) {
153
+ return ;
154
+ }
155
+ for (TccHook hook : hooks ) {
156
+ hook .afterTccPrepare (xid , Long .valueOf (branchId ), actionName , context );
157
+ }
158
+ }
159
+
122
160
/**
123
161
* Get or create action context, and reset to arguments
124
162
*
0 commit comments