KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_jms > JTopicConnectionFactory


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  * --------------------------------------------------------------------------
21  * $Id: JTopicConnectionFactory.java,v 1.8 2004/03/19 14:31:48 sauthieg Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas_jms;
26
27 import javax.jms.JMSException JavaDoc;
28 import javax.jms.TopicConnection JavaDoc;
29 import javax.jms.TopicConnectionFactory JavaDoc;
30 import javax.jms.XATopicConnectionFactory JavaDoc;
31
32 import org.objectweb.util.monolog.api.BasicLevel;
33
34 /**
35  * JTopicConnectionFactory wraps a XATopicConnectionFactory.
36  *
37  * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
38  * Contributor(s):
39  * Philippe Durieux
40  * Jeff Mesnil connection anonymous
41  *
42  */

43 public class JTopicConnectionFactory extends JConnectionFactory implements TopicConnectionFactory JavaDoc {
44     
45     private XATopicConnectionFactory JavaDoc xatcf;
46
47     /**
48      * Constructor.
49      * The underlaying XATopicConnectionFactory is found in the JmsManager.
50      */

51     public JTopicConnectionFactory(String JavaDoc name) {
52         this.name = name;
53         jms = JmsManagerImpl.getJmsManager();
54         xacf = jms.getXATopicConnectionFactory();
55         xatcf = (XATopicConnectionFactory JavaDoc) xacf;
56     }
57
58     // -----------------------------------------------------------------------
59
// TopicConnectionFactory implementation
60
// -----------------------------------------------------------------------
61

62     /**
63      * Create a topic connection for an anonymous user.
64      *
65      * @return a newly created topic connection.
66      * @throws JMSException - if JMS Provider fails to create a Topic
67      * Connection due to some internal error.
68      * @throws JMSSecurityException - if client authentication fails due to
69      * invalid user name or password.
70      */

71     public TopicConnection JavaDoc createTopicConnection() throws JMSException JavaDoc {
72         // Try to reuse a connection from the pool.
73
// Create a new one if no connection available.
74
TraceJms.logger.log(BasicLevel.DEBUG,"");
75         JTopicConnection tc = (JTopicConnection) getJConnection();
76         if (tc == null) {
77             tc = new JTopicConnection(this, xatcf);
78         }
79         return (TopicConnection JavaDoc) tc;
80     }
81
82     /**
83      * Create a topic connection with specified user identity.
84      * The connection is created in stopped mode. No messages will
85      * be delivered until Connection.start method is explicitly called.
86      *
87      * @param userName - the caller's user name
88      * @param password - the caller's password
89      *
90      * @throws JMSException - if JMS Provider fails to create Topic Connection
91      * due to some internal error. required resources for a Topic Connection.
92      * @throws JMSSecurityException - if client authentication fails due to
93      * invalid user name or password.
94      */

95     public TopicConnection JavaDoc createTopicConnection(String JavaDoc userName, String JavaDoc password)
96         throws JMSException JavaDoc {
97         TraceJms.logger.log(BasicLevel.DEBUG,"");
98         // Try to reuse a connection from the pool.
99
// Create a new one if no connection available.
100
JTopicConnection tc = (JTopicConnection) getJConnection(userName);
101         if (tc == null) {
102             tc = new JTopicConnection(this, xatcf, userName, password);
103         }
104         return (TopicConnection JavaDoc) tc;
105     }
106
107 }
108
Popular Tags