KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > resource > RMEImpl


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: RMEImpl.java,v 1.8 2005/04/28 08:43:25 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.resource;
27
28 import javax.resource.ResourceException JavaDoc;
29 import javax.transaction.Transaction JavaDoc;
30 import javax.transaction.RollbackException JavaDoc;
31 import javax.transaction.SystemException JavaDoc;
32 import org.objectweb.transaction.jta.ResourceManagerEvent;
33 import org.objectweb.util.monolog.api.BasicLevel;
34 import org.objectweb.util.monolog.api.Logger;
35
36 /**
37  * This class implements ResourceManagerEvent. An instance of this object is
38  * also an event transmited by the Resource adapter manager to the user
39  * transaction. This event is linked to a ManagedConnection, more exatcly this
40  * implementation is linked to MCInfo instance.
41  *
42  *@author sebastien.chassande@inrialpes.fr
43  */

44 class RMEImpl implements ResourceManagerEvent {
45     /**
46      * The MCInfo instance which represents the physical connection
47      */

48     private MCInfo mci = null;
49     /**
50      * The Logger instance where messages are written.
51      */

52     private Logger trace = null;
53     /**
54      * Set if the RME is valid to call enlist Resource
55      * Issue with JOTM and one thread calling ConnectionOpened, but a
56      * different thread calling Closed or Error and not enough information
57      * in JOTM to keep information straight.
58      */

59     protected boolean isValid = false;
60
61     /**
62      * This constructor permits to specify the MCInfp corresponding to the
63      * ManagedConnection (the physical connection).
64      *
65      * @param mci MCInfo
66      * @param trace Logger
67      */

68     public RMEImpl(MCInfo mci, Logger trace) {
69         this.mci = mci;
70         this.trace = trace;
71     }
72
73
74     /**
75      * Check if equals
76      * @param o Object to test equality
77      * @return boolean if RMEImpl objets are equal
78      */

79     public boolean equals(Object JavaDoc o) {
80         return (o instanceof RMEImpl) && mci.equals(((RMEImpl) o).mci);
81     }
82
83
84     /**
85      * This method is in charge of the enlisting of the managedConnection linked
86      * to this instance, in the transaction specified in parameter.
87      * @param tx TransactionConnection
88      * @throws SystemException if an Exception occurs
89      */

90     public void enlistConnection(Transaction JavaDoc tx) throws SystemException JavaDoc {
91         try {
92             if (isValid) {
93                 if (trace.isLoggable(BasicLevel.DEBUG)) {
94                     trace.log(BasicLevel.DEBUG, "Enlist the XA Resource " + mci.getXAResource()
95                             + " in Tx:" + tx);
96                 }
97                 tx.enlistResource(mci.getXAResource());
98             }
99         } catch (RollbackException JavaDoc rbe) {
100             throw new SystemException JavaDoc(rbe.getMessage());
101         } catch (ResourceException JavaDoc re) {
102             throw new SystemException JavaDoc(re.getMessage());
103         }
104     }
105 }
106
Popular Tags