1 package org.objectweb.celtix.bus.transports.jms; 2 3 import javax.jms.Destination ; 4 import javax.jms.JMSException ; 5 import javax.jms.MessageConsumer ; 6 import javax.jms.MessageProducer ; 7 import javax.jms.Session ; 8 import javax.jms.TemporaryQueue ; 9 10 21 public class PooledSession { 22 private final Session theSession; 23 private Destination theDestination; 24 private final MessageProducer theProducer; 25 private MessageConsumer theConsumer; 26 27 private String correlationID; 28 29 32 PooledSession(Session session, 33 Destination destination, 34 MessageProducer producer, 35 MessageConsumer consumer) { 36 theSession = session; 37 theDestination = destination; 38 theProducer = producer; 39 theConsumer = consumer; 40 } 41 42 43 46 Session session() { 47 return theSession; 48 } 49 50 51 54 Destination destination() { 55 return theDestination; 56 } 57 58 59 62 void destination(Destination destination) { 63 theDestination = destination; 64 } 65 66 67 70 MessageProducer producer() { 71 return theProducer; 72 } 73 74 75 78 MessageConsumer consumer() { 79 return theConsumer; 80 } 81 82 85 86 String getCorrelationID() throws JMSException { 87 if (correlationID == null && theConsumer != null) { 88 String selector = theConsumer.getMessageSelector(); 90 91 if (selector != null && selector.startsWith("JMSCorrelationID")) { 92 int i = selector.indexOf('\''); 93 correlationID = selector.substring(i + 1, selector.length() - 1); 94 } 95 } 96 97 return correlationID; 98 } 99 100 103 void consumer(MessageConsumer consumer) { 104 theConsumer = consumer; 105 } 106 107 108 void close() throws JMSException { 109 if (theProducer != null) { 110 theProducer.close(); 111 } 112 113 if (theConsumer != null) { 114 theConsumer.close(); 115 } 116 117 if (theDestination instanceof TemporaryQueue ) { 118 ((TemporaryQueue )theDestination).delete(); 119 } 120 121 if (theSession != null) { 122 theSession.close(); 123 } 124 } 125 } 126 | Popular Tags |