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 42 public class SimpleMessageListenerContainer102 extends SimpleMessageListenerContainer { 43 44 47 protected Connection createConnection() throws JMSException { 48 if (isPubSubDomain()) { 49 return ((TopicConnectionFactory ) getConnectionFactory()).createTopicConnection(); 50 } 51 else { 52 return ((QueueConnectionFactory ) getConnectionFactory()).createQueueConnection(); 53 } 54 } 55 56 59 protected Session createSession(Connection con) throws JMSException { 60 if (isPubSubDomain()) { 61 return ((TopicConnection ) con).createTopicSession(isSessionTransacted(), getSessionAcknowledgeMode()); 62 } 63 else { 64 return ((QueueConnection ) con).createQueueSession(isSessionTransacted(), getSessionAcknowledgeMode()); 65 } 66 } 67 68 71 protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException { 72 if (isPubSubDomain()) { 73 if (isSubscriptionDurable()) { 74 return ((TopicSession ) session).createDurableSubscriber( 75 (Topic ) destination, getDurableSubscriptionName(), getMessageSelector(), isPubSubNoLocal()); 76 } 77 else { 78 return ((TopicSession ) session).createSubscriber( 79 (Topic ) destination, getMessageSelector(), isPubSubNoLocal()); 80 } 81 } 82 else { 83 return ((QueueSession ) session).createReceiver((Queue ) destination, getMessageSelector()); 84 } 85 } 86 87 92 protected boolean isClientAcknowledge(Session session) throws JMSException { 93 return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE); 94 } 95 96 } 97 | Popular Tags |