commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger JNDISessionFactory.java
Date Fri, 15 Feb 2002 15:54:08 GMT
jstrachan    02/02/15 07:54:08

  Modified:    messenger/src/conf Messenger.xml MessengerAshna.xml
                        MessengerJBoss.xml
               messenger/src/java/org/apache/commons/messenger
                        JNDISessionFactory.java
  Log:
  Applied Saimon's patch to differentiate between Topic and Queue Connections via a boolean
property in the digester XML file as sometimes a Connection object implements both interfaces
- such as JBossMQ
  
  Revision  Changes    Path
  1.4       +6 -6      jakarta-commons-sandbox/messenger/src/conf/Messenger.xml
  
  Index: Messenger.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/conf/Messenger.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Messenger.xml	30 Oct 2001 08:30:09 -0000	1.3
  +++ Messenger.xml	15 Feb 2002 15:54:08 -0000	1.4
  @@ -4,21 +4,21 @@
     <!-- this example Messenger XML config file should work with J2EE SDK -->
     <!-- when running inside of a J2EE container                          -->
   
  -  <messenger name="topic">
  -    <jndi lookupName="java:comp/env/TopicConnectionFactory">
  +  <messenger name="topic" jndiDestinations="false">
  +    <jndi lookupName="java:comp/env/TopicConnectionFactory" topic="true">
         <property>
           <name>com.sun.jms.internal.java.naming.factory.initial</name>
           <value>com.sun.enterprise.naming.SerialInitContextFactory</value>
  -      </property>          
  +      </property>
       </jndi>
     </messenger>
   
  -  <messenger name="queue">
  -    <jndi lookupName="java:comp/env/QueueConnectionFactory">
  +  <messenger name="queue" jndiDestinations="false">
  +    <jndi lookupName="java:comp/env/QueueConnectionFactory" topic="false">
         <property>
           <name>com.sun.jms.internal.java.naming.factory.initial</name>
           <value>com.sun.enterprise.naming.SerialInitContextFactory</value>
  -      </property>          
  +      </property>
       </jndi>
     </messenger>
   
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/messenger/src/conf/MessengerAshna.xml
  
  Index: MessengerAshna.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/conf/MessengerAshna.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MessengerAshna.xml	15 Feb 2002 11:50:18 -0000	1.1
  +++ MessengerAshna.xml	15 Feb 2002 15:54:08 -0000	1.2
  @@ -5,7 +5,7 @@
     <!-- when running outside of a J2EE container                         -->
   
     <messenger name="topic" jndiDestinations="true">
  -    <jndi lookupName="TopicConnectionFactory">
  +    <jndi lookupName="TopicConnectionFactory" topic="true">
         <property>
           <name>java.naming.factory.initial</name>
           <value>com.ashnasoft.jms.client.jndi.InitialContextFactoryImpl</value>
  @@ -18,7 +18,7 @@
     </messenger>
   
     <messenger name="queue" jndiDestinations="true">
  -    <jndi lookupName="QueueConnectionFactory">
  +    <jndi lookupName="QueueConnectionFactory" topic="false">
         <property>
           <name>java.naming.factory.initial</name>
           <value>com.ashnasoft.jms.client.jndi.InitialContextFactoryImpl</value>
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/messenger/src/conf/MessengerJBoss.xml
  
  Index: MessengerJBoss.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/conf/MessengerJBoss.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MessengerJBoss.xml	15 Feb 2002 11:50:18 -0000	1.1
  +++ MessengerJBoss.xml	15 Feb 2002 15:54:08 -0000	1.2
  @@ -5,7 +5,7 @@
     <!-- when running outside of a J2EE container                         -->
   
     <messenger name="topic" jndiDestinations="true">
  -    <jndi lookupName="TopicConnectionFactory">
  +    <jndi lookupName="TopicConnectionFactory" topic="true">
         <property>
           <name>java.naming.factory.initial</name>
           <value>org.jnp.interfaces.NamingContextFactory</value>
  @@ -22,7 +22,7 @@
     </messenger>
   
     <messenger name="queue" jndiDestinations="true">
  -    <jndi lookupName="QueueConnectionFactory">
  +    <jndi lookupName="QueueConnectionFactory" topic="false">
         <property>
           <name>java.naming.factory.initial</name>
           <value>org.jnp.interfaces.NamingContextFactory</value>
  
  
  
  1.4       +76 -22    jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/JNDISessionFactory.java
  
  Index: JNDISessionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/JNDISessionFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JNDISessionFactory.java	29 Aug 2001 10:31:55 -0000	1.3
  +++ JNDISessionFactory.java	15 Feb 2002 15:54:08 -0000	1.4
  @@ -4,8 +4,8 @@
    * This software is published under the terms of the Apache Software License
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
  - * 
  - * $Id: JNDISessionFactory.java,v 1.3 2001/08/29 10:31:55 jstrachan Exp $
  + *
  + * $Id: JNDISessionFactory.java,v 1.4 2002/02/15 15:54:08 jstrachan Exp $
    */
   package org.apache.commons.messenger;
   
  @@ -13,42 +13,60 @@
   import java.util.Properties;
   
   import javax.jms.ConnectionFactory;
  +import javax.jms.Connection;
  +import javax.jms.Session;
  +import javax.jms.TopicConnection;
  +import javax.jms.QueueConnection;
  +import javax.jms.TopicConnectionFactory;
  +import javax.jms.QueueConnectionFactory;
   import javax.jms.JMSException;
   
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
  +import javax.naming.NamingEnumeration;
   
   
   /** <p><code>JNDISessionFactory</code> is a Factory of JMS Session objects
     * which looks up the ConnectionFactory object from JNDI.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class JNDISessionFactory extends SessionFactory {
   
       /** the initial JNDI context used to lookup ConnectionFactory objects */
  -    private Context context;
  -    
  +    public Context context;
  +
       /** the name used to lookup the ConnectionFactory */
       private String lookupName = "TopicConnectionFactory";
  -    
  -    
  -    
  +
  +    /** Wether Topics or Queue Connections should be forced */
  +    private boolean topic = false;
  +
       // Properties
  -    //-------------------------------------------------------------------------    
  -    
  +    //-------------------------------------------------------------------------
  +
       /** The JNDI Name of the ConnectionFactory */
       public String getLookupName() {
  -        return lookupName;        
  +        return lookupName;
       }
  -    
  +
       /** Sets the JNDI Name of the ConnectionFactory */
       public void setLookupName(String lookupName) {
  -        this.lookupName = lookupName;        
  +        this.lookupName = lookupName;
  +    }
  +
  +    /** To force Topic or Queue Connections */
  +    public void setTopic(boolean topic) {
  +    this.topic = topic;
       }
  -    
  +
  +    /** To force Topic or Queue Connections */
  +    public boolean isTopic() {
  +        return topic;
  +    }
  +
       /** Returns the JNDI Context used to lookup JMS ConnectionFactory objects */
       public Context getContext() throws NamingException {
           if ( context == null ) {
  @@ -56,21 +74,27 @@
           }
           return context;
       }
  -    
  +
       public void setContext(Context context) {
           this.context = context;
       }
  -    
  +
       // Implementation methods
  -    //-------------------------------------------------------------------------    
  -    
  -    /** Factory method used to create a connection factory. 
  +    //-------------------------------------------------------------------------
  +
  +    /** Factory method used to create a connection factory.
         * Lookup the ConnectionFactory in JNDI
         */
       protected ConnectionFactory createConnectionFactory() throws JMSException {
           try {
  -            //System.out.println( "Looking up: " + getLookupName() + " in JNDI" );
  -            return (ConnectionFactory) getContext().lookup( getLookupName() );
  +            System.out.println( "Looking up: " + getLookupName() + " in JNDI" );
  +
  +            if (!topic) {
  +                return (QueueConnectionFactory) getContext().lookup(getLookupName());
  +            }
  +
  +            else return (TopicConnectionFactory) getContext().lookup(getLookupName());
  +
           }
           catch (NamingException e) {
               JMSException jmsException = new JMSException( "Failed to lookup: " + getLookupName()
+ " using JNDI. " + e );
  @@ -78,7 +102,37 @@
               throw jmsException;
           }
       }
  -    /** Factory method used to create a connection factory. 
  +
  +    /** Re-implemented from SessionFactory. Method used to create a connection */
  +    public Connection createConnection() throws JMSException {
  +        ConnectionFactory factory = getConnectionFactory();
  +
  +        if ( factory == null ) {
  +            throw new JMSException( "No ConnectionFactory configured. Cannot create a JMS
Session" );
  +        }
  +
  +        if (!topic) {
  +            return createQueueConnection((QueueConnectionFactory) factory);
  +        }
  +
  +        else return createTopicConnection((TopicConnectionFactory) factory);
  +    }
  +
  +    /** Re-implemented from SessionFactory. Creates a new Session instance */
  +    public Session createSession(Connection connection) throws JMSException {
  +
  +         if (!topic) {
  +                QueueConnection queueConnection = (QueueConnection) connection;
  +                return queueConnection.createQueueSession( isTransacted(), getAcknowledgeMode()
);
  +            }
  +
  +           else {
  +                TopicConnection topicConnection = (TopicConnection) connection;
  +                return topicConnection.createTopicSession( isTransacted(), getAcknowledgeMode()
);
  +            }
  +    }
  +
  +    /** Factory method used to create a connection factory.
         * Derived classes may wish to use JNDI to load the ConnectionFactory
         */
       protected Context createContext() throws NamingException {
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message