activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r883495 - /activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
Date Mon, 23 Nov 2009 20:45:40 GMT
Author: tabish
Date: Mon Nov 23 20:45:39 2009
New Revision: 883495

URL: http://svn.apache.org/viewvc?rev=883495&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-250

Update one of the samples to show how to listen for Transport error / recovery.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp?rev=883495&r1=883494&r2=883495&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
Mon Nov 23 20:45:39 2009
@@ -19,6 +19,8 @@
 #include <decaf/lang/Runnable.h>
 #include <decaf/util/concurrent/CountDownLatch.h>
 #include <activemq/core/ActiveMQConnectionFactory.h>
+#include <activemq/core/ActiveMQConnection.h>
+#include <activemq/transport/DefaultTransportListener.h>
 #include <activemq/library/ActiveMQCPP.h>
 #include <decaf/lang/Integer.h>
 #include <activemq/util/Config.h>
@@ -36,6 +38,7 @@
 
 using namespace activemq;
 using namespace activemq::core;
+using namespace activemq::transport;
 using namespace decaf::lang;
 using namespace decaf::util;
 using namespace decaf::util::concurrent;
@@ -44,7 +47,8 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 class SimpleAsyncConsumer : public ExceptionListener,
-                            public MessageListener {
+                            public MessageListener,
+                            public DefaultTransportListener {
 private:
 
     Connection* connection;
@@ -87,6 +91,12 @@
             // Create a Connection
             connection = connectionFactory->createConnection();
             delete connectionFactory;
+
+            ActiveMQConnection* amqConnection = dynamic_cast<ActiveMQConnection*>(
connection );
+            if( amqConnection != NULL ) {
+                amqConnection->addTransportListener( this );
+            }
+
             connection->start();
 
             connection->setExceptionListener(this);
@@ -144,11 +154,19 @@
 
     // If something bad happens you see it here as this class is also been
     // registered as an ExceptionListener with the connection.
-    virtual void onException( const CMSException& ex AMQCPP_UNUSED) {
+    virtual void onException( const CMSException& ex AMQCPP_UNUSED ) {
         printf("CMS Exception occurred.  Shutting down client.\n");
         exit(1);
     }
 
+    virtual void transportInterrupted() {
+        std::cout << "The Connection's Transport has been Interrupted." << std::endl;
+    }
+
+    virtual void transportResumed() {
+        std::cout << "The Connection's Transport has been Restored." << std::endl;
+    }
+
 private:
 
     void cleanup(){



Mime
View raw message