001: /*
002: * Copyright 2002-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jms.listener.serversession;
018:
019: import javax.jms.Connection;
020: import javax.jms.ConnectionConsumer;
021: import javax.jms.Destination;
022: import javax.jms.JMSException;
023: import javax.jms.Queue;
024: import javax.jms.QueueConnection;
025: import javax.jms.QueueConnectionFactory;
026: import javax.jms.ServerSessionPool;
027: import javax.jms.Session;
028: import javax.jms.Topic;
029: import javax.jms.TopicConnection;
030: import javax.jms.TopicConnectionFactory;
031:
032: /**
033: * A subclass of ServerSessionMessageListenerContainer that uses the JMS 1.0.2 specification,
034: * rather than the JMS 1.1 methods used by ServerSessionMessageListenerContainer itself.
035: * This class can be used for JMS 1.0.2 providers, offering the same facility as
036: * ServerSessionMessageListenerContainer does for JMS 1.1 providers.
037: *
038: * @author Juergen Hoeller
039: * @since 2.0
040: */
041: public class ServerSessionMessageListenerContainer102 extends
042: ServerSessionMessageListenerContainer {
043:
044: /**
045: * This implementation overrides the superclass method to use JMS 1.0.2 API.
046: */
047: protected Connection createConnection() throws JMSException {
048: if (isPubSubDomain()) {
049: return ((TopicConnectionFactory) getConnectionFactory())
050: .createTopicConnection();
051: } else {
052: return ((QueueConnectionFactory) getConnectionFactory())
053: .createQueueConnection();
054: }
055: }
056:
057: /**
058: * This implementation overrides the superclass method to use JMS 1.0.2 API.
059: */
060: protected ConnectionConsumer createConsumer(Connection con,
061: Destination destination, ServerSessionPool pool)
062: throws JMSException {
063:
064: if (isPubSubDomain()) {
065: if (isSubscriptionDurable()) {
066: return ((TopicConnection) con)
067: .createDurableConnectionConsumer(
068: (Topic) destination,
069: getDurableSubscriptionName(),
070: getMessageSelector(), pool,
071: getMaxMessagesPerTask());
072: } else {
073: return ((TopicConnection) con)
074: .createConnectionConsumer((Topic) destination,
075: getMessageSelector(), pool,
076: getMaxMessagesPerTask());
077: }
078: } else {
079: return ((QueueConnection) con).createConnectionConsumer(
080: (Queue) destination, getMessageSelector(), pool,
081: getMaxMessagesPerTask());
082: }
083: }
084:
085: /**
086: * This implementation overrides the superclass method to use JMS 1.0.2 API.
087: */
088: protected Session createSession(Connection con) throws JMSException {
089: if (isPubSubDomain()) {
090: return ((TopicConnection) con).createTopicSession(
091: isSessionTransacted(), getSessionAcknowledgeMode());
092: } else {
093: return ((QueueConnection) con).createQueueSession(
094: isSessionTransacted(), getSessionAcknowledgeMode());
095: }
096: }
097:
098: /**
099: * This implementation overrides the superclass method to avoid using
100: * JMS 1.1's Session <code>getAcknowledgeMode()</code> method.
101: * The best we can do here is to check the setting on the listener container.
102: */
103: protected boolean isClientAcknowledge(Session session)
104: throws JMSException {
105: return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
106: }
107:
108: }
|