1 18 package org.apache.activemq.ra; 19 20 21 import javax.jms.*; 22 23 import java.io.Serializable ; 24 25 32 public class InboundSessionProxy implements Session, QueueSession, TopicSession { 33 34 private InboundContext sessionAndProducer; 35 36 public Session getSession() throws JMSException { 37 return getSessionAndProducer().getSession(); 38 } 39 40 public QueueSession getQueueSession() throws JMSException { 41 Session session = getSession(); 42 if (session instanceof QueueSession) { 43 return (QueueSession) session; 44 } 45 else { 46 throw new JMSException("The underlying JMS Session does not support QueueSession semantics: " + session); 47 } 48 } 49 50 public TopicSession getTopicSession() throws JMSException { 51 Session session = getSession(); 52 if (session instanceof TopicSession) { 53 return (TopicSession) session; 54 } 55 else { 56 throw new JMSException("The underlying JMS Session does not support TopicSession semantics: " + session); 57 } 58 } 59 60 public InboundContext getSessionAndProducer() throws JMSException { 61 if( sessionAndProducer==null ) { 62 sessionAndProducer = InboundContextSupport.getActiveSessionAndProducer(); 63 if (sessionAndProducer == null) { 64 throw new JMSException("No currently active Session. This JMS provider cannot be used outside a MessageListener.onMessage() invocation"); 65 } 66 } 67 return sessionAndProducer; 68 } 69 70 public MessageProducer createProducer(Destination destination) throws JMSException { 71 return new InboundMessageProducerProxy(getSessionAndProducer().getMessageProducer(), destination); 72 } 73 74 public void close() throws JMSException { 75 } 78 79 public void commit() throws JMSException { 80 } 82 83 public void rollback() throws JMSException { 84 } 86 87 public void recover() throws JMSException { 88 } 90 91 public void run() { 92 try { 93 getSession().run(); 94 } 95 catch (JMSException e) { 96 throw new RuntimeException ("Failed to run() on session due to: " + e, e); 97 } 98 } 99 100 103 public QueueBrowser createBrowser(Queue queue) throws JMSException { 104 return getSession().createBrowser(queue); 105 } 106 107 public QueueBrowser createBrowser(Queue queue, String s) throws JMSException { 108 return getSession().createBrowser(queue, s); 109 } 110 111 public BytesMessage createBytesMessage() throws JMSException { 112 return getSession().createBytesMessage(); 113 } 114 115 public MessageConsumer createConsumer(Destination destination) throws JMSException { 116 return getSession().createConsumer(destination); 117 } 118 119 public MessageConsumer createConsumer(Destination destination, String s) throws JMSException { 120 return getSession().createConsumer(destination, s); 121 } 122 123 public MessageConsumer createConsumer(Destination destination, String s, boolean b) throws JMSException { 124 return getSession().createConsumer(destination, s, b); 125 } 126 127 public TopicSubscriber createDurableSubscriber(Topic topic, String s) throws JMSException { 128 return getSession().createDurableSubscriber(topic, s); 129 } 130 131 public TopicSubscriber createDurableSubscriber(Topic topic, String s, String s1, boolean b) throws JMSException { 132 return getSession().createDurableSubscriber(topic, s, s1, b); 133 } 134 135 public MapMessage createMapMessage() throws JMSException { 136 return getSession().createMapMessage(); 137 } 138 139 public Message createMessage() throws JMSException { 140 return getSession().createMessage(); 141 } 142 143 public ObjectMessage createObjectMessage() throws JMSException { 144 return getSession().createObjectMessage(); 145 } 146 147 public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException { 148 return getSession().createObjectMessage(serializable); 149 } 150 151 public Queue createQueue(String s) throws JMSException { 152 return getSession().createQueue(s); 153 } 154 155 public StreamMessage createStreamMessage() throws JMSException { 156 return getSession().createStreamMessage(); 157 } 158 159 public TemporaryQueue createTemporaryQueue() throws JMSException { 160 return getSession().createTemporaryQueue(); 161 } 162 163 public TemporaryTopic createTemporaryTopic() throws JMSException { 164 return getSession().createTemporaryTopic(); 165 } 166 167 public TextMessage createTextMessage() throws JMSException { 168 return getSession().createTextMessage(); 169 } 170 171 public TextMessage createTextMessage(String s) throws JMSException { 172 return getSession().createTextMessage(s); 173 } 174 175 public Topic createTopic(String s) throws JMSException { 176 return getSession().createTopic(s); 177 } 178 179 public int getAcknowledgeMode() throws JMSException { 180 return getSession().getAcknowledgeMode(); 181 } 182 183 public MessageListener getMessageListener() throws JMSException { 184 return getSession().getMessageListener(); 185 } 186 187 public boolean getTransacted() throws JMSException { 188 return getSession().getTransacted(); 189 } 190 191 public void setMessageListener(MessageListener messageListener) throws JMSException { 192 getSession().setMessageListener(messageListener); 193 } 194 195 public void unsubscribe(String s) throws JMSException { 196 getSession().unsubscribe(s); 197 } 198 199 public QueueReceiver createReceiver(Queue queue) throws JMSException { 200 return getQueueSession().createReceiver(queue); 201 } 202 203 public QueueReceiver createReceiver(Queue queue, String s) throws JMSException { 204 return getQueueSession().createReceiver(queue, s); 205 } 206 207 public QueueSender createSender(Queue queue) throws JMSException { 208 return new InboundMessageProducerProxy(getSessionAndProducer().getMessageProducer(), queue); 209 } 210 211 public TopicSubscriber createSubscriber(Topic topic) throws JMSException { 212 return getTopicSession().createSubscriber(topic); 213 } 214 215 public TopicSubscriber createSubscriber(Topic topic, String s, boolean b) throws JMSException { 216 return getTopicSession().createSubscriber(topic, s, b); 217 } 218 219 public TopicPublisher createPublisher(Topic topic) throws JMSException { 220 return getTopicSession().createPublisher(topic); 221 } 222 223 public String toString() { 224 try { 225 return "InboundSessionProxy { "+getSession()+" }"; 226 } catch (JMSException e) { 227 return "InboundSessionProxy { null }"; 228 } 229 } 230 231 } 232 | Popular Tags |