1 7 package org.jboss.jms.client; 8 9 import java.io.Serializable ; 10 11 import javax.jms.BytesMessage ; 12 import javax.jms.Destination ; 13 import javax.jms.JMSException ; 14 import javax.jms.MapMessage ; 15 import javax.jms.Message ; 16 import javax.jms.MessageConsumer ; 17 import javax.jms.MessageListener ; 18 import javax.jms.MessageProducer ; 19 import javax.jms.ObjectMessage ; 20 import javax.jms.Queue ; 21 import javax.jms.QueueBrowser ; 22 import javax.jms.QueueReceiver ; 23 import javax.jms.QueueSender ; 24 import javax.jms.QueueSession ; 25 import javax.jms.Session ; 26 import javax.jms.StreamMessage ; 27 import javax.jms.TemporaryQueue ; 28 import javax.jms.TemporaryTopic ; 29 import javax.jms.TextMessage ; 30 import javax.jms.Topic ; 31 import javax.jms.TopicPublisher ; 32 import javax.jms.TopicSession ; 33 import javax.jms.TopicSubscriber ; 34 import javax.jms.XAQueueSession ; 35 import javax.jms.XASession ; 36 import javax.jms.XATopicSession ; 37 import javax.transaction.xa.XAResource ; 38 39 import org.jboss.jms.destination.JBossTemporaryDestination; 40 41 47 public class JBossSession 48 implements Session , QueueSession , TopicSession , 49 XASession , XAQueueSession , XATopicSession 50 { 51 53 54 private static String defaultSelector = null; 55 56 57 private static boolean defaultNoLocal = false; 58 59 61 62 private SessionDelegate delegate; 63 64 65 private boolean isXA; 66 67 68 private boolean transacted; 69 70 71 private int acknowledgeMode; 72 73 74 private MessageListener listener; 75 76 78 80 82 91 public JBossSession(SessionDelegate delegate, boolean isXA, boolean transacted, int acknowledgeMode) 92 throws JMSException 93 { 94 this.delegate = delegate; 95 this.isXA = isXA; 96 this.transacted = transacted; 97 this.acknowledgeMode = acknowledgeMode; 98 } 99 100 102 public void close() throws JMSException 103 { 104 delegate.closing(); 105 delegate.close(); 106 } 107 108 public void commit() throws JMSException 109 { 110 if (transacted == false) 111 throw new JMSException ("Not a transacted session"); 112 delegate.commit(); 113 } 114 115 public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException 116 { 117 if (queue == null) 118 throw new JMSException ("Null queue"); 119 return new JBossBrowser(delegate.createBrowser(queue, messageSelector), queue, messageSelector); 120 } 121 122 public QueueBrowser createBrowser(Queue queue) throws JMSException 123 { 124 return createBrowser(queue, defaultSelector); 125 } 126 127 public BytesMessage createBytesMessage() throws JMSException 128 { 129 return delegate.createBytesMessage(); 130 } 131 132 public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) 133 throws JMSException 134 { 135 if (destination == null) 136 throw new JMSException ("Null destination"); 137 return new JBossConsumer(delegate.createConsumer(destination, null, messageSelector, noLocal), destination, messageSelector, noLocal); 138 } 139 140 public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException 141 { 142 return createConsumer(destination, messageSelector, defaultNoLocal); 143 } 144 145 public MessageConsumer createConsumer(Destination destination) throws JMSException 146 { 147 return createConsumer(destination, defaultSelector, defaultNoLocal); 148 } 149 150 public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) 151 throws JMSException 152 { 153 if (topic == null) 154 throw new JMSException ("Null topic"); 155 if (name == null) 156 throw new JMSException ("Null subscription"); 157 return (TopicSubscriber ) delegate.createConsumer(topic, name, messageSelector, noLocal); 158 } 159 160 public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException 161 { 162 return (TopicSubscriber ) createDurableSubscriber(topic, name, null, defaultNoLocal); 163 } 164 165 public MapMessage createMapMessage() throws JMSException 166 { 167 return delegate.createMapMessage(); 168 } 169 170 public Message createMessage() throws JMSException 171 { 172 return delegate.createMessage(); 173 } 174 175 public ObjectMessage createObjectMessage() throws JMSException 176 { 177 return createObjectMessage(null); 178 } 179 180 public ObjectMessage createObjectMessage(Serializable object) throws JMSException 181 { 182 return delegate.createObjectMessage(object); 183 } 184 185 public MessageProducer createProducer(Destination destination) throws JMSException 186 { 187 return new JBossProducer(delegate.createProducer(destination), destination); 188 } 189 190 public Queue createQueue(String queueName) throws JMSException 191 { 192 return (Queue ) delegate.getDestination(queueName); 193 } 194 195 public StreamMessage createStreamMessage() throws JMSException 196 { 197 return delegate.createStreamMessage(); 198 } 199 200 public TemporaryQueue createTemporaryQueue() throws JMSException 201 { 202 return (TemporaryQueue ) delegate.createTempDestination(JBossTemporaryDestination.TEMPORARY_QUEUE); 203 } 204 205 public TemporaryTopic createTemporaryTopic() throws JMSException 206 { 207 return (TemporaryTopic ) delegate.createTempDestination(JBossTemporaryDestination.TEMPORARY_TOPIC); 208 } 209 210 public TextMessage createTextMessage() throws JMSException 211 { 212 return createTextMessage(null); 213 } 214 215 public TextMessage createTextMessage(String text) throws JMSException 216 { 217 return delegate.createTextMessage(text); 218 } 219 220 public Topic createTopic(String topicName) throws JMSException 221 { 222 return (Topic ) delegate.getDestination(topicName); 223 } 224 225 public int getAcknowledgeMode() throws JMSException 226 { 227 return acknowledgeMode; 228 } 229 230 public MessageListener getMessageListener() throws JMSException 231 { 232 return listener; 233 } 234 235 public boolean getTransacted() throws JMSException 236 { 237 return transacted; 238 } 239 240 public void recover() throws JMSException 241 { 242 delegate.recover(); 243 } 244 245 public void rollback() throws JMSException 246 { 247 if (transacted == false) 248 throw new JMSException ("Not a transacted session"); 249 delegate.rollback(); 250 } 251 252 public void run() 253 { 254 if (listener == null) 255 throw new IllegalStateException ("No message listener"); 256 delegate.run(); 257 } 258 259 public void setMessageListener(MessageListener listener) throws JMSException 260 { 261 delegate.setMessageListener(listener); 262 this.listener = listener; 263 } 264 265 public void unsubscribe(String name) throws JMSException 266 { 267 delegate.unsubscribe(name); 268 } 269 270 272 public Session getSession() throws JMSException 273 { 274 return this; 275 } 276 277 public XAResource getXAResource() 278 { 279 if (isXA == false) 280 throw new IllegalArgumentException ("Not an XASession"); 281 return delegate.getXAResource(); 282 } 283 284 286 public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException 287 { 288 return (QueueReceiver ) createConsumer(queue, messageSelector); 289 } 290 291 public QueueReceiver createReceiver(Queue queue) throws JMSException 292 { 293 return (QueueReceiver ) createConsumer(queue); 294 } 295 296 public QueueSender createSender(Queue queue) throws JMSException 297 { 298 return (QueueSender ) createProducer(queue); 299 } 300 301 303 public TopicSubscriber createSubscriber(Topic topic) throws JMSException 304 { 305 return (TopicSubscriber ) createConsumer(topic); 306 } 307 308 public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException 309 { 310 return (TopicSubscriber ) createConsumer(topic, messageSelector, noLocal); 311 } 312 313 public TopicPublisher createPublisher(Topic topic) throws JMSException 314 { 315 return (TopicPublisher ) createProducer(topic); 316 } 317 318 320 public QueueSession getQueueSession() throws JMSException 321 { 322 return (QueueSession ) getSession(); 323 } 324 325 327 public TopicSession getTopicSession() throws JMSException 328 { 329 return (TopicSession ) getSession(); 330 } 331 332 334 336 338 } 340 | Popular Tags |