1 18 package org.apache.activemq.ra; 19 20 import java.io.Serializable ; 21 22 import javax.jms.BytesMessage ; 23 import javax.jms.Destination ; 24 import javax.jms.IllegalStateException ; 25 import javax.jms.JMSException ; 26 import javax.jms.MapMessage ; 27 import javax.jms.Message ; 28 import javax.jms.MessageConsumer ; 29 import javax.jms.MessageListener ; 30 import javax.jms.MessageProducer ; 31 import javax.jms.ObjectMessage ; 32 import javax.jms.Queue ; 33 import javax.jms.QueueBrowser ; 34 import javax.jms.QueueReceiver ; 35 import javax.jms.QueueSender ; 36 import javax.jms.QueueSession ; 37 import javax.jms.Session ; 38 import javax.jms.StreamMessage ; 39 import javax.jms.TemporaryQueue ; 40 import javax.jms.TemporaryTopic ; 41 import javax.jms.TextMessage ; 42 import javax.jms.Topic ; 43 import javax.jms.TopicPublisher ; 44 import javax.jms.TopicSession ; 45 import javax.jms.TopicSubscriber ; 46 47 import org.apache.activemq.ActiveMQSession; 48 49 55 public class ManagedSessionProxy implements Session , QueueSession , TopicSession { 56 57 private final ActiveMQSession session; 58 boolean closed = false; 59 60 public ManagedSessionProxy(ActiveMQSession session) { 61 this.session = session; 62 } 63 64 public void setUseSharedTxContext(boolean enable) throws JMSException { 65 if( session.getTransactionContext() !=null ) { 66 ((ManagedTransactionContext)session.getTransactionContext()).setUseSharedTxContext(enable); 67 } 68 } 69 70 73 public void close() throws JMSException { 74 cleanup(); 75 } 76 77 83 public void cleanup() throws JMSException { 84 closed = true; 85 session.close(); 86 } 87 88 91 private Session getSession() throws JMSException { 92 if (closed) { 93 throw new IllegalStateException ("The Session is closed"); 94 } 95 return session; 96 } 97 98 101 public void commit() throws JMSException { 102 getSession().commit(); 103 } 104 105 110 public QueueBrowser createBrowser(Queue queue) throws JMSException { 111 return getSession().createBrowser(queue); 112 } 113 114 120 public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException { 121 return getSession().createBrowser(queue, messageSelector); 122 } 123 124 128 public BytesMessage createBytesMessage() throws JMSException { 129 return getSession().createBytesMessage(); 130 } 131 132 137 public MessageConsumer createConsumer(Destination destination) throws JMSException { 138 return getSession().createConsumer(destination); 139 } 140 141 147 public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException { 148 return getSession().createConsumer(destination, messageSelector); 149 } 150 151 158 public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean NoLocal) 159 throws JMSException { 160 return getSession().createConsumer(destination, messageSelector, NoLocal); 161 } 162 163 169 public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException { 170 return getSession().createDurableSubscriber(topic, name); 171 } 172 173 181 public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) 182 throws JMSException { 183 return getSession().createDurableSubscriber(topic, name, messageSelector, noLocal); 184 } 185 186 190 public MapMessage createMapMessage() throws JMSException { 191 return getSession().createMapMessage(); 192 } 193 194 198 public Message createMessage() throws JMSException { 199 return getSession().createMessage(); 200 } 201 202 206 public ObjectMessage createObjectMessage() throws JMSException { 207 return getSession().createObjectMessage(); 208 } 209 210 215 public ObjectMessage createObjectMessage(Serializable object) throws JMSException { 216 return getSession().createObjectMessage(object); 217 } 218 219 224 public MessageProducer createProducer(Destination destination) throws JMSException { 225 return getSession().createProducer(destination); 226 } 227 228 233 public Queue createQueue(String queueName) throws JMSException { 234 return getSession().createQueue(queueName); 235 } 236 237 241 public StreamMessage createStreamMessage() throws JMSException { 242 return getSession().createStreamMessage(); 243 } 244 245 249 public TemporaryQueue createTemporaryQueue() throws JMSException { 250 return getSession().createTemporaryQueue(); 251 } 252 253 257 public TemporaryTopic createTemporaryTopic() throws JMSException { 258 return getSession().createTemporaryTopic(); 259 } 260 261 265 public TextMessage createTextMessage() throws JMSException { 266 return getSession().createTextMessage(); 267 } 268 269 274 public TextMessage createTextMessage(String text) throws JMSException { 275 return getSession().createTextMessage(text); 276 } 277 278 283 public Topic createTopic(String topicName) throws JMSException { 284 return getSession().createTopic(topicName); 285 } 286 287 291 public int getAcknowledgeMode() throws JMSException { 292 return getSession().getAcknowledgeMode(); 293 } 294 295 299 public MessageListener getMessageListener() throws JMSException { 300 return getSession().getMessageListener(); 301 } 302 303 307 public boolean getTransacted() throws JMSException { 308 return getSession().getTransacted(); 309 } 310 311 314 public void recover() throws JMSException { 315 getSession().recover(); 316 } 317 318 321 public void rollback() throws JMSException { 322 getSession().rollback(); 323 } 324 325 329 public void setMessageListener(MessageListener listener) throws JMSException { 330 getSession(); } 332 333 337 public void unsubscribe(String name) throws JMSException { 338 getSession().unsubscribe(name); 339 } 340 341 346 public QueueReceiver createReceiver(Queue queue) throws JMSException { 347 return ((QueueSession ) getSession()).createReceiver(queue); 348 } 349 350 356 public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { 357 return ((QueueSession ) getSession()).createReceiver(queue, messageSelector); 358 } 359 360 365 public QueueSender createSender(Queue queue) throws JMSException { 366 return ((QueueSession ) getSession()).createSender(queue); 367 } 368 369 374 public TopicPublisher createPublisher(Topic topic) throws JMSException { 375 return ((TopicSession ) getSession()).createPublisher(topic); 376 } 377 378 383 public TopicSubscriber createSubscriber(Topic topic) throws JMSException { 384 return ((TopicSession ) getSession()).createSubscriber(topic); 385 } 386 387 394 public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException { 395 return ((TopicSession ) getSession()).createSubscriber(topic, messageSelector, noLocal); 396 } 397 398 401 public void run() { 402 throw new RuntimeException ("Operation not supported."); 403 } 404 405 public String toString() { 406 return "ManagedSessionProxy { "+session+" }"; 407 } 408 409 } 410 | Popular Tags |