001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: */
021: package org.objectweb.jonas_jms;
022:
023: import java.util.Vector;
024:
025: import javax.jms.ConnectionFactory;
026: import javax.jms.Queue;
027: import javax.jms.QueueConnectionFactory;
028: import javax.jms.Topic;
029: import javax.jms.TopicConnectionFactory;
030: import javax.jms.XAConnectionFactory;
031: import javax.jms.XAQueueConnectionFactory;
032: import javax.jms.XATopicConnectionFactory;
033: import javax.naming.InitialContext;
034: import javax.naming.NamingException;
035:
036: import org.objectweb.jonas_jms.api.JmsAdministration;
037: import org.objectweb.util.monolog.api.BasicLevel;
038:
039: /**
040: * WebSphere MQ administration class.
041: * <p>
042: * This WebSphere MQ specific class implements the
043: * <code>JmsAdministration</code> interface. It supposes that administration
044: * is done in parallel within WebSphere MQ (such as creating a queue,
045: * creating and binding the corresponding JMS Queue, etc...).
046: *
047: * @author Frederic Maistre
048: */
049: public class JmsAdminForWSMQ implements JmsAdministration {
050:
051: private static String CONN_FACT_NAME = "JCF";
052: private static String QUEUE_CONN_FACT_NAME = "JQCF";
053: private static String TOPIC_CONN_FACT_NAME = "JTCF";
054:
055: private InitialContext ictx = null;
056: private Vector namelist = new Vector();
057:
058: private XAConnectionFactory xacf = null;
059: private XAQueueConnectionFactory xaqcf = null;
060: private XATopicConnectionFactory xatcf = null;
061: private ConnectionFactory jcf = null;
062: private QueueConnectionFactory jqcf = null;
063: private TopicConnectionFactory jtcf = null;
064:
065: /**
066: * Empty constructor.
067: * <p>
068: * Class created with <code>newInstance()</code>.
069: */
070: public JmsAdminForWSMQ() {
071: }
072:
073: /**
074: * Initialization method, setting the connection factories.
075: * <p>
076: * WebSphere MQ never runs collocated.
077: *
078: * @param collocated Not taken into account.
079: * @param url Not taken into account.
080: *
081: * @exception Exception If creating a connection factory fails.
082: */
083: public void start(boolean collocated, String url) throws Exception {
084:
085: // Creating an InitialContext.
086: ictx = new InitialContext();
087:
088: // Getting the connection factories that will be used by the
089: // EJB components.
090: try {
091: xacf = (XAConnectionFactory) ictx.lookup("wsmqXACF");
092: ictx.unbind("wsmqXACF");
093: } catch (NamingException exc) {
094: TraceJms.logger
095: .log(BasicLevel.ERROR,
096: "WebSphere MQ XAConnectionFactory could not be retrieved from JNDI");
097: }
098: try {
099: xaqcf = (XAQueueConnectionFactory) ictx.lookup("wsmqXAQCF");
100: ictx.unbind("wsmqXAQCF");
101: } catch (NamingException exc) {
102: TraceJms.logger
103: .log(BasicLevel.ERROR,
104: "WebSphere MQ XAQueueConnectionFactory could not be retrieved from JNDI");
105: }
106: try {
107: xatcf = (XATopicConnectionFactory) ictx.lookup("wsmqXATCF");
108: ictx.unbind("wsmqXATCF");
109: } catch (NamingException exc) {
110: TraceJms.logger
111: .log(BasicLevel.ERROR,
112: "WebSphere MQ XATopicConnectionFactory could not be retrieved from JNDI");
113: }
114:
115: // Getting the connection factories that will be used by pure
116: // JMS clients.
117: try {
118: ictx.lookup(CONN_FACT_NAME);
119: namelist.addElement(CONN_FACT_NAME);
120: } catch (NamingException exc) {
121: TraceJms.logger
122: .log(BasicLevel.ERROR,
123: "WebSphere MQ ConnectionFactory could not be retrieved from JNDI");
124: }
125: try {
126: ictx.lookup(QUEUE_CONN_FACT_NAME);
127: namelist.addElement(QUEUE_CONN_FACT_NAME);
128: } catch (NamingException exc) {
129: TraceJms.logger
130: .log(BasicLevel.ERROR,
131: "WebSphere MQ QueueConnectionFactory could not be retrieved from JNDI");
132: }
133: try {
134: ictx.lookup(TOPIC_CONN_FACT_NAME);
135: namelist.addElement(TOPIC_CONN_FACT_NAME);
136: } catch (NamingException exc) {
137: TraceJms.logger
138: .log(BasicLevel.ERROR,
139: "WebSphere MQ TopicConnectionFactory could not be retrieved from JNDI");
140: }
141: }
142:
143: /**
144: * Terminates the JMS Service.
145: */
146: public void stop() {
147: // Cleaning up JNDI.
148: try {
149: ictx.unbind(CONN_FACT_NAME);
150: } catch (Exception ex) {
151: }
152: try {
153: ictx.unbind(QUEUE_CONN_FACT_NAME);
154: } catch (Exception ex) {
155: }
156: try {
157: ictx.unbind(TOPIC_CONN_FACT_NAME);
158: } catch (Exception ex) {
159: }
160:
161: if (TraceJms.isDebug())
162: TraceJms.logger.log(BasicLevel.DEBUG,
163: "connection factories unbound");
164: }
165:
166: /**
167: * Returns the XAConnectionFactory.
168: */
169: public XAConnectionFactory getXAConnectionFactory() {
170: return xacf;
171: }
172:
173: /**
174: * Returns the XATopicConnectionFactory.
175: */
176: public XATopicConnectionFactory getXATopicConnectionFactory() {
177: return xatcf;
178: }
179:
180: /**
181: * Returns the XAQueueConnectionFactory.
182: */
183: public XAQueueConnectionFactory getXAQueueConnectionFactory() {
184: return xaqcf;
185: }
186:
187: /**
188: * Non implemented method: creating a WebSphere MQ destination from JOnAS is not possible.
189: *
190: * @exception Exception Always thrown.
191: */
192: public Queue createQueue(String name) throws Exception {
193: throw new Exception(
194: "WebSphere MQ Queue creation impossible from JOnAS");
195: }
196:
197: /**
198: * Non implemented method: creating a WebSphere MQ destination from JOnAS is not possible.
199: *
200: * @exception Exception Always thrown.
201: */
202: public Topic createTopic(String name) throws Exception {
203: throw new Exception(
204: "WebSphere MQ Topic creation impossible from JOnAS");
205: }
206:
207: /**
208: * Non implemented method: deleting a WebSphere MQ destination from JOnAS is not possible.
209: *
210: * @exception Exception Always thrown.
211: */
212: public void deleteDestination(String name) throws Exception {
213: throw new Exception(
214: "WebSphere MQ destination deletion impossible from JOnAS");
215: }
216:
217: /**
218: * Returns -1; did not have time to find out if getting this information
219: * is possible from a WSMQ Queue.
220: */
221: public int getPendingMessages(javax.jms.Queue queue)
222: throws Exception {
223: return -1;
224: }
225:
226: /**
227: * Returns -1; did not have time to find out if getting this information
228: * is possible from a WSMQ Queue.
229: */
230: public int getPendingRequests(javax.jms.Queue queue)
231: throws Exception {
232: return -1;
233: }
234:
235: /**
236: * Returns -1; did not test the WSMQ Pub/Sub broker.
237: */
238: public int getSubscriptions(javax.jms.Topic topic) throws Exception {
239: return -1;
240: }
241: }
|