KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003 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 package org.objectweb.jonas_jms;
22
23 import java.util.Vector JavaDoc;
24
25 import javax.jms.ConnectionFactory JavaDoc;
26 import javax.jms.Queue JavaDoc;
27 import javax.jms.QueueConnectionFactory JavaDoc;
28 import javax.jms.Topic JavaDoc;
29 import javax.jms.TopicConnectionFactory JavaDoc;
30 import javax.jms.XAConnectionFactory JavaDoc;
31 import javax.jms.XAQueueConnectionFactory JavaDoc;
32 import javax.jms.XATopicConnectionFactory JavaDoc;
33 import javax.naming.InitialContext JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35
36 import org.objectweb.jonas_jms.api.JmsAdministration;
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39
40 /**
41  * WebSphere MQ administration class.
42  * <p>
43  * This WebSphere MQ specific class implements the
44  * <code>JmsAdministration</code> interface. It supposes that administration
45  * is done in parallel within WebSphere MQ (such as creating a queue,
46  * creating and binding the corresponding JMS Queue, etc...).
47  *
48  * @author Frederic Maistre
49  */

50 public class JmsAdminForWSMQ implements JmsAdministration {
51
52     private static String JavaDoc CONN_FACT_NAME="JCF";
53     private static String JavaDoc QUEUE_CONN_FACT_NAME="JQCF";
54     private static String JavaDoc TOPIC_CONN_FACT_NAME="JTCF";
55
56     private InitialContext JavaDoc ictx = null;
57     private Vector JavaDoc namelist = new Vector JavaDoc();
58
59     private XAConnectionFactory JavaDoc xacf = null;
60     private XAQueueConnectionFactory JavaDoc xaqcf = null;
61     private XATopicConnectionFactory JavaDoc xatcf = null;
62     private ConnectionFactory JavaDoc jcf = null;
63     private QueueConnectionFactory JavaDoc jqcf = null;
64     private TopicConnectionFactory JavaDoc jtcf = null;
65
66
67     /**
68      * Empty constructor.
69      * <p>
70      * Class created with <code>newInstance()</code>.
71      */

72     public JmsAdminForWSMQ() {
73     }
74
75     /**
76      * Initialization method, setting the connection factories.
77      * <p>
78      * WebSphere MQ never runs collocated.
79      *
80      * @param collocated Not taken into account.
81      * @param url Not taken into account.
82      *
83      * @exception Exception If creating a connection factory fails.
84      */

85     public void start(boolean collocated, String JavaDoc url) throws Exception JavaDoc {
86
87         // Creating an InitialContext.
88
ictx = new InitialContext JavaDoc();
89
90         // Getting the connection factories that will be used by the
91
// EJB components.
92
try {
93             xacf = (XAConnectionFactory JavaDoc) ictx.lookup("wsmqXACF");
94             ictx.unbind("wsmqXACF");
95         } catch (NamingException JavaDoc exc) {
96             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XAConnectionFactory could not be retrieved from JNDI");
97         }
98         try {
99             xaqcf = (XAQueueConnectionFactory JavaDoc) ictx.lookup("wsmqXAQCF");
100             ictx.unbind("wsmqXAQCF");
101         } catch (NamingException JavaDoc exc) {
102             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XAQueueConnectionFactory could not be retrieved from JNDI");
103         }
104         try {
105             xatcf = (XATopicConnectionFactory JavaDoc) ictx.lookup("wsmqXATCF");
106             ictx.unbind("wsmqXATCF");
107         } catch (NamingException JavaDoc exc) {
108             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XATopicConnectionFactory could not be retrieved from JNDI");
109         }
110          
111         // Getting the connection factories that will be used by pure
112
// JMS clients.
113
try {
114             ictx.lookup(CONN_FACT_NAME);
115             namelist.addElement(CONN_FACT_NAME);
116         } catch (NamingException JavaDoc exc) {
117             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ ConnectionFactory could not be retrieved from JNDI");
118         }
119         try {
120             ictx.lookup(QUEUE_CONN_FACT_NAME);
121             namelist.addElement(QUEUE_CONN_FACT_NAME);
122         } catch (NamingException JavaDoc exc) {
123             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ QueueConnectionFactory could not be retrieved from JNDI");
124         }
125         try {
126             ictx.lookup(TOPIC_CONN_FACT_NAME);
127             namelist.addElement(TOPIC_CONN_FACT_NAME);
128         } catch (NamingException JavaDoc exc) {
129             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ TopicConnectionFactory could not be retrieved from JNDI");
130         }
131     }
132
133     /**
134      * Terminates the JMS Service.
135      */

136     public void stop() {
137         // Cleaning up JNDI.
138
try {
139             ictx.unbind(CONN_FACT_NAME);
140         } catch(Exception JavaDoc ex) {
141         }
142         try {
143             ictx.unbind(QUEUE_CONN_FACT_NAME);
144         } catch(Exception JavaDoc ex) {
145         }
146         try {
147             ictx.unbind(TOPIC_CONN_FACT_NAME);
148         } catch(Exception JavaDoc ex) {
149         }
150
151         if (TraceJms.isDebug())
152             TraceJms.logger.log(BasicLevel.DEBUG, "connection factories unbound");
153     }
154
155
156     /**
157      * Returns the XAConnectionFactory.
158      */

159     public XAConnectionFactory JavaDoc getXAConnectionFactory() {
160         return xacf;
161     }
162
163     /**
164      * Returns the XATopicConnectionFactory.
165      */

166     public XATopicConnectionFactory JavaDoc getXATopicConnectionFactory() {
167         return xatcf;
168     }
169
170     /**
171      * Returns the XAQueueConnectionFactory.
172      */

173     public XAQueueConnectionFactory JavaDoc getXAQueueConnectionFactory() {
174         return xaqcf;
175     }
176
177     /**
178      * Non implemented method: creating a WebSphere MQ destination from JOnAS is not possible.
179      *
180      * @exception Exception Always thrown.
181      */

182     public Queue JavaDoc createQueue(String JavaDoc name) throws Exception JavaDoc {
183         throw new Exception JavaDoc("WebSphere MQ Queue creation impossible from JOnAS");
184     }
185
186     /**
187      * Non implemented method: creating a WebSphere MQ destination from JOnAS is not possible.
188      *
189      * @exception Exception Always thrown.
190      */

191     public Topic JavaDoc createTopic(String JavaDoc name) throws Exception JavaDoc {
192         throw new Exception JavaDoc("WebSphere MQ Topic creation impossible from JOnAS");
193     }
194
195     /**
196      * Non implemented method: deleting a WebSphere MQ destination from JOnAS is not possible.
197      *
198      * @exception Exception Always thrown.
199      */

200     public void deleteDestination(String JavaDoc name) throws Exception JavaDoc {
201         throw new Exception JavaDoc("WebSphere MQ destination deletion impossible from JOnAS");
202     }
203
204     /**
205      * Returns -1; did not have time to find out if getting this information
206      * is possible from a WSMQ Queue.
207      */

208     public int getPendingMessages(javax.jms.Queue JavaDoc queue) throws Exception JavaDoc {
209         return -1;
210     }
211
212     /**
213      * Returns -1; did not have time to find out if getting this information
214      * is possible from a WSMQ Queue.
215      */

216     public int getPendingRequests(javax.jms.Queue JavaDoc queue) throws Exception JavaDoc {
217         return -1;
218     }
219
220     /**
221      * Returns -1; did not test the WSMQ Pub/Sub broker.
222      */

223     public int getSubscriptions(javax.jms.Topic JavaDoc topic) throws Exception JavaDoc {
224         return -1;
225     }
226 }
227
Popular Tags