1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| package org.jboss.cache.interceptors; |
23 |
| |
24 |
| import org.apache.commons.logging.Log; |
25 |
| import org.apache.commons.logging.LogFactory; |
26 |
| import org.jboss.cache.CacheSPI; |
27 |
| import org.jboss.cache.InvocationContext; |
28 |
| import org.jboss.cache.config.Configuration; |
29 |
| import org.jboss.cache.marshall.MethodCall; |
30 |
| import org.jboss.cache.marshall.MethodDeclarations; |
31 |
| |
32 |
| import javax.transaction.Status; |
33 |
| import javax.transaction.SystemException; |
34 |
| import javax.transaction.Transaction; |
35 |
| import java.util.Collections; |
36 |
| import java.util.Map; |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| public abstract class Interceptor implements InterceptorMBean |
46 |
| { |
47 |
| protected Interceptor next = null, last = null; |
48 |
| protected CacheSPI<?, ?> cache; |
49 |
| protected Log log = null; |
50 |
| protected Configuration configuration; |
51 |
| private boolean statsEnabled = false; |
52 |
| |
53 |
24877
| public Interceptor()
|
54 |
| { |
55 |
24877
| log = LogFactory.getLog(getClass());
|
56 |
| } |
57 |
| |
58 |
22559
| public void setNext(Interceptor i)
|
59 |
| { |
60 |
22559
| next = i;
|
61 |
| } |
62 |
| |
63 |
364908
| public Interceptor getNext()
|
64 |
| { |
65 |
364908
| return next;
|
66 |
| } |
67 |
| |
68 |
49174
| public void setCache(CacheSPI cache)
|
69 |
| { |
70 |
49174
| this.cache = cache;
|
71 |
49174
| this.configuration = cache.getConfiguration();
|
72 |
| } |
73 |
| |
74 |
23925645
| public Object invoke(InvocationContext ctx) throws Throwable
|
75 |
| { |
76 |
23925814
| return next.invoke(ctx);
|
77 |
| } |
78 |
| |
79 |
2656550
| public boolean getStatisticsEnabled()
|
80 |
| { |
81 |
2656550
| return statsEnabled;
|
82 |
| } |
83 |
| |
84 |
24511
| public void setStatisticsEnabled(boolean enabled)
|
85 |
| { |
86 |
24511
| statsEnabled = enabled;
|
87 |
| } |
88 |
| |
89 |
2040
| public Interceptor getLast()
|
90 |
| { |
91 |
2040
| return last;
|
92 |
| } |
93 |
| |
94 |
24603
| public void setLast(Interceptor last)
|
95 |
| { |
96 |
24603
| this.last = last;
|
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
0
| public Map<String, Object> dumpStatistics()
|
104 |
| { |
105 |
0
| return Collections.emptyMap();
|
106 |
| } |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
0
| public void resetStatistics()
|
113 |
| { |
114 |
| } |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
3781440
| protected boolean isActive(Transaction tx)
|
120 |
| { |
121 |
0
| if (tx == null) return false;
|
122 |
3781440
| int status = -1;
|
123 |
3781440
| try
|
124 |
| { |
125 |
3781440
| status = tx.getStatus();
|
126 |
3781440
| return status == Status.STATUS_ACTIVE;
|
127 |
| } |
128 |
| catch (SystemException e) |
129 |
| { |
130 |
0
| log.error("failed getting transaction status", e);
|
131 |
0
| return false;
|
132 |
| } |
133 |
| } |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
272486
| protected boolean isPreparing(Transaction tx)
|
139 |
| { |
140 |
0
| if (tx == null) return false;
|
141 |
272486
| int status = -1;
|
142 |
272486
| try
|
143 |
| { |
144 |
272486
| status = tx.getStatus();
|
145 |
272486
| return status == Status.STATUS_PREPARING;
|
146 |
| } |
147 |
| catch (SystemException e) |
148 |
| { |
149 |
0
| log.error("failed getting transaction status", e);
|
150 |
0
| return false;
|
151 |
| } |
152 |
| } |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
3776629
| protected boolean isValid(Transaction tx)
|
161 |
| { |
162 |
3776628
| return isActive(tx) || isPreparing(tx);
|
163 |
| } |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
| |
170 |
1585403
| protected boolean isOnePhaseCommitPrepareMehod(MethodCall m)
|
171 |
| { |
172 |
1585403
| switch (m.getMethodId())
|
173 |
| { |
174 |
154609
| case MethodDeclarations.prepareMethod_id:
|
175 |
154609
| return (Boolean) m.getArgs()[3];
|
176 |
60
| case MethodDeclarations.optimisticPrepareMethod_id:
|
177 |
60
| return (Boolean) m.getArgs()[4];
|
178 |
1430734
| default:
|
179 |
1430734
| return false;
|
180 |
| } |
181 |
| } |
182 |
| |
183 |
913
| public String toString()
|
184 |
| { |
185 |
913
| return getClass()
|
186 |
| + "{next: " |
187 |
913
| + (getNext() == null ? null : getNext().getClass())
|
188 |
| + "; last: " |
189 |
913
| + (getLast() == null ? null : getLast().getClass())
|
190 |
| + "}"; |
191 |
| } |
192 |
| } |