org.apache.qpid.requestreply
Class PingPongBouncer

java.lang.Object
  extended by org.apache.qpid.requestreply.PingPongBouncer
All Implemented Interfaces:
MessageListener

public class PingPongBouncer
extends Object
implements MessageListener

PingPongBouncer is a message listener the bounces back messages to their reply to destination. This is used to return ping messages generated by PingPongProducer but could be used for other purposes too.

The correlation id from the received message is extracted, and placed into the reply as the correlation id. Messages are bounced back to their reply-to destination. The original sender of the message has the option to use either a unique temporary queue or the correlation id to correlate the original message to the reply.

There is a verbose mode flag which causes information about each ping to be output to the console (info level logging, so usually console). This can be helpfull to check the bounce backs are happening but should be disabled for real timing tests as writing to the console will slow things down.

CRC Card
Responsibilities Collaborations
Bounce back messages to their reply to destination.
Provide command line invocation to start the bounce back on a configurable broker url.

Todo:
Replace the command line parsing with a neater tool., Make verbose accept a number of messages, only prints to console every X messages.

Nested Class Summary
static class PingPongBouncer.FailoverNotifier
          A connection listener that logs out any failover complete events.
 
Field Summary
protected  boolean _failAfterCommit
          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 _failBeforeCommit
          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 static SimpleDateFormat timestampFormatter
          A convenient formatter to use when time stamping output.
 
Constructor Summary
PingPongBouncer(String brokerDetails, String username, String password, String virtualpath, String destinationName, boolean persistent, boolean transacted, String selector, boolean verbose, boolean pubsub)
          Creates a PingPongBouncer on the specified producer and consumer sessions.
 
Method Summary
protected  void commitTx(org.apache.qpid.jms.Session session)
          Convenience method to commit the transaction on the specified controlSession.
protected  void doFailover()
          Prompts the user to terminate the broker, in order to test failover functionality.
protected  void doFailover(String broker)
          Prompts the user to terminate the named broker, in order to test failover functionality.
 org.apache.qpid.client.AMQConnection getConnection()
          Gets the underlying connection that this ping client is running on.
 boolean isPubSub()
          Checks whether this client is a p2p or pub/sub ping client.
static void main(String[] args)
          Starts a stand alone ping-pong client running in verbose mode.
 void onMessage(Message message)
          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.
 void setConnection(org.apache.qpid.client.AMQConnection connection)
          Sets the connection that this ping client is using.
 void setPubSub(boolean pubsub)
          Sets or clears the pub/sub flag to indiciate whether this client is pinging a queue or a topic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timestampFormatter

protected static final SimpleDateFormat timestampFormatter
A convenient formatter to use when time stamping output.


_failBeforeCommit

protected boolean _failBeforeCommit
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.


_failAfterCommit

protected boolean _failAfterCommit
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.

Constructor Detail

PingPongBouncer

public PingPongBouncer(String brokerDetails,
                       String username,
                       String password,
                       String virtualpath,
                       String destinationName,
                       boolean persistent,
                       boolean transacted,
                       String selector,
                       boolean verbose,
                       boolean pubsub)
                throws Exception
Creates a PingPongBouncer on the specified producer and consumer sessions.

Parameters:
brokerDetails - The addresses of the brokers to connect to.
username - The broker username.
password - The broker password.
virtualpath - The virtual host name within the broker.
destinationName - The name of the queue to receive pings on (or root of the queue name where many queues are generated).
persistent - A flag to indicate that persistent message should be used.
transacted - A flag to indicate that pings should be sent within transactions.
selector - A message selector to filter received pings with.
verbose - A flag to indicate that message timings should be sent to the console.
Throws:
Exception - All underlying exceptions allowed to fall through. This is only test code...
Method Detail

main

public static void main(String[] args)
                 throws Exception
Starts a stand alone ping-pong client running in verbose mode.

Parameters:
args -
Throws:
Exception

onMessage

public void onMessage(Message message)
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 destination of the message.

Specified by:
onMessage in interface MessageListener
Parameters:
message - The message that triggered this callback.

getConnection

public org.apache.qpid.client.AMQConnection getConnection()
Gets the underlying connection that this ping client is running on.

Returns:
The underlying connection that this ping client is running on.

setConnection

public void setConnection(org.apache.qpid.client.AMQConnection connection)
Sets the connection that this ping client is using.

Parameters:
connection - The ping connection.

setPubSub

public void setPubSub(boolean pubsub)
Sets or clears the pub/sub flag to indiciate whether this client is pinging a queue or a topic.

Parameters:
pubsub - true if this client is pinging a topic, false if it is pinging a queue.

isPubSub

public boolean isPubSub()
Checks whether this client is a p2p or pub/sub ping client.

Returns:
true if this client is pinging a topic, false if it is pinging a queue.

commitTx

protected void commitTx(org.apache.qpid.jms.Session session)
                 throws JMSException
Convenience method to commit the transaction on the specified controlSession. If the controlSession to commit on is not a transactional controlSession, this method does nothing.

If the _failBeforeCommit flag is set, this will prompt the user to kill the broker before the commit is applied. If the _failAfterCommit flag is set, this will prompt the user to kill the broker after the commit is applied.

Throws:
JMSException - If the commit fails and then the rollback fails.

doFailover

protected void doFailover(String broker)
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.

Parameters:
broker - The name of the broker to terminate.

doFailover

protected void doFailover()
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.



Licensed to the Apache Software Foundation