1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: JmsXATopicSession.java,v 1.4 2003/08/07 13:32:51 tanderson Exp $
44 *
45 * Date Author Changes
46 * 10/09/2001 jima Created
47 */
48 package org.exolab.jms.client;
49
50 // xa library
51
52 import javax.jms.JMSException;
53 import javax.jms.TopicSession;
54 import javax.jms.TransactionInProgressException;
55 import javax.jms.XATopicSession;
56 import javax.transaction.xa.XAException;
57 import javax.transaction.xa.XAResource;
58 import javax.transaction.xa.Xid;
59
60
61 /***
62 *
63 * @version $Revision: 1.4 $ $Date: 2003/08/07 13:32:51 $
64 * @author <a href="mailto:jima@intalio.com">Jim Alateras</a>
65 * @see javax.jms.XATopicSession
66 **/
67 public class JmsXATopicSession
68 extends JmsTopicSession
69 implements XATopicSession, XAResource {
70
71 /***
72 * caches the resource manager id, which is globally unique so that a test
73 * through {@link #isSameRM} doesn't have to go across the wire.
74 */
75 private Long _rid = null;
76
77
78 /***
79 * Create an instance of this class specifying the creating entity. This is
80 * the actual connection managing this session. Also specify whether the
81 * session is transacted and the acknowledgement mode.
82 * <p>
83 * If there is a problem creating this object then throw the JMSException
84 * exception.
85 *
86 * @param connection - owner of the session
87 * @param transacted - true if the session is transacted
88 * @param ackMode - acknowledgement mode
89 * @exception JMSException
90 */
91 JmsXATopicSession(JmsXATopicConnection connection, boolean transacted, int ackMode)
92 throws JMSException {
93 super(connection, transacted, ackMode);
94 }
95
96 // implementation of XATopicSession.getTopicSession
97 public TopicSession getTopicSession()
98 throws JMSException {
99 return this;
100 }
101
102 // implementation of XASession.getXAResource
103 public XAResource getXAResource() {
104 return this;
105 }
106
107 // implementation of XASession.getTransacted
108 public boolean getTransacted()
109 throws JMSException {
110 return true;
111 }
112
113 // implementation of XASession.commit
114 public void commit()
115 throws JMSException {
116 throw new TransactionInProgressException(
117 "Cannot call commit on XASession");
118 }
119
120 // implementation of XASession.rollback
121 public void rollback()
122 throws JMSException {
123 throw new TransactionInProgressException(
124 "Cannot call rollback on XASession");
125 }
126
127 // implementation of XAResource.commit
128 public void commit(Xid xid, boolean onePhase)
129 throws XAException {
130 getJmsSessionStub().commit(xid, onePhase);
131 }
132
133 // implementation of XAResource.end
134 public void end(Xid xid, int flags)
135 throws XAException {
136 getJmsSessionStub().end(xid, flags);
137 }
138
139 // implementation of XAResource.forget
140 public void forget(Xid xid)
141 throws XAException {
142 getJmsSessionStub().forget(xid);
143 }
144
145 // implementation of XAResource.getTransactionTimeout
146 public int getTransactionTimeout()
147 throws XAException {
148 return getJmsSessionStub().getTransactionTimeout();
149 }
150
151 // implementation of XAResource.isSameRM
152 public boolean isSameRM(XAResource xares)
153 throws XAException {
154
155 boolean result = false;
156
157 if ((xares != null) &&
158 (xares instanceof JmsXATopicSession) &&
159 (((JmsXATopicSession) xares).getResourceManagerId() ==
160 getResourceManagerId())) {
161 result = true;
162 }
163
164 return result;
165 }
166
167 // implementation of XAResource.prepare
168 public int prepare(Xid xid)
169 throws XAException {
170 return getJmsSessionStub().prepare(xid);
171 }
172
173 // implementation of XAResource.recover
174 public Xid[] recover(int flag)
175 throws XAException {
176 return getJmsSessionStub().recover(flag);
177 }
178
179 // implementation of XAResource.rollback
180 public void rollback(Xid xid)
181 throws XAException {
182 getJmsSessionStub().rollback(xid);
183 }
184
185 // implementation of XAResource.setTransactionTimeout
186 public boolean setTransactionTimeout(int seconds)
187 throws XAException {
188 return getJmsSessionStub().setTransactionTimeout(seconds);
189 }
190
191 // implementation of XAResource.start
192 public void start(Xid xid, int flags)
193 throws XAException {
194 getJmsSessionStub().start(xid, flags);
195 }
196
197 /***
198 * Return the identity of the associated resource manager. If the value
199 * is not cached locally then grab it from the server
200 *
201 * @return long - the identity of the resource
202 * @exception XAException
203 */
204 public long getResourceManagerId()
205 throws XAException {
206 if (_rid == null) {
207 _rid = new Long(getJmsSessionStub().getResourceManagerId());
208 }
209
210 return _rid.longValue();
211 }
212 }
This page was automatically generated by Maven