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 DefaultMessenger.java MessengerSupport.java
Date Fri, 15 Feb 2002 11:50:18 GMT
jstrachan    02/02/15 03:50:18

  Modified:    messenger PROPOSAL.html STATUS.html
               messenger/src/java/org/apache/commons/messenger
                        DefaultMessenger.java MessengerSupport.java
  Added:       messenger/src/conf MessengerAshna.xml MessengerJBoss.xml
                        MessengerSpiritWave.xml
  Removed:     messenger/src/conf SpiritWave.xml
  Log:
  Added Saimon Moore's patches to support JBossMQ and AshnaMQ. Also added SpiritWave support.
Now Queue and Topic objects can be loaded from JNDI rather than dynamically created
  
  Revision  Changes    Path
  1.7       +3 -2      jakarta-commons-sandbox/messenger/PROPOSAL.html
  
  Index: PROPOSAL.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/PROPOSAL.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PROPOSAL.html	13 Nov 2001 09:42:27 -0000	1.6
  +++ PROPOSAL.html	15 Feb 2002 11:50:18 -0000	1.7
  @@ -87,8 +87,9 @@
   
   <h3>(4) Initial Committers</h3>
   <ul>
  -   <li>James Strachan</li>
      <li>Colin Crist</li>
  +   <li>James Strachan</li>
  +   <li>Saimon Moore</li>
   </ul>
   </body>
  -</html>
  +</html>
  \ No newline at end of file
  
  
  
  1.8       +3 -2      jakarta-commons-sandbox/messenger/STATUS.html
  
  Index: STATUS.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/STATUS.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- STATUS.html	13 Nov 2001 09:42:27 -0000	1.7
  +++ STATUS.html	15 Feb 2002 11:50:18 -0000	1.8
  @@ -7,7 +7,7 @@
   
   <div align="center">
   <h1>The Jakarta Commons <em>Messenger</em> Package</h1>
  -$Id: STATUS.html,v 1.7 2001/11/13 09:42:27 jstrachan Exp $<br>
  +$Id: STATUS.html,v 1.8 2002/02/15 11:50:18 jstrachan Exp $<br>
   <a href="#Introduction">[Introduction]</a>
   <a href="#Dependencies">[Dependencies]</a>
   <a href="#Release Info">[Release Info]</a>
  @@ -96,6 +96,7 @@
   <ul>
      <li><a href="mailto:ccrist@apache.org">Colin Crist</a></li>
      <li><a href="mailto:jstrachan@apache.org">James Strachan</a></li>
  +   <li>Saimon Moore</li>
   </ul>
   
   <a name="Action Items"></a>
  @@ -122,4 +123,4 @@
   </table>
   
   </body>
  -</html>
  +</html>
  \ No newline at end of file
  
  
  
  1.1                  jakarta-commons-sandbox/messenger/src/conf/MessengerAshna.xml
  
  Index: MessengerAshna.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <manager>
  
    <!-- this example Messenger XML config file should work with J2EE SDK -->
    <!-- when running outside of a J2EE container                         -->
  
    <messenger name="topic" jndiDestinations="true">
      <jndi lookupName="TopicConnectionFactory">
        <property>
          <name>java.naming.factory.initial</name>
          <value>com.ashnasoft.jms.client.jndi.InitialContextFactoryImpl</value>
        </property>
        <property>
          <name>java.naming.provider.url</name>
          <value>jndi:Ashna://localhost:9090/USERNAME=admin/PASSWORD=/SECURE=false</value>
        </property>
      </jndi>
    </messenger>
  
    <messenger name="queue" jndiDestinations="true">
      <jndi lookupName="QueueConnectionFactory">
        <property>
          <name>java.naming.factory.initial</name>
          <value>com.ashnasoft.jms.client.jndi.InitialContextFactoryImpl</value>
        </property>
        <property>
          <name>java.naming.provider.url</name>
          <value>jndi:Ashna://localhost:9090/USERNAME=admin/PASSWORD=/SECURE=false</value>
        </property>
      </jndi>
    </messenger>
  
  </manager>
  
  
  
  1.1                  jakarta-commons-sandbox/messenger/src/conf/MessengerJBoss.xml
  
  Index: MessengerJBoss.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <manager>
  
    <!-- this example Messenger XML config file should work with J2EE SDK -->
    <!-- when running outside of a J2EE container                         -->
  
    <messenger name="topic" jndiDestinations="true">
      <jndi lookupName="TopicConnectionFactory">
        <property>
          <name>java.naming.factory.initial</name>
          <value>org.jnp.interfaces.NamingContextFactory</value>
        </property>
        <property>
          <name>java.naming.provider.url</name>
          <value>jnp://localhost:1099</value>
        </property>
        <property>
          <name>java.naming.factory.url.pkgs</name>
          <value>org.jboss.naming:org.jnp.interfaces</value>
        </property>
      </jndi>
    </messenger>
  
    <messenger name="queue" jndiDestinations="true">
      <jndi lookupName="QueueConnectionFactory">
        <property>
          <name>java.naming.factory.initial</name>
          <value>org.jnp.interfaces.NamingContextFactory</value>
        </property>
        <property>
          <name>java.naming.provider.url</name>
          <value>jnp://localhost:1099</value>
        </property>
        <property>
          <name>java.naming.factory.url.pkgs</name>
          <value>org.jboss.naming:org.jnp.interfaces</value>
        </property>
      </jndi>
    </messenger>
  
  </manager>
  
  
  
  1.1                  jakarta-commons-sandbox/messenger/src/conf/MessengerSpiritWave.xml
  
  Index: MessengerSpiritWave.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <manager>
  
    <messenger name="topic">
      <factory className="com.spirit.messenger.WaveTopicSessionFactory">
        <property>
          <name>driverName</name>
          <value>SpiritJMQ</value>
        </property>          
      </factory>
    </messenger>
  
    <messenger name="queue">
      <factory className="com.spirit.messenger.WaveQueueSessionFactory">
        <property>
          <name>driverName</name>
          <value>SpiritJMQ</value>
        </property>          
      </factory>
    </messenger>
  
  </manager>
  
  
  
  1.7       +93 -26    jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/DefaultMessenger.java
  
  Index: DefaultMessenger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/DefaultMessenger.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultMessenger.java	25 Oct 2001 21:07:12 -0000	1.6
  +++ DefaultMessenger.java	15 Feb 2002 11:50:18 -0000	1.7
  @@ -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: DefaultMessenger.java,v 1.6 2001/10/25 21:07:12 jstrachan Exp $
  + *
  + * $Id: DefaultMessenger.java,v 1.7 2002/02/15 11:50:18 jstrachan Exp $
    */
   package org.apache.commons.messenger;
   
  @@ -18,19 +18,27 @@
   import javax.jms.MessageListener;
   import javax.jms.ServerSessionPool;
   import javax.jms.Session;
  +import javax.jms.Queue;
  +import javax.jms.Topic;
  +import javax.jms.QueueSession;
  +import javax.jms.TopicSession;
  +import javax.naming.NamingException;
  +import javax.naming.Context;
   
  -/** <p><code>DefaultMessenger</code> is the default implementation of

  +/** <p><code>DefaultMessenger</code> is the default implementation of
     * Messenger which uses a {@link ThreadLocal} variable
     * to keep the JMS Session that should be used for a given calling thread.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class DefaultMessenger extends MessengerSupport {
   
       private static final boolean SHARE_CONNECTION = true;
  -    
  -    
  +
  +
  +
  +
       /** the session object for each thread */
       private ThreadLocal sessionPool = new ThreadLocal();
       /** the listener session object for each thread */
  @@ -39,56 +47,59 @@
       private SessionFactory sessionFactory;
       /** A pool of Connections, one per thread */
       private ThreadLocal connectionPool = new ThreadLocal();
  -    
  +
       public DefaultMessenger() {
       }
  -    
  +
   
       /** Returns the SessionFactory used to create new JMS sessions */
       public SessionFactory getSessionFactory() throws JMSException {
           if ( sessionFactory == null ) {
               sessionFactory = createSessionFactory();
           }
  +
           return sessionFactory;
       }
  -    
  +
       /** Sets the SessionFactory used to create new JMS sessions */
       public void setSessionFactory(SessionFactory sessionFactory) {
           this.sessionFactory = sessionFactory;
       }
  -       
  -    
  +
  +
       public Connection getConnection() throws JMSException {
           if ( SHARE_CONNECTION ) {
               return getSessionFactory().getConnection();
           }
           else {
  +
               Connection answer = (Connection) connectionPool.get();
               if ( answer == null ) {
  +
                   answer = getSessionFactory().createConnection();
  -                
  +
                   System.out.println( "Created connection: " + answer + " for thread: " +
Thread.currentThread() );
  -                
  +
                   connectionPool.set( answer );
               }
               return answer;
           }
       }
  -    
  +
       public ServerSessionPool createServerSessionPool(MessageListener messageListener, int
maxThreads) throws JMSException {
           return getSessionFactory().createServerSessionPool(messageListener, maxThreads);
       }
  -    
  -    public void close() throws JMSException {        
  +
  +    public void close() throws JMSException {
           getSessionFactory().close();
  -        
  +
           // clear all the pools...
           sessionPool = new ThreadLocal();
           listenerSessionPool = new ThreadLocal();
       }
  -    
  +
       // Implementation methods
  -    //-------------------------------------------------------------------------       

  +    //-------------------------------------------------------------------------
       protected Session borrowSession() throws JMSException {
           Session answer = (Session) sessionPool.get();
           if ( answer == null ) {
  @@ -97,14 +108,14 @@
           }
           return answer;
       }
  -    
  +
       protected void returnSession(Session session) {
       }
  -    
  +
       protected void deleteSession(Session session) throws JMSException {
           sessionPool.set( null);
       }
  -    
  +
       protected Session borrowListenerSession() throws JMSException {
           Session answer = (Session) listenerSessionPool.get();
           if ( answer == null ) {
  @@ -113,21 +124,77 @@
           }
           return answer;
       }
  -    
  +
       protected void returnListenerSession(Session session) throws JMSException {
       }
  -    
  +
       /** Factory method to create a new JMS Session */
       protected Session createSession() throws JMSException {
           return getSessionFactory().createSession( getConnection() );
       }
  -    
  -    /** Factory method to create a SessionFactory. 
  +
  +    /** Factory method to create a SessionFactory.
         * Derived classes could override this method to create the SessionFactory
         * from a well known place
         */
       protected SessionFactory createSessionFactory() throws JMSException {
           throw new JMSException( "No SessionFactory configured for this Messenger. Cannot
create a new JMS Session" );
  +    }
  +
  +    public Queue getQueue(QueueSession session, String subject) throws JMSException {
  +        // XXXX: might want to cache
  +        Context ctx = null;
  +        JNDISessionFactory factory = null;;
  +        Queue queue = null;
  +
  +
  +        if ( isJndiDestinations() ) {
  +
  +            try {
  +                factory = (JNDISessionFactory) getSessionFactory();
  +                ctx = factory.getContext();
  +                queue = (Queue) ctx.lookup(subject);
  +            }
  +
  +            catch (Exception e) {
  +                System.out.println("Unable to lookup subject:" + subject);
  +            }
  +        }
  +
  +        else {
  +            // XXXX: might want to cache
  +            queue = session.createQueue( subject );
  +        }
  +
  +        return queue;
  +
  +    }
  +
  +    public Topic getTopic(TopicSession session, String subject) throws JMSException {
  +        // XXXX: might want to cache
  +
  +        Context ctx = null;
  +        JNDISessionFactory factory = null;;
  +        Topic topic = null;
  +
  +        if ( isJndiDestinations() ) {
  +
  +            try {
  +                factory = (JNDISessionFactory) getSessionFactory();
  +                ctx = factory.getContext();
  +                topic = (Topic) ctx.lookup(subject);
  +
  +            }
  +
  +            catch (Exception e) {
  +                System.out.println("Unable to lookup subject:" + subject);
  +            }
  +        }
  +
  +        else {
  +            topic = session.createTopic( subject );
  +        }
  +        return topic;
       }
   }
   
  
  
  
  1.17      +16 -2     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSupport.java
  
  Index: MessengerSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSupport.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- MessengerSupport.java	1 Feb 2002 14:32:33 -0000	1.16
  +++ MessengerSupport.java	15 Feb 2002 11:50:18 -0000	1.17
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    *
  - * $Id: MessengerSupport.java,v 1.16 2002/02/01 14:32:33 jstrachan Exp $
  + * $Id: MessengerSupport.java,v 1.17 2002/02/15 11:50:18 jstrachan Exp $
    */
   package org.apache.commons.messenger;
   
  @@ -45,7 +45,7 @@
     * connection and session creation and the pooling strategy.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.16 $
  +  * @version $Revision: 1.17 $
     */
   public abstract class MessengerSupport implements Messenger {
   
  @@ -55,6 +55,10 @@
       /** The name of the Messenger */
       private String name;
   
  +    /** Wether Queue's and Topic's are looked up using JNDI (true)
  +    * or wether they should be created on the fly */
  +    private boolean jndiDestinations;
  +
       /** are topic subscribers durable? */
       private boolean durable;
   
  @@ -515,6 +519,16 @@
       /** Sets the name that this Messenger is called in a MessengerManager */
       public void setName(String name) {
           this.name = name;
  +    }
  +
  +    /** Setter for DestinationsFromJNDI */
  +    public void setJndiDestinations(boolean jndiDestinations){
  +        this.jndiDestinations = jndiDestinations;
  +    }
  +
  +    /** Getter for JndiDestinations */
  +    public boolean isJndiDestinations() {
  +        return jndiDestinations;
       }
   
       /** Gets whether topic subscribers are durable or not */
  
  
  

--
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