1 |
| package org.jboss.cache.interceptors; |
2 |
| |
3 |
| import org.jboss.cache.CacheSPI; |
4 |
| import org.jboss.cache.InvocationContext; |
5 |
| import org.jboss.cache.lock.IdentityLock; |
6 |
| import org.jboss.cache.marshall.MethodCall; |
7 |
| |
8 |
| import javax.transaction.Transaction; |
9 |
| import java.util.List; |
10 |
| import java.util.ListIterator; |
11 |
| import java.util.Map; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class UnlockInterceptor extends Interceptor |
21 |
| { |
22 |
| |
23 |
| Map lock_table = null; |
24 |
| boolean trace = log.isTraceEnabled(); |
25 |
| |
26 |
4839
| public void setCache(CacheSPI cache)
|
27 |
| { |
28 |
4839
| super.setCache(cache);
|
29 |
4839
| lock_table = cache.getLockTable();
|
30 |
| } |
31 |
| |
32 |
1566287
| public Object invoke(InvocationContext ctx) throws Throwable
|
33 |
| { |
34 |
1566275
| MethodCall m = ctx.getMethodCall();
|
35 |
1566287
| try
|
36 |
| { |
37 |
1566287
| return super.invoke(ctx);
|
38 |
| } |
39 |
| catch (Throwable th) |
40 |
| { |
41 |
6
| throw th;
|
42 |
| } |
43 |
| finally |
44 |
| { |
45 |
1566287
| if (ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isSuppressLocking())
|
46 |
| { |
47 |
1566276
| Transaction tx = ctx.getTransaction();
|
48 |
1566276
| if (tx != null && isValid(tx))
|
49 |
| { |
50 |
| |
51 |
| } |
52 |
| else |
53 |
| { |
54 |
1148359
| Thread currentThread = Thread.currentThread();
|
55 |
1148359
| List locks = (List) lock_table.get(currentThread);
|
56 |
0
| if (trace) log.trace("Attempting to release locks on current thread. Lock table is " + lock_table);
|
57 |
| |
58 |
1148359
| if (locks != null && locks.size() > 0)
|
59 |
| { |
60 |
1072809
| releaseLocks(locks, currentThread);
|
61 |
1072809
| lock_table.remove(currentThread);
|
62 |
| } |
63 |
| } |
64 |
| } |
65 |
| } |
66 |
| } |
67 |
| |
68 |
1072809
| private void releaseLocks(List locks, Thread currentThread)
|
69 |
| { |
70 |
1072809
| IdentityLock lock;
|
71 |
1072809
| for (ListIterator it = locks.listIterator(locks.size()); it.hasPrevious();)
|
72 |
| { |
73 |
6585184
| lock = (IdentityLock) it.previous();
|
74 |
6585184
| if (trace)
|
75 |
0
| log.trace("releasing lock for " + lock.getFqn() + ": " + lock);
|
76 |
6585184
| lock.release(currentThread);
|
77 |
| } |
78 |
| } |
79 |
| |
80 |
| |
81 |
| } |