KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > listener > serversession > ServerSessionMessageListenerContainer102


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jms.listener.serversession;
18
19 import javax.jms.Connection JavaDoc;
20 import javax.jms.ConnectionConsumer JavaDoc;
21 import javax.jms.Destination JavaDoc;
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.Queue JavaDoc;
24 import javax.jms.QueueConnection JavaDoc;
25 import javax.jms.QueueConnectionFactory JavaDoc;
26 import javax.jms.ServerSessionPool JavaDoc;
27 import javax.jms.Session JavaDoc;
28 import javax.jms.Topic JavaDoc;
29 import javax.jms.TopicConnection JavaDoc;
30 import javax.jms.TopicConnectionFactory JavaDoc;
31
32 /**
33  * A subclass of ServerSessionMessageListenerContainer that uses the JMS 1.0.2 specification,
34  * rather than the JMS 1.1 methods used by ServerSessionMessageListenerContainer itself.
35  * This class can be used for JMS 1.0.2 providers, offering the same facility as
36  * ServerSessionMessageListenerContainer does for JMS 1.1 providers.
37  *
38  * @author Juergen Hoeller
39  * @since 2.0
40  */

41 public class ServerSessionMessageListenerContainer102 extends ServerSessionMessageListenerContainer {
42
43     /**
44      * This implementation overrides the superclass method to use JMS 1.0.2 API.
45      */

46     protected Connection JavaDoc createConnection() throws JMSException JavaDoc {
47         if (isPubSubDomain()) {
48             return ((TopicConnectionFactory JavaDoc) getConnectionFactory()).createTopicConnection();
49         }
50         else {
51             return ((QueueConnectionFactory JavaDoc) getConnectionFactory()).createQueueConnection();
52         }
53     }
54
55     /**
56      * This implementation overrides the superclass method to use JMS 1.0.2 API.
57      */

58     protected ConnectionConsumer JavaDoc createConsumer(Connection JavaDoc con, Destination JavaDoc destination, ServerSessionPool JavaDoc pool)
59             throws JMSException JavaDoc {
60
61         if (isPubSubDomain()) {
62             if (isSubscriptionDurable()) {
63                 return ((TopicConnection JavaDoc) con).createDurableConnectionConsumer(
64                         (Topic JavaDoc) destination, getDurableSubscriptionName(), getMessageSelector(), pool, getMaxMessagesPerTask());
65             }
66             else {
67                 return ((TopicConnection JavaDoc) con).createConnectionConsumer(
68                         (Topic JavaDoc) destination, getMessageSelector(), pool, getMaxMessagesPerTask());
69             }
70         }
71         else {
72             return ((QueueConnection JavaDoc) con).createConnectionConsumer(
73                     (Queue JavaDoc) destination, getMessageSelector(), pool, getMaxMessagesPerTask());
74         }
75     }
76
77     /**
78      * This implementation overrides the superclass method to use JMS 1.0.2 API.
79      */

80     protected Session JavaDoc createSession(Connection JavaDoc con) throws JMSException JavaDoc {
81         if (isPubSubDomain()) {
82             return ((TopicConnection JavaDoc) con).createTopicSession(isSessionTransacted(), getSessionAcknowledgeMode());
83         }
84         else {
85             return ((QueueConnection JavaDoc) con).createQueueSession(isSessionTransacted(), getSessionAcknowledgeMode());
86         }
87     }
88
89     /**
90      * This implementation overrides the superclass method to avoid using
91      * JMS 1.1's Session <code>getAcknowledgeMode()</code> method.
92      * The best we can do here is to check the setting on the listener container.
93      */

94     protected boolean isClientAcknowledge(Session JavaDoc session) throws JMSException JavaDoc {
95         return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
96     }
97
98 }
99
Popular Tags