1 25 package org.objectweb.joram.client.jms; 26 27 import javax.jms.JMSException ; 28 import javax.transaction.xa.XAException ; 29 import javax.transaction.xa.Xid ; 30 31 import org.objectweb.util.monolog.api.BasicLevel; 32 import org.objectweb.joram.shared.JoramTracing; 33 34 38 public class XAResource implements javax.transaction.xa.XAResource { 39 40 private boolean enlisted = false; 41 42 private Xid currentXid = null; 43 44 45 XAResourceMngr rm; 46 47 48 Session sess; 49 50 51 54 public XAResource(XAResourceMngr rm, Session sess) { 55 this.rm = rm; 56 this.sess = sess; 57 58 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 59 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 60 " XAResource rm = " + rm + 61 ", sess = " + sess); 62 } 63 64 65 72 public void start(Xid xid, int flag) 73 throws XAException { 74 if (enlisted) 75 throw new XAException ("Resource already enlisted."); 76 77 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 78 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 79 this + ": start(" + xid + 80 ", " + flag + ")"); 81 82 rm.start(xid, flag, sess); 83 84 enlisted = true; 85 currentXid = xid; 86 } 87 88 95 public void end(Xid xid, int flag) 96 throws XAException { 97 if (! enlisted || ! xid.equals(currentXid)) 98 throw new XAException ("Resource is not enlisted in specified" 99 + " transaction."); 100 101 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 102 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 103 this + ": end(" + xid + 104 ", " + flag + ")"); 105 106 rm.end(xid, flag, sess); 107 108 enlisted = false; 109 currentXid = null; 110 } 111 112 117 public int prepare(Xid xid) 118 throws XAException { 119 120 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 121 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 122 this + ": prepare(" + xid + ")"); 123 rm.prepare(xid); 124 return XA_OK; 125 } 126 127 132 public void commit(Xid xid, boolean onePhase) 133 throws XAException { 134 135 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 136 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 137 this + ": commit(" + xid + 138 ", " + onePhase + ")"); 139 140 if (onePhase) 141 rm.prepare(xid); 142 143 rm.commit(xid); 144 } 145 146 151 public void rollback(Xid xid) 152 throws XAException { 153 154 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 155 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 156 this + ": rollback(" + xid + ")"); 157 158 if (enlisted && currentXid.equals(xid)) { 159 rm.end(xid, javax.transaction.xa.XAResource.TMFAIL, sess); 160 enlisted = false; 161 currentXid = null; 162 } 163 164 rm.rollback(xid); 165 } 166 167 172 public Xid [] recover(int flag) throws XAException 173 { 174 return rm.recover(flag); 175 } 176 177 182 public void forget(Xid xid) throws XAException 183 { 184 throw new XAException ("Non implemented method."); 185 } 186 187 192 public boolean setTransactionTimeout(int seconds) throws XAException 193 { 194 return false; 195 } 196 197 202 public int getTransactionTimeout() throws XAException 203 { 204 return 0; 205 } 206 207 213 public boolean isSameRM(javax.transaction.xa.XAResource o) 214 throws XAException { 215 216 if (! (o instanceof org.objectweb.joram.client.jms.XAResource)) 217 return false; 218 219 XAResource other = (org.objectweb.joram.client.jms.XAResource) o; 220 221 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 222 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 223 this + ": isSameRM other.rm = " + other.rm + 224 ", this.rm = " + this.rm + 225 ", equals = " + this.rm.equals(other.rm)); 226 227 return this.rm.equals(other.rm); 228 } 229 } 230 | Popular Tags |