1 |
| package org.jboss.cache.interceptors; |
2 |
| |
3 |
| import org.jboss.cache.CacheImpl; |
4 |
| import org.jboss.cache.CacheSPI; |
5 |
| import org.jboss.cache.InvocationContext; |
6 |
| import org.jboss.cache.config.Option; |
7 |
| import org.jboss.cache.marshall.MethodCall; |
8 |
| import org.jboss.cache.marshall.MethodDeclarations; |
9 |
| import org.jboss.cache.transaction.GlobalTransaction; |
10 |
| |
11 |
| import javax.transaction.Transaction; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| public class CallInterceptor extends Interceptor |
25 |
| { |
26 |
| private CacheImpl cache; |
27 |
| |
28 |
5678
| public void setCache(CacheSPI cache)
|
29 |
| { |
30 |
5678
| super.setCache(cache);
|
31 |
| } |
32 |
| |
33 |
2854
| public void setTreeCacheInstance(CacheImpl c)
|
34 |
| { |
35 |
2854
| cache = c;
|
36 |
| } |
37 |
| |
38 |
1566988
| public Object invoke(InvocationContext ctx) throws Throwable
|
39 |
| { |
40 |
1566992
| MethodCall m = ctx.getMethodCall();
|
41 |
1566992
| Object retval = null;
|
42 |
| |
43 |
1566992
| if (!MethodDeclarations.isTransactionLifecycleMethod(m.getMethodId()))
|
44 |
| { |
45 |
0
| if (log.isTraceEnabled()) log.trace("Passing up method " + m + " so it gets invoked on cache.");
|
46 |
1430741
| try
|
47 |
| { |
48 |
| |
49 |
1430741
| retval = m.invoke(cache);
|
50 |
| } |
51 |
| catch (Throwable t) |
52 |
| { |
53 |
4
| retval = t;
|
54 |
| } |
55 |
| } |
56 |
| else |
57 |
| { |
58 |
0
| if (log.isTraceEnabled()) log.trace("Suppressing invocation of method " + m + " on cache.");
|
59 |
| } |
60 |
| |
61 |
1566992
| Transaction tx = ctx.getTransaction();
|
62 |
1566992
| if (tx != null && isValid(tx))
|
63 |
| { |
64 |
| |
65 |
418575
| if (retval instanceof Throwable)
|
66 |
| { |
67 |
0
| tx.setRollbackOnly();
|
68 |
| } |
69 |
| else |
70 |
| { |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
418575
| if (!configuration.isNodeLockingOptimistic() && MethodDeclarations.isCrudMethod(m.getMethodId()))
|
77 |
| { |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
166191
| GlobalTransaction gtx = ctx.getGlobalTransaction();
|
83 |
166191
| if (gtx == null)
|
84 |
| { |
85 |
0
| if (log.isDebugEnabled())
|
86 |
| { |
87 |
0
| log.debug("didn't find GlobalTransaction for " + tx + "; won't add modification to transaction list");
|
88 |
| } |
89 |
| } |
90 |
| else |
91 |
| { |
92 |
166191
| Option o = ctx.getOptionOverrides();
|
93 |
166191
| if (o != null && o.isCacheModeLocal())
|
94 |
| { |
95 |
17
| log.debug("Not adding method to modification list since cache mode local is set.");
|
96 |
| } |
97 |
| else |
98 |
| { |
99 |
166174
| cache.getTransactionTable().addModification(gtx, m);
|
100 |
| } |
101 |
166191
| if (cache.getCacheLoaderManager() != null)
|
102 |
40973
| cache.getTransactionTable().addCacheLoaderModification(gtx, m);
|
103 |
| } |
104 |
| } |
105 |
| } |
106 |
| } |
107 |
| |
108 |
1566988
| if (retval instanceof Throwable)
|
109 |
| { |
110 |
4
| throw (Throwable) retval;
|
111 |
| } |
112 |
| |
113 |
1566988
| return retval;
|
114 |
| } |
115 |
| } |