Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 85309 invoked from network); 25 Nov 2008 14:59:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Nov 2008 14:59:49 -0000 Received: (qmail 95194 invoked by uid 500); 25 Nov 2008 14:59:59 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 95175 invoked by uid 500); 25 Nov 2008 14:59:59 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 95166 invoked by uid 99); 25 Nov 2008 14:59:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Nov 2008 06:59:59 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Nov 2008 14:58:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 23E882388882; Tue, 25 Nov 2008 06:58:58 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r720509 - /activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp Date: Tue, 25 Nov 2008 14:58:57 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081125145858.23E882388882@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Tue Nov 25 06:58:57 2008 New Revision: 720509 URL: http://svn.apache.org/viewvc?rev=720509&view=rev Log: Updated Producer example with connection retries. Modified: activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp Modified: activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp?rev=720509&r1=720508&r2=720509&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp (original) +++ activemq/activemq-cpp/trunk/src/examples/producers/SimpleProducer.cpp Tue Nov 25 06:58:57 2008 @@ -31,6 +31,7 @@ #include #include #include +#include using namespace activemq; using namespace activemq::core; @@ -54,6 +55,7 @@ unsigned int numMessages; std::string brokerURI; std::string destURI; + unsigned int connectRetries; public: @@ -61,7 +63,8 @@ unsigned int numMessages, const std::string& destURI, bool useTopic = false, - bool clientAck = false ){ + bool clientAck = false, + unsigned int connectRetries = 0 ){ connection = NULL; session = NULL; destination = NULL; @@ -71,24 +74,41 @@ this->brokerURI = brokerURI; this->destURI = destURI; this->clientAck = clientAck; + this->connectRetries = 0; } virtual ~SimpleProducer(){ cleanup(); } + void setConnectRetries( unsigned int retries ) { + this->connectRetries = retries; + } + + unsigned int getConnectRetries() const { + return this->connectRetries; + } + virtual void run() { try { // Create a ConnectionFactory - ActiveMQConnectionFactory* connectionFactory = - new ActiveMQConnectionFactory( brokerURI ); - - // Create a Connection - connection = connectionFactory->createConnection(); - connection->start(); + auto_ptr connectionFactory( + new ActiveMQConnectionFactory( brokerURI ) ); - // free the factory, we are done with it. - delete connectionFactory; + unsigned int retries = this->connectRetries; + do{ + // Create a Connection + try{ + connection = connectionFactory->createConnection(); + connection->start(); + } catch( CMSException& e ) { + e.printStackTrace(); + + if( retries == 0 ) { + return; + } + } + } while( retries-- != 0 ); // Create a Session if( clientAck ) { @@ -215,8 +235,20 @@ //============================================================ bool useTopics = false; + // Pass an integer value to the producer for retry + unsigned int connectRetries = 0; + + if( argc > 1 ) { + try { + connectRetries = decaf::lang::Integer::parseInt( argv[1] ); + } catch( decaf::lang::exceptions::NumberFormatException& ex ) { + connectRetries = 0; + } + } + // Create the producer and run it. SimpleProducer producer( brokerURI, numMessages, destURI, useTopics ); + producer.setConnectRetries( connectRetries ); producer.run(); std::cout << "-----------------------------------------------------\n";