commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Louis Burroughs" <lburr...@aholdusa.com>
Subject Re: [Pool] JMS Pools
Date Thu, 24 Apr 2003 17:03:05 GMT

We don't pool QueueSession objects, we tried that earlier and started
having trouble with any kind of a load.  We do pool QueueConnections using
the BasePoolableObjectFactory.  We are currently experimenting with setting
an ExceptionListener in the QueueConnection to detect connection failures
(which we use to send messages to the Tivoli Tec Console).  We are running
stand-alone on J2SE 1.3.  MQ Series is our JMS implementation.  I am
working on setting up containers for our listeners to run in.  Your other
option is to use Common's Messenger in a J2EE environment .



(Outer Class)
public class InitClass {
     private static MQQueueConnectionFactory qcf = null;
     protected static ObjectPool pool;
     protected static ObjectPool mqPool;
.
.
.
.

.
.(Inner Class)
public class MQConnectionPoolFactory extends BasePoolableObjectFactory {
          public MQConnectionPoolFactory() {
               super();
          }

          public void destroyObject(Object obj) throws Exception {
               try {
                    QueueConnection qConnection = (QueueConnection) obj;
                    qConnection.stop();
                    qConnection = null;
               } catch (JMSException e) {
                    throw new TivoliException(
                         "InitClass$MQConnectionPoolFactory",
                         40000,
                         6500,
                         ("destroyObject(Object) : Error occured stop the
queue connection"
                              + e));
               }
               AholdLogging.log(
                    "InitClass$MQConnectionPoolFactory",
                    20000,
                    "destroyObject(Object) : Object Destroyed");
          }

          public Object makeObject() throws Exception {
               QueueConnection qConnection = null;
               try {
                    qConnection = InitClass.qcf.createQueueConnection();
                    qConnection.setExceptionListener(new ExceptionListener
() {
                         public void onException(JMSException ex) {
                              new TivoliException(
                                   "InitClass",
                                   10000,
                                   6100,
                                   ex.getMessage(),
                                   ex.getLinkedException());
                         }
                    });

               } catch (JMSException e) {
                    throw new TivoliException(
                         "InitClass$MQConnectionPoolFactory",
                         40000,
                         6500,
                         ("makeObject(Object) : Error occured creating
queue connection"
                              + e));
               }
               return qConnection;
          }

          public void activateObject(Object obj) {
               try {
                    QueueConnection qConnection = (QueueConnection) obj;
                    qConnection.start();
               } catch (JMSException e) {
                    new TivoliException(
                         "InitClass$MQConnectionPoolFactory",
                         40000,
                         6500,
                         ("activateObject(Object) : Error occured start the
queue connection"
                              + e));
               }
          }

          public boolean validateObject(Object obj) {
               QueueConnection qConnection = (QueueConnection) obj;
               try {
                    QueueSession qSession =
                         qConnection.createQueueSession(false, 1);
                    javax.jms.Queue queue =
                         (MQQueue) qSession.createQueue(
                              DbQueryFormatterConstants.MONITORED_Q);
                    qSession.close();
                    qSession = null;
                    queue = null;
               } catch (Exception e) {
                    new TivoliException(
                         "InitClass$MQConnectionPoolFactory",
                         40000,
                         6500,
                         ("validateObject(Object) : Error bad queue
connection"
                              + e));
                    return false;
               }
               AholdLogging.log(
                    "InitClass$MQConnectionPoolFactory",
                    20000,
                    "MQ Connection Valid ");
               return true;
          }
     }
.
.
.
.
.
.

(Initialization in the main method)
try {
                    org.apache.commons.pool.PoolableObjectFactory mqFactory
=
                         this.new MQConnectionPoolFactory();
                    GenericObjectPool GPool2 =
                         new GenericObjectPool(
                              mqFactory,
                              (DbQueryFormatterConstants.MAX_MQ_CONN));
                    GPool2.setTestOnBorrow(true);
                    mqPool = GPool2;
               } catch (Exception e) {
                    throw new TivoliException(
                         "InitClass",
                         50000,
                         6900,
                         "main() : Error creating mq pool :" + e);

               }
.

Louis Burroughs
Enterprise Architecture


                                                                                         
                                                    
                    "Tauzell,                                                            
                                                    
                    Dave"                To:     <commons-user@jakarta.apache.org> 
                                                          
                    <Dave.Tauzell@       cc:                                          
                                                       
                    RxHub.net>           Subject:     [Pool] JMS Pools                
                                                       
                                                                                         
                                                    
                    04/24/2003                                                           
                                                    
                    12:37 PM                                                             
                                                    
                    Please respond                                                       
                                                    
                    to "Jakarta                                                          
                                                    
                    Commons Users                                                        
                                                    
                    List"                                                                
                                                    
                                                                                         
                                                    
                                                                                         
                                                    
                                                                                         
                                                    
                                                                                         
                                                    
                                                                                         
                                                    




Has anybody used the Pool classes to create a pool of JMS QueueSession
objects?  I have a large number of threads that need to send JMS
messages. Right now each one gets its own connection which is somewhat
resource intensive (we are using MQSeries).

One issue I have is how to detect when failures happen and how to
re-connect.

If anybody has done something similar I'd be interested in any
information you have.

Thanks,
    Dave




Mime
View raw message