From activemq-commits-return-1966-apmail-geronimo-activemq-commits-archive=geronimo.apache.org@geronimo.apache.org Fri Jun 02 08:25:11 2006 Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 26502 invoked from network); 2 Jun 2006 08:25:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Jun 2006 08:25:11 -0000 Received: (qmail 47433 invoked by uid 500); 2 Jun 2006 08:25:11 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 47393 invoked by uid 500); 2 Jun 2006 08:25:10 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 47384 invoked by uid 99); 2 Jun 2006 08:25:10 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jun 2006 01:25:10 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jun 2006 01:25:10 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id EB8001A983A; Fri, 2 Jun 2006 01:24:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r411085 - /incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java Date: Fri, 02 Jun 2006 08:24:49 -0000 To: activemq-commits@geronimo.apache.org From: foconer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060602082449.EB8001A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: foconer Date: Fri Jun 2 01:24:47 2006 New Revision: 411085 URL: http://svn.apache.org/viewvc?rev=411085&view=rev Log: Added support for sync and async. Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java?rev=411085&r1=411084&r2=411085&view=diff ============================================================================== --- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java (original) +++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java Fri Jun 2 01:24:47 2006 @@ -29,6 +29,7 @@ private Destination destination = null; private boolean isDurable = false; + private boolean isAsync = true; public JmsConsumerClient(ConnectionFactory factory) { this.factory = factory; @@ -66,48 +67,53 @@ setDestination(getDestinationName()); } - System.out.println("Connecting to URL: " + brokerUrl); - System.out.println("Consuming: " + destination); - System.out.println("Using " + (isDurable ? "durable" : "non-durable") + " subscription"); - - if (isDurable) { createDurableSubscriber((Topic) getDestination(), getClass().getName()); } else { createMessageConsumer(getDestination()); } - getMessageConsumer().setMessageListener(this); - getConnection().start(); - - try { - Thread.sleep(duration); - } catch (InterruptedException e) { - throw new JMSException("Error while consumer is sleeping " + e.getMessage()); + if (isAsync) { + getMessageConsumer().setMessageListener(this); + getConnection().start(); + + try { + Thread.sleep(duration); + } catch (InterruptedException e) { + throw new JMSException("Error while consumer is sleeping " + e.getMessage()); + } + } else { + getConnection().start(); + consumeMessages(getMessageConsumer(), duration); } - getMessageConsumer().close(); - getConnection().close(); - - System.out.println("Throughput : " + this.getThroughput()); - + close(); //close consumer, session, and connection. listener.onConfigEnd(this); } + //Increments throughput public void onMessage(Message message) { - try { - TextMessage textMessage = (TextMessage) message; + System.out.println(message.toString()); + this.incThroughput(); + } - // lets force the content to be deserialized - String text = textMessage.getText(); - System.out.println("message: " + text + ":" + this.getThroughput()); - this.incThroughput(); - } catch (JMSException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + protected void consumeMessages(MessageConsumer consumer, long duration) throws JMSException { + + long currentTime = System.currentTimeMillis(); + long endTime = currentTime + duration; + + while (System.currentTimeMillis() <= endTime) { + Message message = consumer.receive(); + onMessage(message); } } + protected void close() throws JMSException { + getMessageConsumer().close(); + getSession().close(); + getConnection().close(); + } + public static void main(String[] args) throws Exception { JmsConsumerClient cons = new JmsConsumerClient("org.apache.activemq.ActiveMQConnectionFactory", "tcp://localhost:61616", "topic://TEST.FOO"); cons.setPerfEventListener(new PerfEventAdapter()); @@ -115,6 +121,22 @@ } // Helper Methods + + public boolean isDurable() { + return isDurable; + } + + public void setDurable(boolean durable) { + isDurable = durable; + } + + public boolean isAsync() { + return isAsync; + } + + public void setAsync(boolean async) { + isAsync = async; + } public String getDestinationName() { return this.destinationName;