1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.transaction; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.cache.lock.NodeLock; |
12 |
| import org.jboss.cache.marshall.MethodCall; |
13 |
| |
14 |
| import javax.transaction.Transaction; |
15 |
| import java.util.Collection; |
16 |
| import java.util.Map; |
17 |
| import java.util.concurrent.ConcurrentHashMap; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| public class TransactionTable |
27 |
| { |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| protected Map<Transaction, GlobalTransaction> tx_map = new ConcurrentHashMap<Transaction, GlobalTransaction>(); |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| protected Map<GlobalTransaction, TransactionEntry> txs = new ConcurrentHashMap<GlobalTransaction, TransactionEntry>(); |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| private static final Log log = LogFactory.getLog(TransactionTable.class); |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
2871
| public TransactionTable()
|
50 |
| { |
51 |
| } |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
101
| public int getNumLocalTransactions()
|
57 |
| { |
58 |
101
| return tx_map.size();
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
102
| public int getNumGlobalTransactions()
|
65 |
| { |
66 |
102
| return txs.size();
|
67 |
| } |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
4069537
| public GlobalTransaction get(Transaction tx)
|
74 |
| { |
75 |
4069524
| if (tx == null)
|
76 |
1083161
| return null;
|
77 |
2986376
| return tx_map.get(tx);
|
78 |
| } |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
1488
| public Transaction getLocalTransaction(GlobalTransaction gtx)
|
91 |
| { |
92 |
1488
| Transaction local_tx;
|
93 |
1488
| GlobalTransaction global_tx;
|
94 |
| |
95 |
1488
| if (gtx == null)
|
96 |
0
| return null;
|
97 |
1488
| for (Map.Entry<Transaction, GlobalTransaction> entry : tx_map.entrySet())
|
98 |
| { |
99 |
811
| local_tx = entry.getKey();
|
100 |
811
| global_tx = entry.getValue();
|
101 |
811
| if (gtx.equals(global_tx))
|
102 |
| { |
103 |
730
| return local_tx;
|
104 |
| } |
105 |
| } |
106 |
758
| return null;
|
107 |
| } |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
1121973
| public void put(Transaction tx, GlobalTransaction gtx)
|
113 |
| { |
114 |
1121973
| if (tx == null)
|
115 |
| { |
116 |
0
| log.error("key (Transaction) is null");
|
117 |
0
| return;
|
118 |
| } |
119 |
1121973
| tx_map.put(tx, gtx);
|
120 |
| } |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
9674373
| public TransactionEntry get(GlobalTransaction gtx)
|
127 |
| { |
128 |
9674373
| return gtx != null ? txs.get(gtx) : null;
|
129 |
| } |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
1121973
| public void put(GlobalTransaction tx, TransactionEntry entry)
|
135 |
| { |
136 |
1121973
| if (tx == null)
|
137 |
| { |
138 |
0
| log.error("key (GlobalTransaction) is null");
|
139 |
0
| return;
|
140 |
| } |
141 |
1121973
| txs.put(tx, entry);
|
142 |
| } |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
1122490
| public TransactionEntry remove(GlobalTransaction tx)
|
148 |
| { |
149 |
1122490
| return txs.remove(tx);
|
150 |
| } |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
1122490
| public GlobalTransaction remove(Transaction tx)
|
156 |
| { |
157 |
1122490
| if (tx == null)
|
158 |
0
| return null;
|
159 |
1122490
| return tx_map.remove(tx);
|
160 |
| } |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
168016
| public void addModification(GlobalTransaction gtx, MethodCall m)
|
166 |
| { |
167 |
168016
| TransactionEntry entry = get(gtx);
|
168 |
168016
| if (entry == null)
|
169 |
| { |
170 |
0
| log.error("transaction not found (gtx=" + gtx + ")");
|
171 |
0
| return;
|
172 |
| } |
173 |
168016
| entry.addModification(m);
|
174 |
| } |
175 |
| |
176 |
41080
| public void addCacheLoaderModification(GlobalTransaction gtx, MethodCall m)
|
177 |
| { |
178 |
41080
| if (m != null)
|
179 |
| { |
180 |
41080
| TransactionEntry entry = get(gtx);
|
181 |
41080
| if (entry == null)
|
182 |
| { |
183 |
0
| log.error("transaction not found (gtx=" + gtx + ")");
|
184 |
0
| return;
|
185 |
| } |
186 |
41080
| entry.addCacheLoaderModification(m);
|
187 |
| } |
188 |
| } |
189 |
| |
190 |
| |
191 |
| |
192 |
| |
193 |
183192
| public void addUndoOperation(GlobalTransaction gtx, MethodCall m)
|
194 |
| { |
195 |
183192
| TransactionEntry entry = get(gtx);
|
196 |
183192
| if (entry == null)
|
197 |
| { |
198 |
2
| log.error("transaction not found (gtx=" + gtx + ")");
|
199 |
2
| return;
|
200 |
| } |
201 |
183190
| entry.addUndoOperation(m);
|
202 |
| } |
203 |
| |
204 |
| |
205 |
| |
206 |
| |
207 |
294779
| public void addLock(GlobalTransaction gtx, NodeLock l)
|
208 |
| { |
209 |
294779
| TransactionEntry entry = get(gtx);
|
210 |
294779
| if (entry == null)
|
211 |
| { |
212 |
0
| log.error("transaction entry not found for (gtx=" + gtx + ")");
|
213 |
0
| return;
|
214 |
| } |
215 |
294779
| entry.addLock(l);
|
216 |
| } |
217 |
| |
218 |
| |
219 |
| |
220 |
| |
221 |
51
| public void addLocks(GlobalTransaction gtx, Collection locks)
|
222 |
| { |
223 |
51
| TransactionEntry entry = get(gtx);
|
224 |
51
| if (entry == null)
|
225 |
| { |
226 |
0
| log.error("transaction entry not found for (gtx=" + gtx + ")");
|
227 |
0
| return;
|
228 |
| } |
229 |
51
| entry.addLocks(locks);
|
230 |
| } |
231 |
| |
232 |
| |
233 |
| |
234 |
| |
235 |
0
| public String toString()
|
236 |
| { |
237 |
0
| StringBuffer sb = new StringBuffer();
|
238 |
0
| sb.append(tx_map.size()).append(" mappings, ");
|
239 |
0
| sb.append(txs.size()).append(" transactions");
|
240 |
0
| return sb.toString();
|
241 |
| } |
242 |
| |
243 |
| |
244 |
| |
245 |
| |
246 |
16
| public String toString(boolean print_details)
|
247 |
| { |
248 |
16
| if (!print_details)
|
249 |
0
| return toString();
|
250 |
16
| StringBuffer sb = new StringBuffer();
|
251 |
16
| sb.append("LocalTransactions: ").append(tx_map.size()).append("\n");
|
252 |
16
| sb.append("GlobalTransactions: ").append(txs.size()).append("\n");
|
253 |
16
| sb.append("tx_map:\n");
|
254 |
16
| for (Map.Entry<Transaction, GlobalTransaction> entry : tx_map.entrySet())
|
255 |
| { |
256 |
12
| sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
|
257 |
| } |
258 |
16
| sb.append("txs:\n");
|
259 |
16
| for (Map.Entry<GlobalTransaction, TransactionEntry> entry : txs.entrySet())
|
260 |
| { |
261 |
12
| sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
|
262 |
| } |
263 |
16
| return sb.toString();
|
264 |
| } |
265 |
| |
266 |
| } |