You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/06/27 17:30:08 UTC

cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger MessengerSupport.java MessengerSession.java

jstrachan    2002/06/27 08:30:08

  Modified:    messenger/src/java/org/apache/commons/messenger
                        MessengerSupport.java MessengerSession.java
  Log:
  Optimised the implementation of the call() methods to pool the MessageConsumer per thread for temporary destinations, which greatly boosts performance on most JMS providers.
  Typically its not safe to generically pool MessageConsumers in JMS, however its fine for temporary destinations, since there are no other processes consuming them, and we only pool 1 MessageConsumer per thread (and per temporary destination) so this is fine.
  
  Revision  Changes    Path
  1.25      +23 -8     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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MessengerSupport.java	26 Jun 2002 11:30:59 -0000	1.24
  +++ MessengerSupport.java	27 Jun 2002 15:30:08 -0000	1.25
  @@ -146,13 +146,13 @@
   
       public Message call( Destination destination, Message message ) throws JMSException {
           Session session = borrowSession();
  -        MessageConsumer consumer = null;
           try {
               Destination replyTo = getReplyToDestination();
  +            
               message.setJMSReplyTo(replyTo);
   
               MessageProducer producer = getMessageProducer( session, destination );
  -            consumer = borrowMessageConsumer( session, replyTo );
  +            MessageConsumer consumer = getReplyToConsumer();
   
               if ( isTopic( session ) ) {
                   ((TopicPublisher) producer).publish( message );
  @@ -163,7 +163,6 @@
               return consumer.receive();
           }
           finally {
  -            returnMessageConsumer(consumer);
               returnSession( session );
           }
       }
  @@ -175,12 +174,12 @@
           throws JMSException {
           Session session = borrowSession();
           MessageProducer producer = null;
  -        MessageConsumer consumer = null;
           try {
               Destination replyTo = getReplyToDestination();
               message.setJMSReplyTo(replyTo);
               producer = getMessageProducer(session, destination);
  -            consumer = borrowMessageConsumer(session, replyTo);
  +            
  +            MessageConsumer consumer = getReplyToConsumer();
               if (isTopic(session)) {
                   ((TopicPublisher) producer).publish(message);
               }
  @@ -190,7 +189,6 @@
               return consumer.receive(timeoutMillis);
           }
           finally {
  -            returnMessageConsumer(consumer);
               producer.close();
               returnSession(session);
           }
  @@ -857,6 +855,23 @@
               QueueSession queueSession = (QueueSession) session;
               return queueSession.createSender((Queue) destination);
           }
  +    }
  +    
  +    /**
  +     * @return the MessageConsumer for this threads temporary destination
  +     * which is cached for the duration of this process.
  +     */
  +    protected MessageConsumer getReplyToConsumer() throws JMSException {
  +        MessengerSession messengerSession = getMessengerSession();
  +        MessageConsumer consumer = messengerSession.getReplyToConsumer();
  +        if ( consumer == null ) {
  +            consumer = createMessageConsumer(
  +                messengerSession.getSession(),
  +                messengerSession.getReplyToDestination()
  +            );
  +            messengerSession.setReplyToConsumer(consumer);
  +        }
  +        return consumer;
       }
       
       /** @return a MessageConsumer for the given session and destination */
  
  
  
  1.2       +16 -1     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSession.java
  
  Index: MessengerSession.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSession.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MessengerSession.java	14 Jun 2002 17:50:13 -0000	1.1
  +++ MessengerSession.java	27 Jun 2002 15:30:08 -0000	1.2
  @@ -42,6 +42,9 @@
       
       /** the JMS Listener (async subscription) Session for this thread */
       private Session listenerSession;
  +
  +    /** the MessageConsumer for this threads reply to destination */    
  +    private MessageConsumer replyToConsumer;
       
       /** The factory used to create each thread's JMS Session */
       private SessionFactory sessionFactory;
  @@ -83,7 +86,19 @@
           }
           return listenerSession;
       }
  -    
  +
  +
  +    /** 
  +     * @return the MessageConsumer for the ReplyTo Destination for this thread
  +     */
  +    public MessageConsumer getReplyToConsumer() {
  +        return replyToConsumer;
  +    }
  +        
  +    public void setReplyToConsumer(MessageConsumer replyToConsumer) {
  +        this.replyToConsumer = replyToConsumer;
  +    }
  +        
       /** 
        * @return the reply to destination (a temporary queue) 
        * used to reply to this thread and session
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>