KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ActiveMQXASession


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq;
20
21 import javax.jms.JMSException JavaDoc;
22 import javax.jms.QueueSession JavaDoc;
23 import javax.jms.Session JavaDoc;
24 import javax.jms.TopicSession JavaDoc;
25 import javax.jms.TransactionInProgressException JavaDoc;
26 import javax.jms.XAQueueSession JavaDoc;
27 import javax.jms.XATopicSession JavaDoc;
28 import javax.transaction.xa.XAResource JavaDoc;
29
30 import org.apache.activemq.command.SessionId;
31
32 /**
33  * The XASession interface extends the capability of Session by adding access
34  * to a JMS provider's support for the Java Transaction API (JTA) (optional).
35  * This support takes the form of a javax.transaction.xa.XAResource object.
36  * The functionality of this object closely resembles that defined by the
37  * standard X/Open XA Resource interface.
38  * <p/>
39  * An application server controls the transactional assignment of an XASession
40  * by obtaining its XAResource. It uses the XAResource to assign the session
41  * to a transaction, prepare and commit work on the transaction, and so on.
42  * <p/>
43  * An XAResource provides some fairly sophisticated facilities for
44  * interleaving work on multiple transactions, recovering a list of
45  * transactions in progress, and so on. A JTA aware JMS provider must fully
46  * implement this functionality. This could be done by using the services of a
47  * database that supports XA, or a JMS provider may choose to implement this
48  * functionality from scratch.
49  * <p/>
50  * A client of the application server is given what it thinks is a regular
51  * JMS Session. Behind the scenes, the application server controls the
52  * transaction management of the underlying XASession.
53  * <p/>
54  * The XASession interface is optional. JMS providers are not required to
55  * support this interface. This interface is for use by JMS providers to
56  * support transactional environments. Client programs are strongly encouraged
57  * to use the transactional support available in their environment, rather
58  * than use these XA interfaces directly.
59  *
60  * @version $Revision: 1.5 $
61  * @see javax.jms.Session
62  * @see javax.jms.QueueSession
63  * @see javax.jms.TopicSession
64  * @see javax.jms.XASession
65  */

66 public class ActiveMQXASession extends ActiveMQSession implements QueueSession JavaDoc, TopicSession JavaDoc, XAQueueSession JavaDoc, XATopicSession JavaDoc {
67
68     public ActiveMQXASession(ActiveMQXAConnection connection, SessionId sessionId, int theAcknowlegeMode, boolean dispatchAsync) throws JMSException JavaDoc {
69         super(connection, sessionId, theAcknowlegeMode, dispatchAsync);
70     }
71
72     public boolean getTransacted() throws JMSException JavaDoc {
73         return true;
74     }
75
76     public void rollback() throws JMSException JavaDoc {
77         throw new TransactionInProgressException JavaDoc("Cannot rollback() inside an XASession");
78     }
79
80     public void commit() throws JMSException JavaDoc {
81         throw new TransactionInProgressException JavaDoc("Cannot commit() inside an XASession");
82     }
83
84     public Session JavaDoc getSession() throws JMSException JavaDoc {
85         return this;
86     }
87
88     public XAResource JavaDoc getXAResource() {
89         return getTransactionContext();
90     }
91
92     public QueueSession JavaDoc getQueueSession() throws JMSException JavaDoc {
93         return new ActiveMQQueueSession(this);
94     }
95
96     public TopicSession JavaDoc getTopicSession() throws JMSException JavaDoc {
97         return new ActiveMQTopicSession(this);
98     }
99
100     /**
101      * This is called before transacted work is done by
102      * the session. XA Work can only be done when this
103      * XA resource is associated with an Xid.
104      *
105      * @throws JMSException not associated with an Xid
106      */

107     protected void doStartTransaction() throws JMSException JavaDoc {
108
109         if (!getTransactionContext().isInXATransaction()) {
110             throw new JMSException JavaDoc("Session's XAResource has not been enlisted in a distributed transaction.");
111         }
112
113     }
114
115 }
116
Popular Tags