activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r382964 - /incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java
Date Fri, 03 Mar 2006 23:21:40 GMT
Author: chirino
Date: Fri Mar  3 15:21:37 2006
New Revision: 382964

URL: http://svn.apache.org/viewcvs?rev=382964&view=rev
Log:
added another option that allows you to basically drain a destination for while messages are
being produced.

Modified:
    incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java

Modified: incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java?rev=382964&r1=382963&r2=382964&view=diff
==============================================================================
--- incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java (original)
+++ incubator/activemq/trunk/assembly/src/release/example/src/ConsumerTool.java Fri Mar  3
15:21:37 2006
@@ -42,7 +42,7 @@
     private boolean running;
     private Session session;
     private long sleepTime=0;
-
+    private long receiveTimeOut=0;
 
     public static void main(String[] args) {
         ConsumerTool tool = new ConsumerTool();
@@ -70,6 +70,10 @@
         if (args.length > 7) {
             tool.sleepTime = Long.parseLong(args[7]);
         }
+        if (args.length > 8) {
+            tool.receiveTimeOut = Long.parseLong(args[8]);
+        }
+        
         
         tool.run();
     }
@@ -92,12 +96,14 @@
             else {
                 consumer = session.createConsumer(destination);
             }
-            if (maxiumMessages <= 0) {
-                consumer.setMessageListener(this);
-            }
-
-            if (maxiumMessages > 0) {
+            if ( maxiumMessages > 0 ) {
                 consumeMessagesAndClose(connection, session, consumer);
+            } else  {
+                if(receiveTimeOut==0) {
+                    consumer.setMessageListener(this);
+                } else {
+                    consumeMessagesAndClose(connection, session, consumer, receiveTimeOut);
+                }
             }
         }
         catch (Exception e) {
@@ -166,6 +172,24 @@
                 onMessage(message);
             }
         }
+        System.out.println("Closing connection");
+        consumer.close();
+        session.close();
+        connection.close();
+        if (pauseBeforeShutdown) {
+            System.out.println("Press return to shut down");
+            System.in.read();
+        }
+    }
+    
+    protected void consumeMessagesAndClose(Connection connection, Session session, MessageConsumer
consumer, long timeout) throws JMSException, IOException {
+        System.out.println("We will consume messages while they continue to be delivered
within: " + timeout + " ms, and then we will shutdown");
+
+        Message message;
+        while ( (message = consumer.receive(timeout)) != null ) {
+            onMessage(message);
+        }
+        
         System.out.println("Closing connection");
         consumer.close();
         session.close();



Mime
View raw message