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/conf subscribe.xml
Date Tue, 09 Jul 2002 11:53:35 GMT
jstrachan    2002/07/09 04:53:35

  Modified:    messenger/src/java/org/apache/commons/messagelet Main.java
               messenger/src/java/org/apache/commons/messenger/tool
                        StopWatchMessageListener.java
               messenger/src/java/org/apache/commons/messagelet/impl
                        SubscriptionDigester.java
               messenger/src/conf subscribe.xml
  Log:
  Patched the StopWatchMessageListener so that it takes an optional MessageListener. So now
StopWatchMessageListener is a sample consumer that just logs the throughput rate that it consumes
messages.
  Also fixed the incorrect package name.
  
  Added a <stopWatch/> element to the subscribe.xml format so that its easy to consume
XML messages.
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/Main.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Main.java	8 Jul 2002 16:19:05 -0000	1.2
  +++ Main.java	9 Jul 2002 11:53:34 -0000	1.3
  @@ -27,9 +27,9 @@
   import org.apache.commons.messagelet.impl.Subscription;
   import org.apache.commons.messagelet.impl.SubscriptionDigester;
   import org.apache.commons.messagelet.impl.SubscriptionList;
  -import org.apache.commons.messagelet.tool.StopWatchMessageListener;
   import org.apache.commons.messenger.Messenger;
   import org.apache.commons.messenger.MessengerManager;
  +import org.apache.commons.messenger.tool.StopWatchMessageListener;
   
   /** 
    * <p><code>Main</code> is a simple command line program that will
  
  
  
  1.2       +33 -8     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/tool/StopWatchMessageListener.java
  
  Index: StopWatchMessageListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/tool/StopWatchMessageListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StopWatchMessageListener.java	8 Jul 2002 16:19:06 -0000	1.1
  +++ StopWatchMessageListener.java	9 Jul 2002 11:53:34 -0000	1.2
  @@ -8,8 +8,10 @@
    * $Id$
    */
   
  -package org.apache.commons.messagelet.tool;
  +package org.apache.commons.messenger.tool;
   
  +import javax.jms.Destination;
  +import javax.jms.JMSException;
   import javax.jms.Message;
   import javax.jms.MessageListener;
   
  @@ -28,7 +30,7 @@
       private Log log = LogFactory.getLog( StopWatchMessageListener.class );
       
       /** the underlying MessageListener */
  -    private MessageListener listener;
  +    private MessageListener messageListener;
   
       /** the number of messages processed */
       private int count;
  @@ -39,8 +41,11 @@
       /** the time that the batch started processing */
       private long startTime;
               
  -    public StopWatchMessageListener(MessageListener listener) {
  -        this.listener = listener;
  +    public StopWatchMessageListener() {
  +    }
  +    
  +    public StopWatchMessageListener(MessageListener messageListener) {
  +        this.messageListener = messageListener;
       }
       
       // MessageListener interface
  @@ -49,16 +54,23 @@
           if ( count == 0 ) {
               startTime = System.currentTimeMillis();
           }
  -        listener.onMessage(message);
  +        if ( messageListener != null ) {
  +            messageListener.onMessage(message);
  +        }
           
           if ( ++count == groupSize ) {
               long elapsed = System.currentTimeMillis() - startTime;            
               double timePerMessage = elapsed / count;
               double messagesPerSecond = groupSize / timePerMessage;
               
  -            
  -            log.info( "Time to process " + count + " messages: " + elapsed + " millis"
);
  -            log.info( "Average time per message: " + timePerMessage + " millis" );
  +            Destination destination = null;
  +            try {
  +                destination = message.getJMSDestination();
  +            }
  +            catch (JMSException e) {
  +                // ignore
  +            }            
  +            log.info( "Time to process " + count + " messages: " + elapsed + " millis on:
" + destination );
               log.info( "Average number of messages per second: " + messagesPerSecond );
               count = 0;
           }
  @@ -97,5 +109,18 @@
           this.log = log;
       }
           
  +    /**
  +     * @return the MessageListener which this listener delegates to
  +     */
  +    public MessageListener getMessageListener() {
  +        return messageListener;    
  +    }
  +    
  +    /**
  +     * Sets the MessageListener which this listener delegates to, which can be null.
  +     */
  +    public void setMessageListener(MessageListener messageListener) {
  +        this.messageListener = messageListener;
  +    }
       
   }
  
  
  
  1.6       +11 -3     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/SubscriptionDigester.java
  
  Index: SubscriptionDigester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/impl/SubscriptionDigester.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SubscriptionDigester.java	8 Jul 2002 14:37:36 -0000	1.5
  +++ SubscriptionDigester.java	9 Jul 2002 11:53:35 -0000	1.6
  @@ -25,7 +25,7 @@
       private String listenerClass = "org.apache.commons.messagelet.impl.MessageServletDispatcher";
       private String bridgeClass = "org.apache.commons.messagelet.BridgeMDO";
       private String distributeBridgeClass = "org.apache.commons.messagelet.DistributeBridgeMDO";
  -
  +    private String stopWatchClass = "org.apache.commons.messenger.tool.StopWatchMessageListener";
       
       public SubscriptionDigester() {
       }
  @@ -64,6 +64,14 @@
           addSetNext( path, "setMessageListener",
              "javax.jms.MessageListener"
           );
  +        
  +        path = "subscriptions/subscription/stopWatch";
  +        addObjectCreate( path, stopWatchClass, "className" );
  +        addSetProperties( path );
  +        addSetNext( path, "setMessageListener",
  +           "javax.jms.MessageListener"
  +        );
  +
           
           path = "subscriptions/subscription/bridge";
           addObjectCreate( path, bridgeClass, "className" );
  
  
  
  1.8       +14 -0     jakarta-commons-sandbox/messenger/src/conf/subscribe.xml
  
  Index: subscribe.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/conf/subscribe.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- subscribe.xml	8 Jul 2002 15:15:24 -0000	1.7
  +++ subscribe.xml	9 Jul 2002 11:53:35 -0000	1.8
  @@ -17,6 +17,20 @@
     </subscription>
   
   
  +  <!-- consume the output queues and report throughput -->
  +  <subscription connection="queue" subject="output.A">
  +    <stopWatch groupSize="100"/>
  +  </subscription>
  +  <subscription connection="queue" subject="output.B">
  +    <stopWatch groupSize="100"/>
  +  </subscription>
  +  <subscription connection="queue" subject="output.C">
  +    <stopWatch groupSize="100"/>
  +  </subscription>
  +  <subscription connection="queue" subject="output.D">
  +    <stopWatch groupSize="100"/>
  +  </subscription>
  +
   
   
     <!-- An example of how subscriptions can look... -->
  
  
  

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