KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > bean > XAResourceEnlisterCallerBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.recover.bean;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32 import javax.transaction.RollbackException JavaDoc;
33 import javax.transaction.SystemException JavaDoc;
34 import javax.transaction.Transaction JavaDoc;
35 import javax.transaction.TransactionManager JavaDoc;
36 import javax.transaction.xa.XAResource JavaDoc;
37
38 import org.jboss.logging.Logger;
39 import org.jboss.test.recover.interfaces.XAResourceEnlister;
40 import org.jboss.test.recover.interfaces.XAResourceEnlisterHome;
41 import org.jboss.test.util.ejb.SessionSupport;
42 import org.jboss.tm.recovery.Recoverable;
43
44 /**
45  * A XAResourceEnlisterCallerBean.
46  *
47  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
48  * @version $Revision: 37406 $
49  */

50 public class XAResourceEnlisterCallerBean
51       extends SessionSupport
52 {
53    private static final Logger log =
54       Logger.getLogger(XAResourceEnlisterCallerBean.class);
55
56    private TransactionManager JavaDoc tm;
57    private Recoverable recoverable1;
58    private Recoverable recoverable2;
59    private XAResourceEnlister xaResEnlisterJBRem1;
60    private XAResourceEnlister xaResEnlisterJBRem2;
61    private XAResourceEnlister xaResEnlisterIIOP1;
62    private XAResourceEnlister xaResEnlisterIIOP2;
63    
64    public void ejbCreate()
65    {
66       try
67       {
68          Context JavaDoc ctx = new InitialContext JavaDoc();
69          
70          tm = (TransactionManager JavaDoc) ctx.lookup("java:/TransactionManager");
71          recoverable1 = (Recoverable) ctx.lookup("DummyRecoverableProxy1");
72          recoverable2 = (Recoverable) ctx.lookup("DummyRecoverableProxy2");
73          
74          Object JavaDoc obj;
75          XAResourceEnlisterHome home;
76          
77          obj = ctx.lookup("java:comp/env/ejb/XAResEnlisterJBRem1");
78          home = (XAResourceEnlisterHome)
79             PortableRemoteObject.narrow(obj, XAResourceEnlisterHome.class);
80          xaResEnlisterJBRem1 = home.create();
81
82          obj = ctx.lookup("java:comp/env/ejb/XAResEnlisterJBRem2");
83          home = (XAResourceEnlisterHome)
84             PortableRemoteObject.narrow(obj, XAResourceEnlisterHome.class);
85          xaResEnlisterJBRem2 = home.create();
86
87          obj = ctx.lookup("java:comp/env/ejb/XAResEnlisterIIOP1");
88          home = (XAResourceEnlisterHome)
89             PortableRemoteObject.narrow(obj, XAResourceEnlisterHome.class);
90          xaResEnlisterIIOP1 = home.create();
91
92          obj = ctx.lookup("java:comp/env/ejb/XAResEnlisterIIOP2");
93          home = (XAResourceEnlisterHome)
94             PortableRemoteObject.narrow(obj, XAResourceEnlisterHome.class);
95          xaResEnlisterIIOP2 = home.create();
96       }
97       catch (NamingException JavaDoc e)
98       {
99          log.info(e);
100          throw new EJBException JavaDoc(e);
101       }
102       catch (RemoteException JavaDoc e)
103       {
104          log.info(e);
105          throw new EJBException JavaDoc(e);
106       }
107       catch (CreateException JavaDoc e)
108       {
109          log.info(e);
110          throw new EJBException JavaDoc(e);
111       }
112       
113    }
114
115    public void callXAResourceEnlistersOverJBRem()
116    {
117       log.info("callXAResourceEnlistersOverJBRem called");
118       try
119       {
120          Transaction JavaDoc tx = tm.getTransaction();
121          log.info("tx=" + tx);
122
123          // enlist XA resources
124
XAResource JavaDoc xaRes1 = recoverable1.getResource();
125          tx.enlistResource(xaRes1);
126          log.info("enlisted xaRes1=" + xaRes1);
127          XAResource JavaDoc xaRes2 = recoverable2.getResource();
128          tx.enlistResource(xaRes2);
129          log.info("enlisted xaRes2=" + xaRes2);
130          
131          // access remote resources
132
xaResEnlisterJBRem1.method();
133          xaResEnlisterJBRem2.method();
134       }
135       catch (SystemException JavaDoc e)
136       {
137          log.info(e);
138          throw new EJBException JavaDoc(e);
139       }
140       catch (RollbackException JavaDoc e)
141       {
142          log.info(e);
143          throw new EJBException JavaDoc(e);
144       }
145       catch (RemoteException JavaDoc e)
146       {
147          log.info(e);
148          throw new EJBException JavaDoc(e);
149       }
150    }
151
152    public void callXAResourceEnlistersOverIIOP()
153    {
154       log.info("callXAResourceEnlistersOverIIOP called");
155       try
156       {
157          Transaction JavaDoc tx = tm.getTransaction();
158          log.info("tx=" + tx);
159
160          // enlist XA resources
161
XAResource JavaDoc xaRes1 = recoverable1.getResource();
162          tx.enlistResource(xaRes1);
163          log.info("enlisted xaRes1=" + xaRes1);
164          XAResource JavaDoc xaRes2 = recoverable2.getResource();
165          tx.enlistResource(xaRes2);
166          log.info("enlisted xaRes2=" + xaRes2);
167          
168          // access remote resources
169
xaResEnlisterIIOP1.method();
170          xaResEnlisterIIOP2.method();
171       }
172       catch (SystemException JavaDoc e)
173       {
174          log.info(e);
175          throw new EJBException JavaDoc(e);
176       }
177       catch (RollbackException JavaDoc e)
178       {
179          log.info(e);
180          throw new EJBException JavaDoc(e);
181       }
182       catch (RemoteException JavaDoc e)
183       {
184          log.info(e);
185          throw new EJBException JavaDoc(e);
186       }
187    }
188    
189    public void callXAResourceEnlistersOverJBRemAndIIOP()
190    {
191       log.info("callXAResourceEnlistersOverJBRemAndIIOP called");
192       try
193       {
194          Transaction JavaDoc tx = tm.getTransaction();
195          log.info("tx=" + tx);
196
197          // enlist XA resources
198
XAResource JavaDoc xaRes1 = recoverable1.getResource();
199          tx.enlistResource(xaRes1);
200          log.info("enlisted xaRes1=" + xaRes1);
201          XAResource JavaDoc xaRes2 = recoverable2.getResource();
202          tx.enlistResource(xaRes2);
203          log.info("enlisted xaRes2=" + xaRes2);
204          
205          // access remote resources
206
xaResEnlisterJBRem1.method();
207          xaResEnlisterIIOP2.method();
208       }
209       catch (SystemException JavaDoc e)
210       {
211          log.info(e);
212          throw new EJBException JavaDoc(e);
213       }
214       catch (RollbackException JavaDoc e)
215       {
216          log.info(e);
217          throw new EJBException JavaDoc(e);
218       }
219       catch (RemoteException JavaDoc e)
220       {
221          log.info(e);
222          throw new EJBException JavaDoc(e);
223       }
224    }
225
226    public void callXAResourceEnlistersOverIIOPAndJBRem()
227    {
228       log.info("callXAResourceEnlistersOverIIOPAndJBRem called");
229       try
230       {
231          Transaction JavaDoc tx = tm.getTransaction();
232          log.info("tx=" + tx);
233
234          // enlist XA resources
235
XAResource JavaDoc xaRes1 = recoverable1.getResource();
236          tx.enlistResource(xaRes1);
237          log.info("enlisted xaRes1=" + xaRes1);
238          XAResource JavaDoc xaRes2 = recoverable2.getResource();
239          tx.enlistResource(xaRes2);
240          log.info("enlisted xaRes2=" + xaRes2);
241          
242          // access remote resources
243
xaResEnlisterIIOP1.method();
244          xaResEnlisterJBRem2.method();
245       }
246       catch (SystemException JavaDoc e)
247       {
248          log.info(e);
249          throw new EJBException JavaDoc(e);
250       }
251       catch (RollbackException JavaDoc e)
252       {
253          log.info(e);
254          throw new EJBException JavaDoc(e);
255       }
256       catch (RemoteException JavaDoc e)
257       {
258          log.info(e);
259          throw new EJBException JavaDoc(e);
260       }
261    }
262
263    public void enlistOneXAResourcePerAppServerOverJBRem()
264    {
265       log.info("enlistOneXAResourcePerServerOverJBRem called");
266       try
267       {
268          Transaction JavaDoc tx = tm.getTransaction();
269          log.info("tx=" + tx);
270
271          // enlist XA resource 1
272
XAResource JavaDoc xaRes1 = recoverable1.getResource();
273          tx.enlistResource(xaRes1);
274          
275          // access remote resources
276
xaResEnlisterJBRem1.enlistXAResource(2);
277          xaResEnlisterJBRem2.enlistXAResource(3);
278       }
279       catch (SystemException JavaDoc e)
280       {
281          log.info(e);
282          throw new EJBException JavaDoc(e);
283       }
284       catch (RollbackException JavaDoc e)
285       {
286          log.info(e);
287          throw new EJBException JavaDoc(e);
288       }
289       catch (RemoteException JavaDoc e)
290       {
291          log.info(e);
292          throw new EJBException JavaDoc(e);
293       }
294    }
295
296    public void enlistOneXAResourcePerAppServerOverIIOP()
297    {
298       log.info("enlistOneXAResourcePerServerOverIIOP called");
299       try
300       {
301          Transaction JavaDoc tx = tm.getTransaction();
302          log.info("tx=" + tx);
303
304          // enlist XA resource 1
305
XAResource JavaDoc xaRes1 = recoverable1.getResource();
306          tx.enlistResource(xaRes1);
307          
308          // access remote resources
309
xaResEnlisterIIOP1.enlistXAResource(2);
310          xaResEnlisterIIOP2.enlistXAResource(3);
311       }
312       catch (SystemException JavaDoc e)
313       {
314          log.info(e);
315          throw new EJBException JavaDoc(e);
316       }
317       catch (RollbackException JavaDoc e)
318       {
319          log.info(e);
320          throw new EJBException JavaDoc(e);
321       }
322       catch (RemoteException JavaDoc e)
323       {
324          log.info(e);
325          throw new EJBException JavaDoc(e);
326       }
327    }
328
329    public void enlistOneXAResourcePerAppServerOverJBRemAndIIOP()
330    {
331       log.info("enlistOneXAResourcePerServerOverJBRemAndIIOP called");
332       try
333       {
334          Transaction JavaDoc tx = tm.getTransaction();
335          log.info("tx=" + tx);
336
337          // enlist XA resource 1
338
XAResource JavaDoc xaRes1 = recoverable1.getResource();
339          tx.enlistResource(xaRes1);
340          
341          // access remote resources
342
xaResEnlisterJBRem1.enlistXAResource(2);
343          xaResEnlisterIIOP2.enlistXAResource(3);
344       }
345       catch (SystemException JavaDoc e)
346       {
347          log.info(e);
348          throw new EJBException JavaDoc(e);
349       }
350       catch (RollbackException JavaDoc e)
351       {
352          log.info(e);
353          throw new EJBException JavaDoc(e);
354       }
355       catch (RemoteException JavaDoc e)
356       {
357          log.info(e);
358          throw new EJBException JavaDoc(e);
359       }
360    }
361
362    public void enlistOneXAResourcePerAppServerOverIIOPAndJBRem()
363    {
364       log.info("enlistOneXAResourcePerServerOverIIOPAndJBRem called");
365       try
366       {
367          Transaction JavaDoc tx = tm.getTransaction();
368          log.info("tx=" + tx);
369
370          // enlist XA resource 1
371
XAResource JavaDoc xaRes1 = recoverable1.getResource();
372          tx.enlistResource(xaRes1);
373          
374          // access remote resources
375
xaResEnlisterIIOP1.enlistXAResource(2);
376          xaResEnlisterJBRem2.enlistXAResource(3);
377       }
378       catch (SystemException JavaDoc e)
379       {
380          log.info(e);
381          throw new EJBException JavaDoc(e);
382       }
383       catch (RollbackException JavaDoc e)
384       {
385          log.info(e);
386          throw new EJBException JavaDoc(e);
387       }
388       catch (RemoteException JavaDoc e)
389       {
390          log.info(e);
391          throw new EJBException JavaDoc(e);
392       }
393    }
394
395 }
396
Popular Tags