1 16 17 package org.springframework.jms.listener; 18 19 import javax.jms.Connection ; 20 import javax.jms.Destination ; 21 import javax.jms.JMSException ; 22 import javax.jms.MessageConsumer ; 23 import javax.jms.Queue ; 24 import javax.jms.QueueConnection ; 25 import javax.jms.QueueConnectionFactory ; 26 import javax.jms.QueueSession ; 27 import javax.jms.Session ; 28 import javax.jms.Topic ; 29 import javax.jms.TopicConnection ; 30 import javax.jms.TopicConnectionFactory ; 31 import javax.jms.TopicSession ; 32 33 import org.springframework.jms.connection.JmsResourceHolder; 34 35 44 public class DefaultMessageListenerContainer102 extends DefaultMessageListenerContainer { 45 46 50 protected Connection getConnection(JmsResourceHolder holder) { 51 return holder.getConnection(isPubSubDomain() ? (Class ) TopicConnection .class : QueueConnection .class); 52 } 53 54 58 protected Session getSession(JmsResourceHolder holder) { 59 return holder.getSession(isPubSubDomain() ? (Class ) TopicSession .class : QueueSession .class); 60 } 61 62 65 protected Connection createConnection() throws JMSException { 66 if (isPubSubDomain()) { 67 return ((TopicConnectionFactory ) getConnectionFactory()).createTopicConnection(); 68 } 69 else { 70 return ((QueueConnectionFactory ) getConnectionFactory()).createQueueConnection(); 71 } 72 } 73 74 77 protected Session createSession(Connection con) throws JMSException { 78 if (isPubSubDomain()) { 79 return ((TopicConnection ) con).createTopicSession(isSessionTransacted(), getSessionAcknowledgeMode()); 80 } 81 else { 82 return ((QueueConnection ) con).createQueueSession(isSessionTransacted(), getSessionAcknowledgeMode()); 83 } 84 } 85 86 89 protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException { 90 if (isPubSubDomain()) { 91 if (isSubscriptionDurable()) { 92 return ((TopicSession ) session).createDurableSubscriber( 93 (Topic ) destination, getDurableSubscriptionName(), getMessageSelector(), isPubSubNoLocal()); 94 } 95 else { 96 return ((TopicSession ) session).createSubscriber( 97 (Topic ) destination, getMessageSelector(), isPubSubNoLocal()); 98 } 99 } 100 else { 101 return ((QueueSession ) session).createReceiver((Queue ) destination, getMessageSelector()); 102 } 103 } 104 105 110 protected boolean isClientAcknowledge(Session session) throws JMSException { 111 return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE); 112 } 113 114 } 115 | Popular Tags |