1 26 27 package org.objectweb.jonas_jms; 28 29 import javax.jms.InvalidDestinationException ; 30 import javax.jms.JMSException ; 31 import javax.jms.Session ; 32 import javax.jms.TemporaryTopic ; 33 import javax.jms.Topic ; 34 import javax.jms.TopicPublisher ; 35 import javax.jms.TopicSession ; 36 import javax.jms.TopicSubscriber ; 37 import javax.jms.XATopicConnection ; 38 import javax.jms.XATopicSession ; 39 import javax.transaction.RollbackException ; 40 import javax.transaction.SystemException ; 41 import javax.transaction.Transaction ; 42 43 import org.objectweb.util.monolog.api.BasicLevel; 44 50 51 public class JTopicSession extends JSession implements TopicSession { 52 53 protected XATopicConnection xatc; 55 protected TopicSession ts = null; 56 protected XATopicSession xats = null; 57 58 61 public JTopicSession(JConnection jconn, XATopicConnection xatc) { 62 super(jconn); 63 this.xatc = xatc; 64 } 65 66 70 73 protected Session getMOMSession() throws JMSException { 74 return getMOMTopicSession(); 75 } 76 77 protected TopicSession getMOMTopicSession() throws JMSException { 78 Transaction tx = null; 79 try { 80 tx = tm.getTransaction(); 81 } catch (SystemException e) { 82 TraceJms.logger.log(BasicLevel.ERROR,"cannot get Transaction"); 83 } 84 if (tx == null) { 85 if (ts == null) { 86 ts = xatc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 87 jconn.sessionOpen(this); 88 } 89 return ts; 90 } else { 91 if (xats == null) { 92 xats = xatc.createXATopicSession(); 93 if (currtx != null) { 94 TraceJms.logger.log(BasicLevel.ERROR,"mixed transactions"); 95 } 96 currtx = tx; 97 xares = xats.getXAResource(); 98 try { 99 tx.enlistResource(this.getXAResource()); 100 txover = false; 101 } catch (SystemException e) { 102 TraceJms.logger.log(BasicLevel.ERROR,"cannot enlist session:"+e); 103 throw new JMSException (e.toString()); 104 } catch (RollbackException e) { 105 TraceJms.logger.log(BasicLevel.DEBUG,"transaction rolled back"); 106 throw new JMSException (e.toString()); 107 } 108 } 109 return xats.getTopicSession(); 110 } 111 } 112 113 protected void MOMSessionClose() { 114 try { 115 if (xats != null) { 116 xats.close(); 117 xats = null; 118 } 119 if (ts != null) { 120 ts.close(); 121 ts = null; 122 jconn.sessionClose(this); 123 } 124 } catch (JMSException e) { 125 TraceJms.logger.log(BasicLevel.ERROR,"exception:"+e); 126 } 127 } 128 129 133 136 public Topic createTopic(String topicName) throws JMSException { 137 TraceJms.logger.log(BasicLevel.DEBUG, ""); 138 return getMOMTopicSession().createTopic(topicName); 139 } 140 141 144 public TopicSubscriber createSubscriber(Topic topic) 145 throws JMSException { 146 TraceJms.logger.log(BasicLevel.DEBUG, ""); 147 return getMOMTopicSession().createSubscriber(topic); 148 } 149 150 153 public TopicSubscriber createSubscriber(Topic topic, 154 String messageSelector, 155 boolean noLocal) throws JMSException { 156 TraceJms.logger.log(BasicLevel.DEBUG, ""); 157 return getMOMTopicSession().createSubscriber(topic, messageSelector, noLocal); 158 } 159 160 163 public TopicSubscriber createDurableSubscriber(Topic topic, 164 String name) throws JMSException { 165 TraceJms.logger.log(BasicLevel.DEBUG, ""); 166 return getMOMTopicSession().createDurableSubscriber(topic, name); 167 } 168 169 172 public TopicSubscriber createDurableSubscriber(Topic topic, 173 String name, 174 String messageSelector, 175 boolean noLocal) throws JMSException { 176 TraceJms.logger.log(BasicLevel.DEBUG, ""); 177 return getMOMTopicSession().createDurableSubscriber(topic, name, messageSelector, noLocal); 178 } 179 180 183 public TopicPublisher createPublisher(Topic topic) throws JMSException { 184 TraceJms.logger.log(BasicLevel.DEBUG, ""); 185 return getMOMTopicSession().createPublisher(topic); 186 } 187 188 191 public TemporaryTopic createTemporaryTopic() throws JMSException { 192 TraceJms.logger.log(BasicLevel.DEBUG, ""); 193 return getMOMTopicSession().createTemporaryTopic(); 194 } 195 196 199 public void unsubscribe(java.lang.String name) throws JMSException , InvalidDestinationException { 200 TraceJms.logger.log(BasicLevel.DEBUG, ""); 201 getMOMTopicSession().unsubscribe(name); 202 } 203 } 204 | Popular Tags |