1 23 package org.objectweb.joram.client.connector; 24 25 import javax.jms.IllegalStateException ; 26 import javax.jms.JMSException ; 27 import javax.jms.Session ; 28 import javax.jms.TopicSubscriber ; 29 30 import org.objectweb.util.monolog.api.BasicLevel; 31 32 36 public class OutboundSession implements javax.jms.Session 37 { 38 39 protected OutboundConnection cnx; 40 41 Session sess; 42 43 44 boolean valid = true; 45 46 47 boolean started = false; 48 49 protected boolean transacted; 50 51 54 OutboundSession(Session sess, OutboundConnection cnx) { 55 this.sess = sess; 56 this.cnx = cnx; 57 cnx.sessions.add(this); 58 59 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 60 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 61 "OutboundSession(" + sess + 62 ", " + cnx + ")" + 63 " cnx.sessions = " + cnx.sessions); 64 } 65 66 69 OutboundSession(Session sess, 70 OutboundConnection cnx, 71 boolean transacted) { 72 this.sess = sess; 73 this.cnx = cnx; 74 this.transacted = transacted; 75 cnx.sessions.add(this); 76 77 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 78 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 79 "OutboundSession(" + sess + 80 ", " + cnx + ")" + 81 " cnx.sessions = " + cnx.sessions); 82 } 83 84 87 public int getAcknowledgeMode() throws JMSException { 88 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 89 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 90 this + " getAcknowledgeMode() = " + sess.getAcknowledgeMode()); 91 92 checkValidity(); 93 if (transacted) 94 return Session.SESSION_TRANSACTED; 95 return sess.getAcknowledgeMode(); 96 } 97 98 101 public boolean getTransacted() throws JMSException { 102 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 103 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 104 this + " getTransacted() = " + sess.getTransacted()); 105 106 checkValidity(); 107 return sess.getTransacted(); 108 } 109 110 114 public void setMessageListener(javax.jms.MessageListener messageListener) 115 throws JMSException 116 { 117 checkValidity(); 118 throw new IllegalStateException ("Forbidden call on a component's session."); 119 } 120 121 125 public javax.jms.MessageListener getMessageListener() throws JMSException 126 { 127 checkValidity(); 128 throw new IllegalStateException ("Forbidden call on a component's session."); 129 } 130 131 134 public javax.jms.Message createMessage() throws JMSException { 135 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 136 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 137 this + " createMessage()"); 138 139 checkValidity(); 140 return sess.createMessage(); 141 } 142 143 146 public javax.jms.TextMessage createTextMessage() throws JMSException { 147 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 148 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 149 this + " createTextMessage()"); 150 151 checkValidity(); 152 return sess.createTextMessage(); 153 } 154 155 158 public javax.jms.TextMessage createTextMessage(String text) 159 throws JMSException { 160 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 161 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 162 this + " createTextMessage(" + text + ")"); 163 164 checkValidity(); 165 return sess.createTextMessage(text); 166 } 167 168 171 public javax.jms.BytesMessage createBytesMessage() throws JMSException 172 { 173 checkValidity(); 174 return sess.createBytesMessage(); 175 } 176 177 180 public javax.jms.MapMessage createMapMessage() throws JMSException 181 { 182 checkValidity(); 183 return sess.createMapMessage(); 184 } 185 186 189 public javax.jms.ObjectMessage createObjectMessage() throws JMSException 190 { 191 checkValidity(); 192 return sess.createObjectMessage(); 193 } 194 195 198 public javax.jms.ObjectMessage createObjectMessage(java.io.Serializable obj) 199 throws JMSException 200 { 201 checkValidity(); 202 return sess.createObjectMessage(obj); 203 } 204 205 208 public javax.jms.StreamMessage createStreamMessage() 209 throws JMSException 210 { 211 checkValidity(); 212 return sess.createStreamMessage(); 213 } 214 215 218 public javax.jms.QueueBrowser 219 createBrowser(javax.jms.Queue queue, String selector) 220 throws JMSException 221 { 222 checkValidity(); 223 return sess.createBrowser(queue, selector); 224 } 225 226 229 public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue) 230 throws JMSException 231 { 232 checkValidity(); 233 return sess.createBrowser(queue); 234 } 235 236 239 public javax.jms.MessageProducer createProducer(javax.jms.Destination dest) 240 throws JMSException { 241 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 242 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createProducer(" + dest + ")"); 243 244 checkValidity(); 245 return new OutboundProducer(sess.createProducer(dest), this); 246 } 247 248 251 public javax.jms.MessageConsumer 252 createConsumer(javax.jms.Destination dest, 253 String selector, 254 boolean noLocal) 255 throws JMSException { 256 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 257 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createConsumer(" + dest + 258 ", " + selector + 259 ", " + noLocal + ")"); 260 261 checkValidity(); 262 return new OutboundConsumer(sess.createConsumer(dest, selector, noLocal), 263 this); 264 } 265 266 269 public javax.jms.MessageConsumer 270 createConsumer(javax.jms.Destination dest, String selector) 271 throws JMSException { 272 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 273 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createConsumer(" + dest + 274 ", " + selector + ")"); 275 276 checkValidity(); 277 return new OutboundConsumer(sess.createConsumer(dest, selector), this); 278 } 279 280 283 public javax.jms.MessageConsumer createConsumer(javax.jms.Destination dest) 284 throws JMSException { 285 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 286 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createConsumer(" + dest + ")"); 287 288 checkValidity(); 289 return new OutboundConsumer(sess.createConsumer(dest), this); 290 } 291 292 295 public javax.jms.TopicSubscriber 296 createDurableSubscriber(javax.jms.Topic topic, 297 String name, 298 String selector, 299 boolean noLocal) 300 throws JMSException { 301 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 302 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 303 this + " createDurableSubscriber(" + topic + 304 ", " + name + 305 ", " + selector + 306 ", " + noLocal + ")"); 307 308 checkValidity(); 309 310 TopicSubscriber sub = 311 sess.createDurableSubscriber(topic, name, selector, noLocal); 312 313 return new OutboundSubscriber(topic, noLocal, sub, this); 314 } 315 316 319 public javax.jms.TopicSubscriber 320 createDurableSubscriber(javax.jms.Topic topic, String name) 321 throws JMSException { 322 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 323 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 324 this + " createDurableSubscriber(" + topic + 325 ", " + name + ")"); 326 327 checkValidity(); 328 329 TopicSubscriber sub = sess.createDurableSubscriber(topic, name); 330 return new OutboundSubscriber(topic, false, sub, this); 331 } 332 333 336 public javax.jms.Queue createQueue(String queueName) throws JMSException { 337 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 338 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 339 this + " createQueue(" + queueName + ")"); 340 341 checkValidity(); 342 return sess.createQueue(queueName); 343 } 344 345 348 public javax.jms.Topic createTopic(String topicName) throws JMSException { 349 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 350 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 351 this + " createTopic(" + topicName + ")"); 352 353 checkValidity(); 354 return sess.createTopic(topicName); 355 } 356 357 360 public javax.jms.TemporaryQueue createTemporaryQueue() throws JMSException { 361 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 362 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 363 this + " createTemporaryQueue()"); 364 365 checkValidity(); 366 return sess.createTemporaryQueue(); 367 } 368 369 372 public javax.jms.TemporaryTopic createTemporaryTopic() throws JMSException { 373 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 374 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 375 this + " createTemporaryTopic()"); 376 377 checkValidity(); 378 return sess.createTemporaryTopic(); 379 } 380 381 382 public void run() 383 {} 384 385 389 public void commit() throws JMSException 390 { 391 checkValidity(); 392 throw new IllegalStateException ("Forbidden call on a component's session."); 393 } 394 395 399 public void rollback() throws JMSException 400 { 401 checkValidity(); 402 throw new IllegalStateException ("Forbidden call on a component's session."); 403 } 404 405 408 public void recover() throws JMSException { 409 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 410 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 411 this + " recover()"); 412 413 checkValidity(); 414 sess.recover(); 415 } 416 417 418 421 public void unsubscribe(String name) throws JMSException { 422 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 423 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 424 this + " unsubscribe(" + name + ")"); 425 426 checkValidity(); 427 sess.unsubscribe(name); 428 } 429 430 433 void start() { 434 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 435 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 436 this + " start() started = true"); 437 438 started = true; 439 } 440 441 445 public void close() throws JMSException { 446 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 447 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 448 this + " close()"); 449 450 valid = false; 451 cnx.sessions.remove(this); 452 started = false; 453 } 454 455 458 public boolean isStarted() { 459 return started; 460 } 461 462 463 void checkValidity() throws IllegalStateException 464 { 465 boolean validity; 466 467 if (! valid) 468 validity = false; 469 else 470 validity = cnx.valid; 471 472 if (! validity) 473 throw new IllegalStateException ("Invalid state: session is closed."); 474 } 475 } 476 | Popular Tags |