001 /* Licensed to the Apache Software Foundation (ASF) under one
002 * or more contributor license agreements. See the NOTICE file
003 * distributed with this work for additional information
004 * regarding copyright ownership. The ASF licenses this file
005 * to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance
007 * with the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing,
012 * software distributed under the License is distributed on an
013 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
014 * KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations
016 * under the License.
017 */
018 package org.apache.qpid.client;
019
020 import org.apache.qpid.client.message.MessageFactoryRegistry;
021
022 import javax.jms.*;
023 import javax.transaction.xa.XAResource;
024
025 /**
026 * This is an implementation of the javax.njms.XASEssion interface.
027 */
028 public class XASessionImpl extends AMQSession_0_10 implements XASession, XATopicSession, XAQueueSession
029 {
030 /**
031 * XAResource associated with this XASession
032 */
033 private final XAResourceImpl _xaResource;
034
035 /**
036 * This XASession Qpid DtxSession
037 */
038 private org.apache.qpid.transport.Session _qpidDtxSession;
039
040 /**
041 * The standard session
042 */
043 private Session _jmsSession;
044
045
046 //-- Constructors
047 /**
048 * Create a JMS XASession
049 */
050 public XASessionImpl(org.apache.qpid.transport.Connection qpidConnection, AMQConnection con, int channelId,
051 int defaultPrefetchHigh, int defaultPrefetchLow)
052 {
053 super(qpidConnection, con, channelId, false, // this is not a transacted session
054 Session.AUTO_ACKNOWLEDGE, // the ack mode is transacted
055 MessageFactoryRegistry.newDefaultRegistry(), defaultPrefetchHigh, defaultPrefetchLow);
056 createSession();
057 _xaResource = new XAResourceImpl(this);
058 }
059
060 //-- public methods
061
062 /**
063 * Create a qpid session.
064 */
065 public void createSession()
066 {
067 _qpidDtxSession = _qpidConnection.createSession(0);
068 _qpidDtxSession.setSessionListener(this);
069 _qpidDtxSession.dtxSelect();
070 }
071
072
073 //--- javax.njms.XASEssion API
074
075 /**
076 * Gets the session associated with this XASession.
077 *
078 * @return The session object.
079 * @throws JMSException if an internal error occurs.
080 */
081 public Session getSession() throws JMSException
082 {
083 if (_jmsSession == null)
084 {
085 _jmsSession = getAMQConnection().createSession(true, getAcknowledgeMode());
086 }
087 return _jmsSession;
088 }
089
090 /**
091 * Returns an XA resource.
092 *
093 * @return An XA resource.
094 */
095 public XAResource getXAResource()
096 {
097 return _xaResource;
098 }
099
100 //-- overwritten mehtods
101 /**
102 * Throws a {@link TransactionInProgressException}, since it should
103 * not be called for an XASession object.
104 *
105 * @throws TransactionInProgressException always.
106 */
107 public void commit() throws JMSException
108 {
109 throw new TransactionInProgressException(
110 "XASession: A direct invocation of the commit operation is probibited!");
111 }
112
113 /**
114 * Throws a {@link TransactionInProgressException}, since it should
115 * not be called for an XASession object.
116 *
117 * @throws TransactionInProgressException always.
118 */
119 public void rollback() throws JMSException
120 {
121 throw new TransactionInProgressException(
122 "XASession: A direct invocation of the rollback operation is probibited!");
123 }
124
125 /**
126 * Access to the underlying Qpid Session
127 *
128 * @return The associated Qpid Session.
129 */
130 protected org.apache.qpid.transport.Session getQpidSession()
131 {
132 return _qpidDtxSession;
133 }
134
135 //--- interface XAQueueSession
136 /**
137 * Gets the topic session associated with this <CODE>XATopicSession</CODE>.
138 *
139 * @return the topic session object
140 * @throws JMSException If an internal error occurs.
141 */
142 public QueueSession getQueueSession() throws JMSException
143 {
144 return (QueueSession) getSession();
145 }
146
147 //--- interface XATopicSession
148
149 /**
150 * Gets the topic session associated with this <CODE>XATopicSession</CODE>.
151 *
152 * @return the topic session object
153 * @throws JMSException If an internal error occurs.
154 */
155 public TopicSession getTopicSession() throws JMSException
156 {
157 return (TopicSession) getSession();
158 }
159 }
|