You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/09/08 00:41:12 UTC

svn commit: r573740 - in /incubator/qpid/branches/M2.1/java/perftests: bin/ src/main/java/org/apache/qpid/oldtopic/

Author: rgreig
Date: Fri Sep  7 15:41:10 2007
New Revision: 573740

URL: http://svn.apache.org/viewvc?rev=573740&view=rev
Log:
QPID-583 Added old topic test which had been removed in the past.


Added:
    incubator/qpid/branches/M2.1/java/perftests/bin/
    incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh   (with props)
    incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh   (with props)
    incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh   (with props)
    incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/
    incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java   (with props)
    incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java   (with props)
    incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java   (with props)
    incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java   (with props)

Added: incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh (added)
+++ incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh Fri Sep  7 15:41:10 2007
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+# args: 
+# <number of processes to start>
+# <name of run>
+# <command ro run>
+
+for i in `seq 1 $1`; do
+    $3 >$2.$i.out 2>>$2.err &
+    echo $! > $2.$i.pid
+done;

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/run_many.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh (added)
+++ incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh Fri Sep  7 15:41:10 2007
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+# XXX -Xmx512m -Xms512m -XX:NewSize=150m
+. qpid-run -Damqj.logging.level="INFO" org.apache.qpid.topic.Listener $*

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/topicListener.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh (added)
+++ incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh Fri Sep  7 15:41:10 2007
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# XXX -Xmx512m -Xms512m -XX:NewSize=150m
+. qpid-run -Damqj.logging.level="INFO" org.apache.qpid.topic.Publisher $*

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/branches/M2.1/java/perftests/bin/topicPublisher.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java (added)
+++ incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java Fri Sep  7 15:41:10 2007
@@ -0,0 +1,243 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.oldtopic;
+
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.config.ConnectorConfig;
+import org.apache.qpid.config.ConnectionFactoryInitialiser;
+import org.apache.qpid.config.Connector;
+import org.apache.qpid.config.AbstractConfig;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+
+class Config extends AbstractConfig implements ConnectorConfig
+{
+
+    private String host = "localhost";
+    private int port = 5672;
+    private String factory = null;
+
+    private int payload = 256;
+    private int messages = 1000;
+    private int clients = 1;
+    private int batch = 1;
+    private long delay = 1;
+    private int warmup;
+    private int ackMode= AMQSession.NO_ACKNOWLEDGE;
+    private String clientId;
+    private String subscriptionId;
+    private boolean persistent;
+
+    public Config()
+    {
+    }
+
+    int getAckMode()
+    {
+        return ackMode;
+    }
+
+    void setPayload(int payload)
+    {
+        this.payload = payload;
+    }
+
+    int getPayload()
+    {
+        return payload;
+    }
+
+    void setClients(int clients)
+    {
+        this.clients = clients;
+    }
+
+    int getClients()
+    {
+        return clients;
+    }
+
+    void setMessages(int messages)
+    {
+        this.messages = messages;
+    }
+
+    int getMessages()
+    {
+        return messages;
+    }
+
+    public String getHost()
+    {
+        return host;
+    }
+
+    public void setHost(String host)
+    {
+        this.host = host;
+    }
+
+    public int getPort()
+    {
+        return port;
+    }
+
+    public String getFactory()
+    {
+        return factory;
+    }
+
+    public void setPort(int port)
+    {
+        this.port = port;
+    }
+
+    int getBatch()
+    {
+        return batch;
+    }
+
+    void setBatch(int batch)
+    {
+        this.batch = batch;
+    }
+
+    int getWarmup()
+    {
+        return warmup;
+    }
+
+    void setWarmup(int warmup)
+    {
+        this.warmup = warmup;
+    }
+
+    public long getDelay()
+    {
+        return delay;
+    }
+
+    public void setDelay(long delay)
+    {
+        this.delay = delay;
+    }
+
+    String getClientId()
+    {
+        return clientId;
+    }
+
+    String getSubscriptionId()
+    {
+        return subscriptionId;
+    }
+
+    boolean usePersistentMessages()
+    {
+        return persistent;
+    }
+
+    public void setOption(String key, String value)
+    {
+        if("-host".equalsIgnoreCase(key))
+        {
+            setHost(value);
+        }
+        else if("-port".equalsIgnoreCase(key))
+        {
+            try
+            {
+                setPort(Integer.parseInt(value));
+            }
+            catch(NumberFormatException e)
+            {
+                throw new RuntimeException("Bad port number: " + value);
+            }
+        }
+        else if("-payload".equalsIgnoreCase(key))
+        {
+            setPayload(parseInt("Bad payload size", value));
+        }
+        else if("-messages".equalsIgnoreCase(key))
+        {
+            setMessages(parseInt("Bad message count", value));
+        }
+        else if("-clients".equalsIgnoreCase(key))
+        {
+            setClients(parseInt("Bad client count", value));
+        }
+        else if("-batch".equalsIgnoreCase(key))
+        {
+            setBatch(parseInt("Bad batch count", value));
+        }
+        else if("-delay".equalsIgnoreCase(key))
+        {
+            setDelay(parseLong("Bad batch delay", value));
+        }
+        else if("-warmup".equalsIgnoreCase(key))
+        {
+            setWarmup(parseInt("Bad warmup count", value));
+        }
+        else if("-ack".equalsIgnoreCase(key))
+        {
+            ackMode = parseInt("Bad ack mode", value);
+        }
+        else if("-factory".equalsIgnoreCase(key))
+        {
+            factory = value;
+        }
+        else if("-clientId".equalsIgnoreCase(key))
+        {
+            clientId = value;
+        }
+        else if("-subscriptionId".equalsIgnoreCase(key))
+        {
+            subscriptionId = value;
+        }
+        else if("-persistent".equalsIgnoreCase(key))
+        {
+            persistent = "true".equalsIgnoreCase(value);
+        }
+        else
+        {
+            System.out.println("Ignoring unrecognised option: " + key);
+        }
+    }
+
+    static String getAckModeDescription(int ackMode)
+    {
+        switch(ackMode)
+        {
+            case AMQSession.NO_ACKNOWLEDGE: return "NO_ACKNOWLEDGE";
+            case AMQSession.AUTO_ACKNOWLEDGE: return "AUTO_ACKNOWLEDGE";
+            case AMQSession.CLIENT_ACKNOWLEDGE: return "CLIENT_ACKNOWLEDGE";
+            case AMQSession.DUPS_OK_ACKNOWLEDGE: return "DUPS_OK_ACKNOWELDGE";
+            case AMQSession.PRE_ACKNOWLEDGE: return "PRE_ACKNOWLEDGE";
+        }
+        return "AckMode=" + ackMode;
+    }
+
+    public Connection createConnection() throws Exception
+    {
+        return new Connector().createConnection(this);
+    }
+}

Propchange: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Config.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java (added)
+++ incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java Fri Sep  7 15:41:10 2007
@@ -0,0 +1,141 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.oldtopic;
+import org.apache.log4j.*;
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+public class Listener implements MessageListener
+{
+    private final Connection _connection;
+    private final MessageProducer _controller;
+    private final javax.jms.Session _session;
+    private final MessageFactory _factory;
+    private boolean init;
+    private int count;
+    private long start;
+
+    Listener(Connection connection, int ackMode) throws Exception
+    {
+        this(connection, ackMode, null);
+    }
+
+    Listener(Connection connection, int ackMode, String name) throws Exception
+    {
+        _connection = connection;
+        _session = connection.createSession(false, ackMode);
+        _factory = new MessageFactory(_session);
+
+        //register for events
+        if(name == null)
+        {
+            _factory.createTopicConsumer().setMessageListener(this);
+        }
+        else
+        {
+            _factory.createDurableTopicConsumer(name).setMessageListener(this);
+        }
+
+        _connection.start();
+
+        _controller = _factory.createControlPublisher();
+        System.out.println("Waiting for messages " +
+                Config.getAckModeDescription(ackMode)
+                + (name == null ? "" : " (subscribed with name " + name + " and client id " + connection.getClientID() + ")")
+                + "...");
+
+    }
+
+    private void shutdown()
+    {
+        try
+        {
+            _session.close();
+            _connection.stop();
+            _connection.close();
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace(System.out);
+        }
+    }
+
+    private void report()
+    {
+        try
+        {
+            String msg = getReport();
+            _controller.send(_factory.createReportResponseMessage(msg));
+            System.out.println("Sent report: " + msg);
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace(System.out);
+        }
+    }
+
+    private String getReport()
+    {
+        long time = (System.currentTimeMillis() - start);
+        return "Received " + count + " in " + time + "ms";
+    }
+
+    public void onMessage(Message message)
+    {
+        if(!init)
+        {
+            start = System.currentTimeMillis();
+            count = 0;
+            init = true;
+        }
+
+        if(_factory.isShutdown(message))
+        {
+            shutdown();
+        }
+        else if(_factory.isReport(message))
+        {
+            //send a report:
+            report();
+            init = false;
+        }
+        else if (++count % 100 == 0)
+        {
+            System.out.println("Received " + count + " messages.");
+        }
+    }
+
+    public static void main(String[] argv) throws Exception
+    {
+        Config config = new Config();
+        config.setOptions(argv);
+
+        Connection con = config.createConnection();
+        if(config.getClientId() != null)
+        {
+            con.setClientID(config.getClientId());
+        }
+        new Listener(con, config.getAckMode(), config.getSubscriptionId());
+    }
+}

Propchange: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Listener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java (added)
+++ incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java Fri Sep  7 15:41:10 2007
@@ -0,0 +1,153 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.oldtopic;
+
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQTopic;
+
+import javax.jms.*;
+
+/**
+ */
+class MessageFactory
+{
+    private static final char[] DATA = "abcdefghijklmnopqrstuvwxyz".toCharArray();
+
+    private final Session _session;
+    private final Topic _topic;
+    private final Topic _control;
+    private final byte[] _payload;
+
+
+    MessageFactory(Session session) throws JMSException
+    {
+        this(session, 256);
+    }
+
+    MessageFactory(Session session, int size) throws JMSException
+    {
+        _session = session;
+/*        if(session instanceof AMQSession)
+        {
+            _topic = new AMQTopic("topictest.messages");
+            _control = new AMQTopic("topictest.control");
+        }
+        else*/
+        {
+            _topic = session.createTopic("topictest.messages");
+            _control = session.createTopic("topictest.control");
+        }
+        _payload = new byte[size];
+
+        for(int i = 0; i < size; i++)
+        {
+            _payload[i] = (byte) DATA[i % DATA.length];
+        }
+    }
+
+    Topic getTopic()
+    {
+        return _topic;
+    }
+
+    Message createEventMessage() throws JMSException
+    {
+        BytesMessage msg = _session.createBytesMessage();
+        msg.writeBytes(_payload);
+        return msg;
+    }
+
+    Message createShutdownMessage() throws JMSException
+    {
+        return _session.createTextMessage("SHUTDOWN");
+    }
+
+    Message createReportRequestMessage() throws JMSException
+    {
+        return _session.createTextMessage("REPORT");
+    }
+
+    Message createReportResponseMessage(String msg) throws JMSException
+    {
+        return _session.createTextMessage(msg);
+    }
+
+    boolean isShutdown(Message m)
+    {
+        return checkText(m, "SHUTDOWN");
+    }
+
+    boolean isReport(Message m)
+    {
+        return checkText(m, "REPORT");
+    }
+
+    Object getReport(Message m)
+    {
+        try
+        {
+            return ((TextMessage) m).getText();
+        }
+        catch (JMSException e)
+        {
+            e.printStackTrace(System.out);
+            return e.toString();
+        }
+    }
+
+    MessageConsumer createTopicConsumer() throws Exception
+    {
+        return _session.createConsumer(_topic);
+    }
+
+    MessageConsumer createDurableTopicConsumer(String name) throws Exception
+    {
+        return _session.createDurableSubscriber(_topic, name);
+    }
+
+    MessageConsumer createControlConsumer() throws Exception
+    {
+        return _session.createConsumer(_control);
+    }
+
+    MessageProducer createTopicPublisher() throws Exception
+    {
+        return _session.createProducer(_topic);
+    }
+
+    MessageProducer createControlPublisher() throws Exception
+    {
+        return _session.createProducer(_control);
+    }
+
+    private static boolean checkText(Message m, String s)
+    {
+        try
+        {
+            return m instanceof TextMessage && ((TextMessage) m).getText().equals(s);
+        }
+        catch (JMSException e)
+        {
+            e.printStackTrace(System.out);
+            return false;
+        }
+    }
+}

Propchange: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/MessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java?rev=573740&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java (added)
+++ incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java Fri Sep  7 15:41:10 2007
@@ -0,0 +1,175 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.oldtopic;
+
+import javax.jms.*;
+
+public class Publisher implements MessageListener
+{
+    private final Object _lock = new Object();
+    private final Connection _connection;
+    private final Session _session;
+    private final MessageFactory _factory;
+    private final MessageProducer _publisher;
+    private int _count;
+
+    Publisher(Connection connection, int size, int ackMode, boolean persistent) throws Exception
+    {
+        _connection = connection;
+        _session = _connection.createSession(false, ackMode);
+        _factory = new MessageFactory(_session, size);
+        _publisher = _factory.createTopicPublisher();
+        _publisher.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+        System.out.println("Publishing " + (persistent ? "persistent" : "non-persistent") + " messages of " + size + " bytes, " + Config.getAckModeDescription(ackMode) + ".");
+    }
+
+    private void test(Config config) throws Exception
+    {
+        test(config.getBatch(), config.getDelay(), config.getMessages(), config.getClients(), config.getWarmup());
+    }
+
+    private void test(int batches, long delay, int msgCount, int consumerCount, int warmup) throws Exception
+    {
+        _factory.createControlConsumer().setMessageListener(this);
+        _connection.start();
+
+        if(warmup > 0)
+        {
+            System.out.println("Runing warmup (" + warmup + " msgs)");
+            long time = batch(warmup, consumerCount);
+            System.out.println("Warmup completed in " + time + "ms");
+        }
+
+        long[] times = new long[batches];
+        for(int i = 0; i < batches; i++)
+        {
+            if(i > 0) Thread.sleep(delay*1000);
+            times[i] = batch(msgCount, consumerCount);
+            System.out.println("Batch " + (i+1) + " of " + batches + " completed in " + times[i] + " ms.");
+        }
+
+        long min = min(times);
+        long max = max(times);
+        System.out.println("min: " + min + ", max: " + max + " avg: " + avg(times, min, max));
+
+        //request shutdown
+        _publisher.send(_factory.createShutdownMessage());
+
+        _connection.stop();
+        _connection.close();
+    }
+
+    private long batch(int msgCount, int consumerCount) throws Exception
+    {
+        _count = consumerCount;
+        long start = System.currentTimeMillis();
+        publish(msgCount);
+        waitForCompletion(consumerCount);
+        return System.currentTimeMillis() - start;
+    }
+
+    private void publish(int count) throws Exception
+    {
+
+        //send events
+        for (int i = 0; i < count; i++)
+        {
+            _publisher.send(_factory.createEventMessage());
+            if ((i + 1) % 100 == 0)
+            {
+                System.out.println("Sent " + (i + 1) + " messages");
+            }
+        }
+
+        //request report
+        _publisher.send(_factory.createReportRequestMessage());
+    }
+
+    private void waitForCompletion(int consumers) throws Exception
+    {
+        System.out.println("Waiting for completion...");
+        synchronized (_lock)
+        {
+            while (_count > 0)
+            {
+                _lock.wait();
+            }
+        }
+    }
+
+
+    public void onMessage(Message message)
+    {
+        System.out.println("Received report " + _factory.getReport(message) + " " + --_count + " remaining");
+        if (_count == 0)
+        {
+            synchronized (_lock)
+            {
+                _lock.notify();
+            }
+        }
+    }
+
+    static long min(long[] times)
+    {
+        long min = times.length > 0 ? times[0] : 0;
+        for(int i = 0; i < times.length; i++)
+        {
+            min = Math.min(min, times[i]);
+        }
+        return min;
+    }
+
+    static long max(long[] times)
+    {
+        long max = times.length > 0 ? times[0] : 0;
+        for(int i = 0; i < times.length; i++)
+        {
+            max = Math.max(max, times[i]);
+        }
+        return max;
+    }
+
+    static long avg(long[] times, long min, long max)
+    {
+        long sum = 0;
+        for(int i = 0; i < times.length; i++)
+        {
+            sum += times[i];
+        }
+        sum -= min;
+        sum -= max;
+
+        return (sum / (times.length - 2));
+    }
+
+    public static void main(String[] argv) throws Exception
+    {
+        Config config = new Config();
+        config.setOptions(argv);
+
+        Connection con = config.createConnection();
+        int size = config.getPayload();
+        int ackMode = config.getAckMode();
+        boolean persistent = config.usePersistentMessages();
+        new Publisher(con, size, ackMode, persistent).test(config);
+    }
+}

Propchange: incubator/qpid/branches/M2.1/java/perftests/src/main/java/org/apache/qpid/oldtopic/Publisher.java
------------------------------------------------------------------------------
    svn:eol-style = native