JmsAdminForWSMQ.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 2003 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  */
00021 package org.objectweb.jonas_jms;
00022 
00023 import java.util.Vector;
00024 
00025 import javax.jms.ConnectionFactory;
00026 import javax.jms.Queue;
00027 import javax.jms.QueueConnectionFactory;
00028 import javax.jms.Topic;
00029 import javax.jms.TopicConnectionFactory;
00030 import javax.jms.XAConnectionFactory;
00031 import javax.jms.XAQueueConnectionFactory;
00032 import javax.jms.XATopicConnectionFactory;
00033 import javax.naming.InitialContext;
00034 import javax.naming.NamingException;
00035 
00036 import org.objectweb.jonas_jms.api.JmsAdministration;
00037 import org.objectweb.util.monolog.api.BasicLevel;
00038 
00039 
00050 public class JmsAdminForWSMQ implements JmsAdministration {
00051 
00052     private static String CONN_FACT_NAME="JCF";
00053     private static String QUEUE_CONN_FACT_NAME="JQCF";
00054     private static String TOPIC_CONN_FACT_NAME="JTCF";
00055 
00056     private InitialContext ictx = null;
00057     private Vector namelist = new Vector();
00058 
00059     private XAConnectionFactory xacf = null;
00060     private XAQueueConnectionFactory xaqcf = null;
00061     private XATopicConnectionFactory xatcf = null;
00062     private ConnectionFactory jcf = null;
00063     private QueueConnectionFactory jqcf = null;
00064     private TopicConnectionFactory jtcf = null;
00065 
00066 
00072     public JmsAdminForWSMQ() {
00073     }
00074 
00085     public void start(boolean collocated, String url) throws Exception {
00086 
00087         // Creating an InitialContext.
00088         ictx = new InitialContext();
00089 
00090         // Getting the connection factories that will be used by the
00091         // EJB components.
00092         try {
00093             xacf = (XAConnectionFactory) ictx.lookup("wsmqXACF");
00094             ictx.unbind("wsmqXACF");
00095         } catch (NamingException exc) {
00096             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XAConnectionFactory could not be retrieved from JNDI");
00097         }
00098         try {
00099             xaqcf = (XAQueueConnectionFactory) ictx.lookup("wsmqXAQCF");
00100             ictx.unbind("wsmqXAQCF");
00101         } catch (NamingException exc) {
00102             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XAQueueConnectionFactory could not be retrieved from JNDI");
00103         }
00104         try {
00105             xatcf = (XATopicConnectionFactory) ictx.lookup("wsmqXATCF");
00106             ictx.unbind("wsmqXATCF");
00107         } catch (NamingException exc) {
00108             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ XATopicConnectionFactory could not be retrieved from JNDI");
00109         }
00110          
00111         // Getting the connection factories that will be used by pure
00112         // JMS clients.
00113         try {
00114             ictx.lookup(CONN_FACT_NAME);
00115             namelist.addElement(CONN_FACT_NAME);
00116         } catch (NamingException exc) {
00117             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ ConnectionFactory could not be retrieved from JNDI");
00118         }
00119         try {
00120             ictx.lookup(QUEUE_CONN_FACT_NAME);
00121             namelist.addElement(QUEUE_CONN_FACT_NAME);
00122         } catch (NamingException exc) {
00123             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ QueueConnectionFactory could not be retrieved from JNDI");
00124         }
00125         try {
00126             ictx.lookup(TOPIC_CONN_FACT_NAME);
00127             namelist.addElement(TOPIC_CONN_FACT_NAME);
00128         } catch (NamingException exc) {
00129             TraceJms.logger.log(BasicLevel.ERROR, "WebSphere MQ TopicConnectionFactory could not be retrieved from JNDI");
00130         }
00131     }
00132 
00136     public void stop() {
00137         // Cleaning up JNDI.
00138         try {               
00139             ictx.unbind(CONN_FACT_NAME);
00140         } catch(Exception ex) {
00141         }
00142         try {               
00143             ictx.unbind(QUEUE_CONN_FACT_NAME);
00144         } catch(Exception ex) {
00145         }
00146         try {               
00147             ictx.unbind(TOPIC_CONN_FACT_NAME);
00148         } catch(Exception ex) {
00149         }
00150 
00151         if (TraceJms.isDebug())
00152             TraceJms.logger.log(BasicLevel.DEBUG, "connection factories unbound");
00153     }
00154 
00155 
00159     public XAConnectionFactory getXAConnectionFactory() {
00160         return xacf;
00161     }
00162 
00166     public XATopicConnectionFactory getXATopicConnectionFactory() {
00167         return xatcf;
00168     }
00169 
00173     public XAQueueConnectionFactory getXAQueueConnectionFactory() {
00174         return xaqcf;
00175     }
00176 
00182     public Queue createQueue(String name) throws Exception {
00183         throw new Exception("WebSphere MQ Queue creation impossible from JOnAS");
00184     }
00185 
00191     public Topic createTopic(String name) throws Exception {
00192         throw new Exception("WebSphere MQ Topic creation impossible from JOnAS");
00193     }
00194 
00200     public void deleteDestination(String name) throws Exception {
00201         throw new Exception("WebSphere MQ destination deletion impossible from JOnAS");
00202     }
00203 
00208     public int getPendingMessages(javax.jms.Queue queue) throws Exception {
00209         return -1;
00210     }
00211 
00216     public int getPendingRequests(javax.jms.Queue queue) throws Exception {
00217         return -1;
00218     }
00219 
00223     public int getSubscriptions(javax.jms.Topic topic) throws Exception {
00224         return -1;
00225     }
00226 }

Generated on Tue Feb 15 15:05:49 2005 for JOnAS by  doxygen 1.3.9.1