Rev 1312 | Rev 1782 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1312 | Rev 1781 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | 37 | ||
38 | import java.util.ArrayList; |
38 | import java.util.ArrayList; |
39 | 39 | ||
40 | public class TransactionalServiceInvoker extends ServiceInvoker |
40 | public class TransactionalServiceInvoker extends ServiceInvoker |
41 | { |
41 | { |
- | 42 | ||
- | 43 | static boolean debug = false; |
|
- | 44 | ||
- | 45 | //TODO HIPOTESE DE TER AQUI UMA VERIFICACAO DE TRANSACAO CONTIDA |
|
- | 46 | //PROBLEMA E QUE TEMOS DE USAR A THREAD SE POR ALGUMA RAZAO MUDAMOS DE TRANSACTION BROKER |
|
- | 47 | //TUDO ESTRAGADO |
|
- | 48 | //NAO DA ISTO É UM SINGLETON boolean alreadyActive = false; |
|
- | 49 | //TIVEMOS DE TER COMO VAR LOCAL UMA VEZ QUE O InVOCADOR E NUCLEAR |
|
- | 50 | ||
42 | public final static TransactionalServiceInvoker invocador = new TransactionalServiceInvoker(); |
51 | public final static TransactionalServiceInvoker invocador = new TransactionalServiceInvoker(); |
- | 52 | ||
43 | public final 5+0%2Fdocs%2Fapi+Object">Object invoke( |
53 | public final 5+0%2Fdocs%2Fapi+Object">Object invoke( |
44 | 5+0%2Fdocs%2Fapi+Object">Object requester, |
54 | 5+0%2Fdocs%2Fapi+Object">Object requester, |
45 | IService service, |
55 | IService service, |
46 | 1.5.0/docs/api/java/lang/String.html">String methodName, |
56 | 1.5.0/docs/api/java/lang/String.html">String methodName, |
47 | 5+0%2Fdocs%2Fapi+Object">Object arguments[], |
57 | 5+0%2Fdocs%2Fapi+Object">Object arguments[], |
48 | 1.5.0/docs/api/java/lang/String.html">String names[], |
58 | 1.5.0/docs/api/java/lang/String.html">String names[], |
Line 53... | Line 63... | ||
53 | boolean passedPost = false; |
63 | boolean passedPost = false; |
54 | ServiceRequest request = new ServiceRequest(requester, arguments,names,service,methodName); |
64 | ServiceRequest request = new ServiceRequest(requester, arguments,names,service,methodName); |
55 | ServiceResponse response = new ServiceResponse(); |
65 | ServiceResponse response = new ServiceResponse(); |
56 | FilteringResult filteringResult = null; |
66 | FilteringResult filteringResult = null; |
57 | ITransactionBroker tb = BerserkConfiguration.getApplicationTransactionBroker(); |
67 | ITransactionBroker tb = BerserkConfiguration.getApplicationTransactionBroker(); |
- | 68 | boolean alreadyActive = tb.isTransactionActive(); |
|
58 | try |
69 | try |
59 | { |
70 | { |
- | 71 | ||
- | 72 | if(debug) |
|
- | 73 | 1.5.0/docs/api/java/lang/System.html">System.out.println("THREAD:" + 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getId() + "Starting transaction for service: " + service.getClass().getName() + " method:" + methodName); |
|
- | 74 | if(!alreadyActive) |
|
- | 75 | { |
|
60 | tb.beginTransaction(); |
76 | tb.beginTransaction(); |
- | 77 | } |
|
- | 78 | else |
|
- | 79 | { |
|
- | 80 | 1.5.0/docs/api/java/lang/System.html">System.out.println("THREAD:" + 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getId() + "AVISO : ESTA A CHAMAR UM SERVICO TRANSACIONAL DENTRO DE UMA TRANSACAO, VAMOS MANTER A MESMA TRASACAO"); |
|
- | 81 | 1.5.0/docs/api/java/lang/System.html">System.out.println(">>>>>>TRANSACTION WARNING BUT NO PROBLEM: AVISO: Já existia uma transação activa e foi iniciada outra neste momento sem fechar a anterior "); |
|
- | 82 | for (1.5.0/docs/api/java/lang/StackTraceElement.html">StackTraceElement ste : 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getStackTrace()) { |
|
- | 83 | 1.5.0/docs/api/java/lang/System.html">System.out.println("\t" + ste); |
|
- | 84 | } |
|
- | 85 | ||
- | 86 | } |
|
61 | try |
87 | try |
62 | { |
88 | { |
63 | filteringResult = broker.executePreFiltering(request, response); |
89 | filteringResult = broker.executePreFiltering(request, response); |
64 | passedPre = filteringResult.isSuccess(); |
90 | passedPre = filteringResult.isSuccess(); |
65 | } |
91 | } |
Line 90... | Line 116... | ||
90 | e); |
116 | e); |
91 | } |
117 | } |
92 | if (passedPost) |
118 | if (passedPost) |
93 | { |
119 | { |
94 | //the sucessfull case |
120 | //the sucessfull case |
- | 121 | if(!alreadyActive) |
|
95 | tb.commitTransaction(); |
122 | tb.commitTransaction(); |
96 | return response.getReturnObject(); |
123 | return response.getReturnObject(); |
97 | } |
124 | } |
98 | else |
125 | else |
99 | { |
126 | { |
100 | throw new FilterChainFailedException( |
127 | throw new FilterChainFailedException( |
Line 105... | Line 132... | ||
105 | { |
132 | { |
106 | //ok let this exception go up |
133 | //ok let this exception go up |
107 | try |
134 | try |
108 | { |
135 | { |
109 | //if we get here, something went wrong with the executing service. we should roll back all changes |
136 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 137 | if(!alreadyActive) |
|
110 | tb.abortTransaction(); |
138 | tb.abortTransaction(); |
111 | } |
139 | } |
112 | catch (StorageException e) |
140 | catch (StorageException e) |
113 | { |
141 | { |
114 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
142 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
115 | } |
143 | } |
Line 119... | Line 147... | ||
119 | { |
147 | { |
120 | //ok let this exception go up |
148 | //ok let this exception go up |
121 | try |
149 | try |
122 | { |
150 | { |
123 | //if we get here, something went wrong with the executing service. we should roll back all changes |
151 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 152 | if(!alreadyActive) |
|
124 | tb.abortTransaction(); |
153 | tb.abortTransaction(); |
125 | } |
154 | } |
126 | catch (StorageException e) |
155 | catch (StorageException e) |
127 | { |
156 | { |
128 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
157 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
129 | } |
158 | } |
Line 132... | Line 161... | ||
132 | catch (StorageException ex) |
161 | catch (StorageException ex) |
133 | { |
162 | { |
134 | try |
163 | try |
135 | { |
164 | { |
136 | //if we get here, something went wrong with the executing service. we should roll back all changes |
165 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 166 | if(!alreadyActive) |
|
137 | tb.abortTransaction(); |
167 | tb.abortTransaction(); |
138 | } |
168 | } |
139 | catch (StorageException e) |
169 | catch (StorageException e) |
140 | { |
170 | { |
141 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
171 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
142 | } |
172 | } |
Line 146... | Line 176... | ||
146 | { |
176 | { |
147 | //ok let this exception go up |
177 | //ok let this exception go up |
148 | try |
178 | try |
149 | { |
179 | { |
150 | //if we get here, something went wrong with the executing service. we should roll back all changes |
180 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 181 | if(!alreadyActive) |
|
151 | tb.abortTransaction(); |
182 | tb.abortTransaction(); |
152 | } |
183 | } |
153 | catch (StorageException e) |
184 | catch (StorageException e) |
154 | { |
185 | { |
155 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
186 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
156 | } |
187 | } |
Line 178... | Line 209... | ||
178 | request.setExcludeChains(new ArrayList<String>()); |
209 | request.setExcludeChains(new ArrayList<String>()); |
179 | request.getExcludeChains().add("Logger"); |
210 | request.getExcludeChains().add("Logger"); |
180 | ServiceResponse response = new ServiceResponse(); |
211 | ServiceResponse response = new ServiceResponse(); |
181 | FilteringResult filteringResult = null; |
212 | FilteringResult filteringResult = null; |
182 | ITransactionBroker tb = BerserkConfiguration.getApplicationTransactionBroker(); |
213 | ITransactionBroker tb = BerserkConfiguration.getApplicationTransactionBroker(); |
- | 214 | boolean alreadyActive = tb.isTransactionActive(); |
|
183 | try |
215 | try |
184 | { |
216 | { |
- | 217 | if(debug) |
|
- | 218 | 1.5.0/docs/api/java/lang/System.html">System.out.println("THREAD:" + 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getId() + ": Starting transaction for service: " + service.getClass().getName() + " method:" + methodName); |
|
- | 219 | if(!alreadyActive) |
|
- | 220 | { |
|
185 | tb.beginTransaction(); |
221 | tb.beginTransaction(); |
- | 222 | } |
|
- | 223 | else |
|
- | 224 | { |
|
- | 225 | 1.5.0/docs/api/java/lang/System.html">System.out.println("THREAD:" + 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getId() +" AVISO : ESTA A CHAMAR UM SERVICO TRANSACIONAL DENTRO DE UMA TRANSACAO, VAMOS MANTER A MESMA TRASACAO"); |
|
- | 226 | 1.5.0/docs/api/java/lang/System.html">System.out.println(">>>>>>TRANSACTION WARNING BUT NO PROBLEM: AVISO: Já existia uma transação activa e foi iniciada outra neste momento sem fechar a anterior "); |
|
- | 227 | for (1.5.0/docs/api/java/lang/StackTraceElement.html">StackTraceElement ste : 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getStackTrace()) { |
|
- | 228 | 1.5.0/docs/api/java/lang/System.html">System.out.println("\t" + ste); |
|
- | 229 | } |
|
- | 230 | } |
|
- | 231 | ||
186 | try |
232 | try |
187 | { |
233 | { |
188 | filteringResult = broker.executePreFiltering(request, response); |
234 | filteringResult = broker.executePreFiltering(request, response); |
189 | passedPre = filteringResult.isSuccess(); |
235 | passedPre = filteringResult.isSuccess(); |
190 | } |
236 | } |
Line 194... | Line 240... | ||
194 | "a not 'FilterException' exception occured while executing pre filter chain", |
240 | "a not 'FilterException' exception occured while executing pre filter chain", |
195 | e); |
241 | e); |
196 | } |
242 | } |
197 | if (passedPre) |
243 | if (passedPre) |
198 | { |
244 | { |
- | 245 | if(!alreadyActive) |
|
199 | tb.commitTransaction(); |
246 | tb.commitTransaction(); |
200 | return true; |
247 | return true; |
201 | } |
248 | } |
202 | else |
249 | else |
203 | { |
250 | { |
204 | throw new FilterChainFailedException( |
251 | throw new FilterChainFailedException( |
Line 209... | Line 256... | ||
209 | { |
256 | { |
210 | //ok let this exception go up |
257 | //ok let this exception go up |
211 | try |
258 | try |
212 | { |
259 | { |
213 | //if we get here, something went wrong with the executing service. we should roll back all changes |
260 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 261 | if(!alreadyActive) |
|
214 | tb.abortTransaction(); |
262 | tb.abortTransaction(); |
215 | } |
263 | } |
216 | catch (StorageException e) |
264 | catch (StorageException e) |
217 | { |
265 | { |
218 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
266 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
219 | } |
267 | } |
Line 223... | Line 271... | ||
223 | { |
271 | { |
224 | //ok let this exception go up |
272 | //ok let this exception go up |
225 | try |
273 | try |
226 | { |
274 | { |
227 | //if we get here, something went wrong with the executing service. we should roll back all changes |
275 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 276 | if(!alreadyActive) |
|
228 | tb.abortTransaction(); |
277 | tb.abortTransaction(); |
229 | } |
278 | } |
230 | catch (StorageException e) |
279 | catch (StorageException e) |
231 | { |
280 | { |
232 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
281 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
233 | } |
282 | } |
Line 236... | Line 285... | ||
236 | catch (StorageException ex) |
285 | catch (StorageException ex) |
237 | { |
286 | { |
238 | try |
287 | try |
239 | { |
288 | { |
240 | //if we get here, something went wrong with the executing service. we should roll back all changes |
289 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 290 | if(!alreadyActive) |
|
241 | tb.abortTransaction(); |
291 | tb.abortTransaction(); |
242 | } |
292 | } |
243 | catch (StorageException e) |
293 | catch (StorageException e) |
244 | { |
294 | { |
245 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
295 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
246 | } |
296 | } |
Line 250... | Line 300... | ||
250 | { |
300 | { |
251 | //ok let this exception go up |
301 | //ok let this exception go up |
252 | try |
302 | try |
253 | { |
303 | { |
254 | //if we get here, something went wrong with the executing service. we should roll back all changes |
304 | //if we get here, something went wrong with the executing service. we should roll back all changes |
- | 305 | if(!alreadyActive) |
|
255 | tb.abortTransaction(); |
306 | tb.abortTransaction(); |
256 | } |
307 | } |
257 | catch (StorageException e) |
308 | catch (StorageException e) |
258 | { |
309 | { |
259 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
310 | throw new ServiceManagerException("Storage Exception while aborting transaction",e); |
260 | } |
311 | } |