jstrachan    01/08/24 08:37:13

  Modified:    messenger build.properties.sample build.xml
  Added:       messenger/src/java/org/apache/commons/messenger
                        PoolingMessenger.java
                        ServerSessionPoolMessenger.java
  Log:
  Added default implementations based on optional ServerSessionPool and Jakarta 
Commons Pool implementations
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-commons-sandbox/messenger/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.properties.sample,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.properties.sample   2001/08/24 14:20:28     1.1
  +++ build.properties.sample   2001/08/24 15:37:13     1.2
  @@ -4,6 +4,6 @@
   # jms.jar
   jms.jar=/java/jms/jms.jar
   
  -# jakarta-commons-pool.jar
  -pool.jar=../../jakarta-commons/collections/dist/commons-pool.jar
  +# jakarta commons-pool.jar
  +pool.jar=../../jakarta-commons/pool/dist/commons-pool.jar
   
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/messenger/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml 2001/08/24 14:20:28     1.1
  +++ build.xml 2001/08/24 15:37:13     1.2
  @@ -1,4 +1,4 @@
  -<!-- $Id: build.xml,v 1.1 2001/08/24 14:20:28 jstrachan Exp $ -->
  +<!-- $Id: build.xml,v 1.2 2001/08/24 15:37:13 jstrachan Exp $ -->
   <project name="messenger" default="test" basedir=".">
   
      <!-- patternset describing files to be copied from the doc directory -->
  @@ -42,7 +42,7 @@
         <property name="cp" value=""/>
   
         <!-- now combine the classpaths -->
  -      <property name="classpath" value="${cp}:${jms.jar}:${junit.jar}"/>
  +      <property name="classpath" 
value="${cp}:${jms.jar}:${pool.jar}:${junit.jar}"/>
   
         <property name="name" value="messenger"/>
         <property name="Name" value="Messenger"/>
  
  
  
  1.1                  
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/PoolingMessenger.java
  
  Index: PoolingMessenger.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * 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: PoolingMessenger.java,v 1.1 2001/08/24 15:37:13 jstrachan Exp $
   */
  package org.apache.commons.messenger;
  
  import java.io.Serializable;
  
  import javax.jms.Connection;
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.Session;
  
  import org.apache.commons.pool.ObjectPool;
  import org.apache.commons.pool.PoolableObjectFactory;
  import org.apache.commons.pool.impl.GenericObjectPool;
  
  /** <p><code>PoolingMessenger</code> is a Messenger which uses the 
    * Jakarta Commons Pool to pool JMS Sessions.</p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class PoolingMessenger extends MessengerSupport {
  
      /** the session pool */
      private ObjectPool sessionPool;
      
      
      public PoolingMessenger(PoolableObjectFactory sessionFactory) {
          sessionPool = createSessionPool( sessionFactory );
      }
      
      public PoolingMessenger(ObjectPool sessionPool) {
          this.sessionPool = sessionPool;
      }
      
      public ObjectPool getSessionPool() {
          return sessionPool;
      }
      
      public void setSessionPool(ObjectPool sessionPool) {
          this.sessionPool = sessionPool;
      }
      
      
      // Implementation methods
      //-------------------------------------------------------------------------    
      
      protected Session borrowSession() {
          return (Session) sessionPool.borrowObject();
      }
      
      protected void returnSession(Session session) {
          sessionPool.returnObject(session);
      }
      
      protected ObjectPool createSessionPool(PoolableObjectFactory sessionFactory) {
          return new GenericObjectPool( sessionFactory );
      }
      
      protected PoolableObjectFactory createSessionFactory(Connection connection) {
          return null;
      }
  }
  
  
  
  
  1.1                  
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ServerSessionPoolMessenger.java
  
  Index: ServerSessionPoolMessenger.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * 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: ServerSessionPoolMessenger.java,v 1.1 2001/08/24 15:37:13 jstrachan Exp $
   */
  package org.apache.commons.messenger;
  
  import java.io.Serializable;
  
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.Session;
  import javax.jms.ServerSession;
  import javax.jms.ServerSessionPool;
  
  
  /** <p><code>ServerSessionPoolMessenger</code> is a Messenger which uses the 
    * optional ServerSessionPool to implement session based pooling.</p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ServerSessionPoolMessenger extends MessengerSupport {
  
      /** the session pool */
      private ServerSessionPool sessionPool;
      
      
      public ServerSessionPoolMessenger() {
      }
      
      public ServerSessionPoolMessenger(ServerSessionPool sessionPool) {
          this.sessionPool = sessionPool;
      }
      
      public ServerSessionPool getServerSessionPool() {
          return sessionPool;
      }
      
      public void setServerSessionPool(ServerSessionPool sessionPool) {
          this.sessionPool = sessionPool;
      }
      
      
      // Implementation methods
      //-------------------------------------------------------------------------    
      
      protected Session borrowSession() throws JMSException {
          ServerSession serverSession = sessionPool.getServerSession();
          return serverSession.getSession();
      }
      
      protected void returnSession(Session session) throws JMSException {
      }
  }
  
  
  
  

Reply via email to