1 25 26 package org.objectweb.jonas_jms; 27 28 import javax.jms.JMSException ; 29 import javax.jms.Queue ; 30 import javax.jms.QueueBrowser ; 31 import javax.jms.QueueReceiver ; 32 import javax.jms.QueueSender ; 33 import javax.jms.QueueSession ; 34 import javax.jms.Session ; 35 import javax.jms.TemporaryQueue ; 36 import javax.jms.XAQueueConnection ; 37 import javax.jms.XAQueueSession ; 38 import javax.transaction.RollbackException ; 39 import javax.transaction.SystemException ; 40 import javax.transaction.Transaction ; 41 42 import org.objectweb.util.monolog.api.BasicLevel; 43 44 50 public class JQueueSession extends JSession implements QueueSession { 51 52 protected XAQueueConnection xaqc; 54 protected QueueSession qs = null; 55 protected XAQueueSession xaqs = null; 56 57 60 public JQueueSession(JConnection jconn, XAQueueConnection xaqc) { 61 super(jconn); 62 this.xaqc = xaqc; 63 } 64 65 69 72 protected Session getMOMSession() throws JMSException { 73 return getMOMQueueSession(); 74 } 75 76 protected QueueSession getMOMQueueSession() throws JMSException { 77 Transaction tx = null; 78 try { 79 tx = tm.getTransaction(); 80 } catch (SystemException e) { 81 TraceJms.logger.log(BasicLevel.ERROR,"cannot get Transaction"); 82 } 83 if (tx == null) { 84 if (qs == null) { 85 qs = xaqc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 86 jconn.sessionOpen(this); 87 } 88 return qs; 89 } else { 90 if (xaqs == null) { 91 xaqs = xaqc.createXAQueueSession(); 92 if (currtx != null) { 93 TraceJms.logger.log(BasicLevel.ERROR,"mixed transactions"); 94 } 95 currtx = tx; 96 xares = xaqs.getXAResource(); 97 try { 98 tx.enlistResource(this.getXAResource()); 99 txover = false; 100 } catch (SystemException e) { 101 TraceJms.logger.log(BasicLevel.ERROR,"cannot enlist session:"+e); 102 throw new JMSException (e.toString()); 103 } catch (RollbackException e) { 104 TraceJms.logger.log(BasicLevel.ERROR,"transaction rolled back"); 105 throw new JMSException (e.toString()); 106 } 107 } 108 return xaqs.getQueueSession(); 109 } 110 } 111 112 protected void MOMSessionClose() { 113 try { 114 if (xaqs != null) { 115 xaqs.close(); 116 xaqs = null; 117 } 118 if (qs != null) { 119 qs.close(); 120 qs = null; 121 jconn.sessionClose(this); 122 } 123 } catch (JMSException e) { 124 TraceJms.logger.log(BasicLevel.ERROR,"exception:"+e); 125 } 126 } 127 128 132 135 public QueueBrowser createBrowser(Queue queue) throws JMSException { 136 TraceJms.logger.log(BasicLevel.DEBUG, ""); 137 return getMOMQueueSession().createBrowser(queue); 138 } 139 140 143 public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException { 144 TraceJms.logger.log(BasicLevel.DEBUG, ""); 145 return getMOMQueueSession().createBrowser(queue, messageSelector); 146 } 147 148 151 public Queue createQueue(String queueName) throws JMSException { 152 TraceJms.logger.log(BasicLevel.DEBUG, ""); 153 return getMOMQueueSession().createQueue(queueName); 154 } 155 156 159 public QueueReceiver createReceiver(Queue queue) throws JMSException { 160 TraceJms.logger.log(BasicLevel.DEBUG, ""); 161 return getMOMQueueSession().createReceiver(queue); 162 } 163 164 167 public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { 168 TraceJms.logger.log(BasicLevel.DEBUG, ""); 169 return getMOMQueueSession().createReceiver(queue, messageSelector); 170 } 171 172 175 public QueueSender createSender(Queue queue) throws JMSException { 176 TraceJms.logger.log(BasicLevel.DEBUG, ""); 177 return getMOMQueueSession().createSender(queue); 178 } 179 180 183 public TemporaryQueue createTemporaryQueue() throws JMSException { 184 TraceJms.logger.log(BasicLevel.DEBUG, ""); 185 return getMOMQueueSession().createTemporaryQueue(); 186 } 187 188 189 } 190 | Popular Tags |