Modified: incubator/qpid/branches/perftesting/qpid/java/perftests/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/perftesting/qpid/java/perftests/pom.xml?view=diff&rev=502624&r1=502623&r2=502624
==============================================================================
--- incubator/qpid/branches/perftesting/qpid/java/perftests/pom.xml (original)
+++ incubator/qpid/branches/perftesting/qpid/java/perftests/pom.xml Fri Feb  2 
07:28:08 2007
@@ -19,6 +19,7 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0";
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.qpid</groupId>
     <artifactId>qpid-perftests</artifactId>
@@ -35,7 +36,7 @@
 
     <properties>
         <topDirectoryLocation>..</topDirectoryLocation>
-    <log4j.perftests>perftests.log4j</log4j.perftests>
+        <log4j.perftests>perftests.log4j</log4j.perftests>
     </properties>
 
     <!-- Temporary local maven repo, whilst JUnit Toolkit is still reaching 
stable version to add to central maven repository. -->
@@ -43,7 +44,7 @@
         <repository>
           <id>junit-toolkit.snapshots</id>
           <name>JUnit Toolkit SNAPSHOT Repository</name>
-      <url>file://${basedir}/../mvn-repo</url>
+         <url>file://${basedir}/../mvn-repo</url>
           <snapshots>
             <enabled>true</enabled>
           </snapshots>
@@ -55,7 +56,7 @@
         <pluginRepository>
           <id>junit-toolkit-plugin.snapshots</id>
           <name>JUnit Toolkit SNAPSHOT Repository</name>
-      <url>file://${basedir}/../mvn-repo</url>
+         <url>file://${basedir}/../mvn-repo</url>
           <snapshots>
             <enabled>true</enabled>
           </snapshots>
@@ -74,15 +75,15 @@
             <artifactId>log4j</artifactId>
         </dependency>
 
-        <!-- Test dependencies. -->
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>uk.co.thebadgerset</groupId>
+            <artifactId>junit-toolkit</artifactId>
         </dependency>
 
+        <!-- Test dependencies. -->
         <dependency>
-            <groupId>uk.co.thebadgerset</groupId>
-            <artifactId>junit-toolkit</artifactId>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
         </dependency>
 
     </dependencies>
@@ -96,60 +97,57 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <!--<skip>true</skip>-->
-                </configuration>
             </plugin>
 
-            <!-- The JUnit Toolkit maven2 plugin is in the process of being 
added to the maven repository. It will take a day or two from 16/1/2007.
+            <!-- The JUnit Toolkit maven2 plugin is in the process of being 
added to the maven repository.
 
-             Configures the toolkit test runner for performance testing. These 
can be run from within maven, or by using the generated
+                 Configures the toolkit test runner for performance testing. 
These can be run from within maven, or by using the generated
                  scripts.
 
-         To run from maven:
+                 To run from within maven:
 
-         mvn uk.co.thebadgerset:junit-toolkit-maven-plugin:tktest
+                 mvn uk.co.thebadgerset:junit-toolkit-maven-plugin:tktest
 
-         To run from the command line (after doing assembly:assembly goal):
+                 To run from the command line (after doing assembly:assembly 
goal):
 
-         java -cp target/test_jar-jar-with-dependencies.jar 
uk.co.thebadgerset.junit.extensions.TKTestRunner -s 1 -r 100000 -o target 
org.apache.qpid.requestreply.PingPongTestPerf
+                 java -cp target/test_jar-jar-with-dependencies.jar 
uk.co.thebadgerset.junit.extensions.TKTestRunner -s 1 -r 100000 
+                      -o target org.apache.qpid.requestreply.PingPongTestPerf
 
-         To generate the scripts do:
+                 To generate the scripts do:
 
-         mvn uk.co.thebadgerset:junit-toolkit-maven-plugin:tkscriptgen
+                 mvn uk.co.thebadgerset:junit-toolkit-maven-plugin:tkscriptgen
 
-         Then to run the scripts do (after doing assembly:assembly goal):
+                 Then to run the scripts, in the target directory do (after 
doing assembly:assembly goal):
 
-         ./bin/script_name or ./bin/script_name.bat
-
-         These scripts can find everything in the 'all test dependencies' jar 
created by the assembly:assembly goal.
-         -->
+                 ./script_name.sh
 
+                 These scripts can find everything in the 'all test 
dependencies' jar created by the assembly:assembly goal.
+                 -->
             <plugin>
               <groupId>uk.co.thebadgerset</groupId>
-              <artifactId>junit-toolkit-maven-plugin</artifactId>              
+              <artifactId>junit-toolkit-maven-plugin</artifactId>
 
               <configuration>
-               <scriptOutDirectory>target</scriptOutDirectory>
-               <testJar>${project.build.finalName}-all-test-deps.jar</testJar>
+                <scriptOutDirectory>target</scriptOutDirectory>
+                <testJar>${project.build.finalName}-all-test-deps.jar</testJar>
 
                 <systemproperties>
-                          <property>
-                            <name>log4j.configuration</name>
-                            <value>${log4j.perftests}</value>
-                          </property>
-                          <property>
-                            <name>amqj.logging.level</name>
-                            <value>warn</value>
-                          </property>
-                          <property>
-                            <name>badger.level</name>
-                            <value>warn</value>
-                          </property>
-                          <property>
-                            <name>amqj.test.logging.level</name>
-                            <value>info</value>
-                          </property>
+                  <property>
+                    <name>log4j.configuration</name>
+                    <value>${log4j.perftests}</value>
+                  </property>
+                  <property>
+                    <name>amqj.logging.level</name>
+                    <value>warn</value>
+                  </property>
+                  <property><!-- Turn off most logging messages from the 
junit-toolkit test tool itself. -->
+                    <name>badger.level</name>
+                    <value>warn</value>
+                  </property>
+                  <property>
+                    <name>amqj.test.logging.level</name>
+                    <value>info</value>
+                  </property>
                           <property>
                               <name>logdir</name>
                               <value>$QPID_WORK/results</value>
@@ -164,25 +162,45 @@
                           </property>
                   </systemproperties>
 
-        <commands>
-          <!-- Run the ping pong test once. This is just to check toolkit test 
runner is working. Real tests follow. -->
-          <PingOnce>-n PingOnce -s [1] -r 1 -t testPingOk -o . 
org.apache.qpid.ping.PingTestPerf</PingOnce>
-
-          <!-- Tests the accuracy of the throttle implementation at different 
speeds. Throttle is used to restrict message rate in some tsts. -->
-          <ThrottleTest>-n ThrottleTest -r 5 -s [10,10000],samples=100,exp -t 
testThrottle -o . org.apache.qpid.ping.ThrottleTestPerf</ThrottleTest>
-
-          <!--
-             Skim Tests.
-             These are not part of the performance suite. They run quick tests 
to check that the different combinations of
-             options that the performance suite uses are going to work.
-            -->
-          <Skim-Tx>-n Skim-Tx -s [1000] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf transacted=true</Skim-Tx>
-          <Skim-Size>-n Skim-Size -s [1000] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf messagesize=51200</Skim-Size>
-          <Skim-Many>-n Skim-Many -s [1] -c [4] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf</Skim-Many>
-          <Skim-Queues>-n Skim-Queues -s [1000] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf destinationcount=10</Skim-Queues>
-          <Skim-Duration>-n Skim-Duration -s [1000] -d10S -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf</Skim-Duration>
-          <Skim-Rate>-n Skim-Rate -s [1000] -d10S -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf rate=100</Skim-Rate>
+                <commands>
+                  <!-- Single pings. These can be scaled up by overriding the 
parameters when calling the test script. -->
+                  <Ping-Once>-n Ping-Once -s [1] -r 1 -t testPingOk -o . 
org.apache.qpid.ping.PingTestPerf</Ping-Once>
+                  <Ping-Once-Async>-n Ping-Once-Async -s [1] -r 1 -t 
testAsyncPingOk -o . org.apache.qpid.ping.PingAsyncTestPerf</Ping-Once-Async>
+                  <Ping-Latency>-n Ping-Latency -s [1000] -d 10S -t 
testPingLatency -o . org.apache.qpid.ping.PingLatencyTestPerf</Ping-Latency>
+
+                  <!-- More example Tests. These are examples to exercise all 
the features of the test harness. Can scale up with option overrides. -->
+                  <Ping-Tx>-n Ping-Tx -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf transacted=true</Ping-Tx>
+                  <Ping-Size>-n Ping-Size -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf messagesize=512</Ping-Size>
+                  <Ping-Concurrent>-n Ping-Concurrent -s [100] -c [4] -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf</Ping-Concurrent>
+                  <Ping-Many-Queues>
+                     -n Ping-Many-Queues -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf destinationcount=4
+                 </Ping-Many-Queues>
+                  <Ping-Duration>-n Ping-Duration -s [100] -d10S -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf</Ping-Duration>
+                  <Ping-Rate>-n Ping-Rate -s [100] -d10S -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf rate=500</Ping-Rate>
+                 <Ping-PubSub>-n Ping-PubSub -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf pubsub=true</Ping-PubSub>
+                 <Ping-Many-Topics>
+                     -n Ping-Many-Topics -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf pubsub=true destinationcount=4
+                 </Ping-Many-Topics>
+                  <Ping-Persistent>
+                     -n Ping-Persistent -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf persistent=true
+                 </Ping-Persistent>
+                  <Ping-Batch-Logging>
+                     -n Ping-Batch-Logging -s [100] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf BatchSize=10
+                 </Ping-Batch-Logging>
+                 <Ping-Failover-Before-Send> 
+                     -n Ping-Failover-Before-Send -s [100] -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf CommitBatchSize=10 
FailBeforeSend=true
+                 </Ping-Failover-Before-Send>
+                 <Ping-Failover-After-Send>
+                     -n Ping-Failover-After-Send -s [100] -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf CommitBatchSize=10 
FailAfterSend=true
+                 </Ping-Failover-After-Send>
+                 <Ping-Failover-Before-Commit>
+                     -n Ping-Failover-Before-Commit -s [100] -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf CommitBatchSize=10 
FailBeforeCommit=true
+                 </Ping-Failover-Before-Commit>
+                 <Ping-Failover-After-Commit>
+                     -n Ping-Failover-After-Commit -s [100] -o . -t 
testAsyncPingOk org.apache.qpid.ping.PingAsyncTestPerf CommitBatchSize=10 
FailAfterCommit=true
+                 </Ping-Failover-After-Commit>
 
+           
           <!-- P2P Volume Tests. -->
           <VT-Qpid-1>-n VT-Qpid-1 -s [15000000] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf pubsub=true BatchSize=10000 
transacted=true</VT-Qpid-1>
           <VT-Qpid-2>-n VT-Qpid-2 -s [15000000] -o . -t testAsyncPingOk 
org.apache.qpid.ping.PingAsyncTestPerf pubsub=true BatchSize=10000</VT-Qpid-2>
@@ -323,7 +341,6 @@
             </execution>
           </executions>
         </plugin>
-
             <!-- Bundles all the dependencies, fully expanded into a single 
jar, required to run the tests.
 
                  Usefull when bundling system, integration or performance 
tests into a convenient
@@ -353,7 +370,7 @@
         </plugins>
 
         <resources>
-        <!-- Include source files in built jar -->
+            <!-- Include source files in built jar -->
             <resource>
                 <targetPath>src/</targetPath>
                 <filtering>false</filtering>
@@ -362,7 +379,7 @@
                     <include>**/*.java</include>
                 </includes>
             </resource>
-        <!-- Include a log4j configuration in the jar at the root level (don't 
name this log4j.properties though as won't be able to override it). -->
+            <!-- Include a log4j configuration in the jar at the root level 
(don't name this log4j.properties though as won't be able to override it). -->
             <resource>
                 <targetPath>/</targetPath>
                 <filtering>false</filtering>

Added: 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java?view=auto&rev=502624
==============================================================================
--- 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java
 (added)
+++ 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java
 Fri Feb  2 07:28:08 2007
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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.ping;
+
+import java.util.List;
+
+import javax.jms.Destination;
+
+import org.apache.qpid.requestreply.PingPongProducer;
+
+/**
+ * PingClient is a [EMAIL PROTECTED] PingPongProducer} that does not need a 
[EMAIL PROTECTED] org.apache.qpid.requestreply.PingPongBouncer}
+ * to send replies to its pings. It simply listens to its own ping 
destinations, rather than seperate reply queues.
+ * It is an all in one ping client, that produces and consumes its own pings.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Create a ping pong producer that listens to its own pings <td> 
[EMAIL PROTECTED] PingPongProducer}
+ * </table>
+ */
+public class PingClient extends PingPongProducer
+{
+    /**
+     * Creates a ping producer with the specified parameters, of which there 
are many. See their individual comments
+     * for details. This constructor creates ping pong producer but 
de-registers its reply-to destination message
+     * listener, and replaces it by listening to all of its ping destinations.
+     *
+     * @param brokerDetails    The URL of the broker to send pings to.
+     * @param username         The username to log onto the broker with.
+     * @param password         The password to log onto the broker with.
+     * @param virtualpath      The virtual host name to use on the broker.
+     * @param destinationName  The name (or root where multiple destinations 
are used) of the desitination to send
+     *                         pings to.
+     * @param selector         The selector to filter replies with.
+     * @param transacted       Indicates whether or not pings are sent and 
received in transactions.
+     * @param persistent       Indicates whether pings are sent using 
peristent delivery.
+     * @param messageSize      Specifies the size of ping messages to send.
+     * @param verbose          Indicates that information should be printed to 
the console on every ping.
+     * @param afterCommit      Indicates that the user should be promted to 
terminate a broker after commits to test failover.
+     * @param beforeCommit     Indicates that the user should be promted to 
terminate a broker before commits to test failover.
+     * @param afterSend        Indicates that the user should be promted to 
terminate a broker after sends to test failover.
+     * @param beforeSend       Indicates that the user should be promted to 
terminate a broker before sends to test failover.
+     * @param failOnce         Indicates that the failover testing behaviour 
should only happen on the first commit, not all.
+     * @param txBatchSize      Specifies the number of pings to send in each 
transaction.
+     * @param noOfDestinations The number of destinations to ping. Must be 1 
or more.
+     * @param rate             Specified the number of pings per second to 
send. Setting this to 0 means send as fast as
+     *                         possible, with no rate restriction.
+     * @param pubsub
+     *
+     * @throws Exception Any exceptions are allowed to fall through.
+     */
+    public PingClient(String brokerDetails, String username, String password, 
String virtualpath, String destinationName,
+                      String selector, boolean transacted, boolean persistent, 
int messageSize, boolean verbose,
+                      boolean afterCommit, boolean beforeCommit, boolean 
afterSend, boolean beforeSend, boolean failOnce,
+                      int txBatchSize, int noOfDestinations, int rate, boolean 
pubsub) throws Exception
+    {
+        super(brokerDetails, username, password, virtualpath, destinationName, 
selector, transacted, persistent, messageSize,
+              verbose, afterCommit, beforeCommit, afterSend, beforeSend, 
failOnce, txBatchSize, noOfDestinations, rate,
+              pubsub);
+    }
+
+    /**
+     * Returns the ping destinations themselves as the reply destinations for 
this pinger to listen to. This has the
+     * effect of making this pinger listen to its own pings.
+     *
+     * @return The ping destinations.
+     */
+    public List<Destination> getReplyDestinations()
+    {
+        return _pingDestinations;
+    }
+}

Propchange: 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingClient.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java?view=diff&rev=502624&r1=502623&r2=502624
==============================================================================
--- 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java
 (original)
+++ 
incubator/qpid/branches/perftesting/qpid/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongBouncer.java
 Fri Feb  2 07:28:08 2007
@@ -20,7 +20,9 @@
  */
 package org.apache.qpid.requestreply;
 
+import java.io.IOException;
 import java.net.InetAddress;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import javax.jms.*;
@@ -32,7 +34,6 @@
 import org.apache.qpid.client.AMQTopic;
 import org.apache.qpid.jms.ConnectionListener;
 import org.apache.qpid.jms.Session;
-import org.apache.qpid.ping.AbstractPingClient;
 import org.apache.qpid.topic.Config;
 
 /**
@@ -58,7 +59,7 @@
  *
  * @todo Make verbose accept a number of messages, only prints to console 
every X messages.
  */
-public class PingPongBouncer extends AbstractPingClient implements 
MessageListener
+public class PingPongBouncer implements MessageListener
 {
     private static final Logger _logger = 
Logger.getLogger(PingPongBouncer.class);
 
@@ -73,6 +74,9 @@
     /** The default exclusive flag for the message consumer. */
     private static final boolean EXCLUSIVE = false;
 
+    /** A convenient formatter to use when time stamping output. */
+    protected static final SimpleDateFormat timestampFormatter = new 
SimpleDateFormat("hh:mm:ss:SS");
+
     /** Used to indicate that the reply generator should log timing info to 
the console (logger info level). */
     private boolean _verbose = false;
 
@@ -93,6 +97,24 @@
     /** The producer session. */
     private Session _producerSession;
 
+    /** Holds the connection to the broker. */
+    private AMQConnection _connection;
+
+    /** Flag used to indicate if this is a point to point or pub/sub ping 
client. */
+    private boolean _isPubSub = false;
+
+    /**
+     * This flag is used to indicate that the user should be prompted to kill 
a broker, in order to test
+     * failover, immediately before committing a transaction.
+     */
+    protected boolean _failBeforeCommit = false;
+
+    /**
+     * This flag is used to indicate that the user should be prompted to a 
kill a broker, in order to test
+     * failover, immediate after committing a transaction.
+     */
+    protected boolean _failAfterCommit = false;
+
     /**
      * Creates a PingPongBouncer on the specified producer and consumer 
sessions.
      *
@@ -110,8 +132,8 @@
      * @throws Exception All underlying exceptions allowed to fall through. 
This is only test code...
      */
     public PingPongBouncer(String brokerDetails, String username, String 
password, String virtualpath,
-                           String destinationName, boolean persistent, boolean 
transacted, String selector,
-                           boolean verbose, boolean pubsub) throws Exception
+                           String destinationName, boolean persistent, boolean 
transacted, String selector, boolean verbose,
+                           boolean pubsub) throws Exception
     {
         // Create a client id to uniquely identify this client.
         InetAddress address = InetAddress.getLocalHost();
@@ -133,7 +155,8 @@
 
         // Create the queue to listen for message on.
         createConsumerDestination(destinationName);
-        MessageConsumer consumer = 
_consumerSession.createConsumer(_consumerDestination, PREFETCH, NO_LOCAL, 
EXCLUSIVE, selector);
+        MessageConsumer consumer =
+            _consumerSession.createConsumer(_consumerDestination, PREFETCH, 
NO_LOCAL, EXCLUSIVE, selector);
 
         // Create a producer for the replies, without a default destination.
         _replyProducer = _producerSession.createProducer(null);
@@ -144,18 +167,6 @@
         consumer.setMessageListener(this);
     }
 
-    private void createConsumerDestination(String name)
-    {
-        if (isPubSub())
-        {
-            _consumerDestination = new AMQTopic(name);
-        }
-        else
-        {
-            _consumerDestination = new AMQQueue(name);
-        }
-    }
-
     /**
      * Starts a stand alone ping-pong client running in verbose mode.
      *
@@ -177,12 +188,13 @@
         Config config = new Config();
         config.setOptions(args);
         String brokerDetails = config.getHost() + ":" + config.getPort();
-        String virtualpath = "/test";        
+        String virtualpath = "test";
         String destinationName = config.getDestination();
         if (destinationName == null)
         {
             destinationName = DEFAULT_DESTINATION_NAME;
         }
+
         String selector = config.getSelector();
         boolean transacted = config.isTransacted();
         boolean persistent = config.usePersistentMessages();
@@ -192,13 +204,22 @@
         //String selector = null;
 
         // Instantiate the ping pong client with the command line options and 
start it running.
-        PingPongBouncer pingBouncer = new PingPongBouncer(brokerDetails, 
"guest", "guest", virtualpath,
-                                                destinationName, persistent, 
transacted, selector, verbose, pubsub);
+        PingPongBouncer pingBouncer =
+            new PingPongBouncer(brokerDetails, "guest", "guest", virtualpath, 
destinationName, persistent, transacted,
+                                selector, verbose, pubsub);
         pingBouncer.getConnection().start();
 
         System.out.println("Waiting...");
     }
 
+    private static void usage()
+    {
+        System.err.println("Usage: PingPongBouncer \n" + "-host : broker 
host\n" + "-port : broker port\n"
+                           + "-destinationname : queue/topic name\n" + 
"-transacted : (true/false). Default is false\n"
+                           + "-persistent : (true/false). Default is false\n"
+                           + "-pubsub     : (true/false). Default is false\n" 
+ "-selector   : selector string\n");
+    }
+
     /**
      * This is a callback method that is notified of all messages for which 
this has been registered as a message
      * listener on a message consumer. It sends a reply (pong) to all messages 
it receieves on the reply to
@@ -260,14 +281,145 @@
         }
     }
 
-    private static void usage()
+    /**
+     * Gets the underlying connection that this ping client is running on.
+     *
+     * @return The underlying connection that this ping client is running on.
+     */
+    public AMQConnection getConnection()
+    {
+        return _connection;
+    }
+
+    /**
+     * Sets the connection that this ping client is using.
+     *
+     * @param connection The ping connection.
+     */
+    public void setConnection(AMQConnection connection)
+    {
+        this._connection = connection;
+    }
+
+    /**
+     * Sets or clears the pub/sub flag to indiciate whether this client is 
pinging a queue or a topic.
+     *
+     * @param pubsub <tt>true</tt> if this client is pinging a topic, 
<tt>false</tt> if it is pinging a queue.
+     */
+    public void setPubSub(boolean pubsub)
+    {
+        _isPubSub = pubsub;
+    }
+
+    /**
+     * Checks whether this client is a p2p or pub/sub ping client.
+     *
+     * @return <tt>true</tt> if this client is pinging a topic, <tt>false</tt> 
if it is pinging a queue.
+     */
+    public boolean isPubSub()
+    {
+        return _isPubSub;
+    }
+
+    /**
+     * Convenience method to commit the transaction on the specified session. 
If the session to commit on is not
+     * a transactional session, this method does nothing.
+     *
+     * <p/>If the [EMAIL PROTECTED] #_failBeforeCommit} flag is set, this will 
prompt the user to kill the broker before the
+     * commit is applied. If the [EMAIL PROTECTED] #_failAfterCommit} flag is 
set, this will prompt the user to kill the broker
+     * after the commit is applied.
+     *
+     * @throws javax.jms.JMSException If the commit fails and then the 
rollback fails.
+     */
+    protected void commitTx(Session session) throws JMSException
+    {
+        if (session.getTransacted())
+        {
+            try
+            {
+                if (_failBeforeCommit)
+                {
+                    _logger.trace("Failing Before Commit");
+                    doFailover();
+                }
+
+                session.commit();
+
+                if (_failAfterCommit)
+                {
+                    _logger.trace("Failing After Commit");
+                    doFailover();
+                }
+
+                _logger.trace("Session Commited.");
+            }
+            catch (JMSException e)
+            {
+                _logger.trace("JMSException on commit:" + e.getMessage(), e);
+
+                try
+                {
+                    session.rollback();
+                    _logger.debug("Message rolled back.");
+                }
+                catch (JMSException jmse)
+                {
+                    _logger.trace("JMSE on rollback:" + jmse.getMessage(), 
jmse);
+
+                    // Both commit and rollback failed. Throw the rollback 
exception.
+                    throw jmse;
+                }
+            }
+        }
+    }
+
+    /**
+     * Prompts the user to terminate the named broker, in order to test 
failover functionality. This method will block
+     * until the user supplied some input on the terminal.
+     *
+     * @param broker The name of the broker to terminate.
+     */
+    protected void doFailover(String broker)
     {
-        System.err.println("Usage: PingPongBouncer \n" + "-host : broker 
host\n" + "-port : broker port\n" +
-                           "-destinationname : queue/topic name\n" +
-                           "-transacted : (true/false). Default is false\n" +
-                           "-persistent : (true/false). Default is false\n" +
-                           "-pubsub     : (true/false). Default is false\n" +
-                           "-selector   : selector string\n");
+        System.out.println("Kill Broker " + broker + " now.");
+        try
+        {
+            System.in.read();
+        }
+        catch (IOException e)
+        { }
+
+        System.out.println("Continuing.");
+    }
+
+    /**
+     * Prompts the user to terminate the broker, in order to test failover 
functionality. This method will block
+     * until the user supplied some input on the terminal.
+     */
+    protected void doFailover()
+    {
+        System.out.println("Kill Broker now.");
+        try
+        {
+            System.in.read();
+        }
+        catch (IOException e)
+        { }
+
+        System.out.println("Continuing.");
+
+    }
+
+    private void createConsumerDestination(String name)
+    {
+        if (isPubSub())
+        {
+            _consumerDestination = new AMQTopic(name);
+        }
+        else
+        {
+            _consumerDestination = new AMQQueue(name);
+        }
     }
 
     /**


Reply via email to