You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2012/05/09 17:38:32 UTC

svn commit: r1336246 - in /qpid/trunk/qpid/cpp/src/qpid: broker/Link.cpp broker/Link.h broker/LinkRegistry.cpp broker/LinkRegistry.h ha/Backup.cpp

Author: aconway
Date: Wed May  9 15:38:32 2012
New Revision: 1336246

URL: http://svn.apache.org/viewvc?rev=1336246&view=rev
Log:
QPID-3603: Make failover subscrption optional for Links.

Used by ha::Backup because HA brokers use a different reconnect list from clients.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/Link.h
    qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h
    qpid/trunk/qpid/cpp/src/qpid/ha/Backup.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp?rev=1336246&r1=1336245&r2=1336246&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp Wed May  9 15:38:32 2012
@@ -136,7 +136,8 @@ Link::Link(const string&  _name,
            const string&        _username,
            const string&        _password,
            Broker*        _broker,
-           Manageable*    parent)
+           Manageable*    parent,
+           bool failover_)
     : name(_name), links(_links),
       configuredTransport(_transport), configuredHost(_host), configuredPort(_port),
       host(_host), port(_port), transport(_transport),
@@ -152,6 +153,7 @@ Link::Link(const string&  _name,
       agent(0),
       listener(l),
       timerTask(new LinkTimerTask(*this, broker->getTimer())),
+      failover(failover_),
       failoverChannel(0)
 {
     if (parent != 0 && broker != 0)
@@ -174,13 +176,15 @@ Link::Link(const string&  _name,
     }
     broker->getTimer().add(timerTask);
 
-    stringstream exchangeName;
-    exchangeName << "qpid.link." << name;
-    std::pair<Exchange::shared_ptr, bool> rc = broker->getExchanges().declare(exchangeName.str(),
-                                                                              exchangeTypeName);
-    failoverExchange = boost::static_pointer_cast<LinkExchange>(rc.first);
-    assert(failoverExchange);
-    failoverExchange->setLink(this);
+    if (failover) {
+        stringstream exchangeName;
+        exchangeName << "qpid.link." << name;
+        std::pair<Exchange::shared_ptr, bool> rc =
+            broker->getExchanges().declare(exchangeName.str(), exchangeTypeName);
+        failoverExchange = boost::static_pointer_cast<LinkExchange>(rc.first);
+        assert(failoverExchange);
+        failoverExchange->setLink(this);
+    }
 }
 
 Link::~Link ()
@@ -192,7 +196,8 @@ Link::~Link ()
     if (mgmtObject != 0)
         mgmtObject->resourceDestroy ();
 
-    broker->getExchanges().destroy(failoverExchange->getName());
+    if (failover)
+        broker->getExchanges().destroy(failoverExchange->getName());
 }
 
 void Link::setStateLH (int newState)
@@ -273,9 +278,7 @@ class DetachedCallback : public SessionH
     void connectionException(framing::connection::CloseCode, const std::string&) {}
     void channelException(framing::session::DetachCode, const std::string&) {}
     void executionException(framing::execution::ErrorCode, const std::string&) {}
-    void detach()  {
-        QPID_LOG(notice, "detached from 'amq.failover' for link: " << name);
-    }
+    void detach() {}
   private:
     const std::string name;
 };
@@ -300,42 +303,44 @@ void Link::opened() {
         QPID_LOG(debug, "Known hosts for peer of inter-broker link: " << url);
     }
 
-    //
-    // attempt to subscribe to failover exchange for updates from remote
-    //
-
-    const std::string queueName = "qpid.link." + framing::Uuid(true).str();
-    failoverChannel = nextChannel();
-
-    SessionHandler& sessionHandler = connection->getChannel(failoverChannel);
-    sessionHandler.setErrorListener(
-        boost::shared_ptr<SessionHandler::ErrorListener>(new DetachedCallback(*this)));
-    failoverSession = queueName;
-    sessionHandler.attachAs(failoverSession);
-
-    framing::AMQP_ServerProxy remoteBroker(sessionHandler.out);
-
-    remoteBroker.getQueue().declare(queueName,
-                                    "",         // alt-exchange
-                                    false,      // passive
-                                    false,      // durable
-                                    true,       // exclusive
-                                    true,       // auto-delete
-                                    FieldTable());
-    remoteBroker.getExchange().bind(queueName,
-                                    FAILOVER_EXCHANGE,
-                                    "",     // no key
-                                    FieldTable());
-    remoteBroker.getMessage().subscribe(queueName,
-                                        failoverExchange->getName(),
-                                        1,           // implied-accept mode
-                                        0,           // pre-acquire mode
-                                        false,       // exclusive
-                                        "",          // resume-id
-                                        0,           // resume-ttl
+    if (failover) {
+        //
+        // attempt to subscribe to failover exchange for updates from remote
+        //
+
+        const std::string queueName = "qpid.link." + framing::Uuid(true).str();
+        failoverChannel = nextChannel();
+
+        SessionHandler& sessionHandler = connection->getChannel(failoverChannel);
+        sessionHandler.setErrorListener(
+            boost::shared_ptr<SessionHandler::ErrorListener>(new DetachedCallback(*this)));
+        failoverSession = queueName;
+        sessionHandler.attachAs(failoverSession);
+
+        framing::AMQP_ServerProxy remoteBroker(sessionHandler.out);
+
+        remoteBroker.getQueue().declare(queueName,
+                                        "",         // alt-exchange
+                                        false,      // passive
+                                        false,      // durable
+                                        true,       // exclusive
+                                        true,       // auto-delete
                                         FieldTable());
-    remoteBroker.getMessage().flow(failoverExchange->getName(), 0, 0xFFFFFFFF);
-    remoteBroker.getMessage().flow(failoverExchange->getName(), 1, 0xFFFFFFFF);
+        remoteBroker.getExchange().bind(queueName,
+                                        FAILOVER_EXCHANGE,
+                                        "",     // no key
+                                        FieldTable());
+        remoteBroker.getMessage().subscribe(queueName,
+                                            failoverExchange->getName(),
+                                            1,           // implied-accept mode
+                                            0,           // pre-acquire mode
+                                            false,       // exclusive
+                                            "",          // resume-id
+                                            0,           // resume-ttl
+                                            FieldTable());
+        remoteBroker.getMessage().flow(failoverExchange->getName(), 0, 0xFFFFFFFF);
+        remoteBroker.getMessage().flow(failoverExchange->getName(), 1, 0xFFFFFFFF);
+    }
 }
 
 void Link::closed(int, std::string text)
@@ -711,11 +716,13 @@ void Link::closeConnection( const std::s
 {
     if (connection != 0) {
         // cancel our subscription to the failover exchange
-        SessionHandler& sessionHandler = connection->getChannel(failoverChannel);
-        if (sessionHandler.getSession()) {
-            framing::AMQP_ServerProxy remoteBroker(sessionHandler.out);
-            remoteBroker.getMessage().cancel(failoverExchange->getName());
-            remoteBroker.getSession().detach(failoverSession);
+        if (failover) {
+            SessionHandler& sessionHandler = connection->getChannel(failoverChannel);
+            if (sessionHandler.getSession()) {
+                framing::AMQP_ServerProxy remoteBroker(sessionHandler.out);
+                remoteBroker.getMessage().cancel(failoverExchange->getName());
+                remoteBroker.getSession().detach(failoverSession);
+            }
         }
         connection->close(CLOSE_CODE_CONNECTION_FORCED, reason);
         connection = 0;

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Link.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Link.h?rev=1336246&r1=1336245&r2=1336246&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Link.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Link.h Wed May  9 15:38:32 2012
@@ -63,7 +63,8 @@ class Link : public PersistableConfig, p
     uint16_t            port;
     std::string         transport;
 
-    bool          durable;
+    bool durable;
+
     std::string        authMechanism;
     std::string        username;
     std::string        password;
@@ -87,6 +88,7 @@ class Link : public PersistableConfig, p
     boost::function<void(Link*)> listener;
     boost::intrusive_ptr<sys::TimerTask> timerTask;
     boost::shared_ptr<broker::LinkExchange> failoverExchange;  // subscribed to remote's amq.failover exchange
+    bool failover; // Do we subscribe to a failover exchange?
     uint failoverChannel;
     std::string failoverSession;
 
@@ -132,7 +134,8 @@ class Link : public PersistableConfig, p
          const std::string&       username,
          const std::string&       password,
          Broker*       broker,
-         management::Manageable* parent = 0);
+         management::Manageable* parent = 0,
+         bool failover=true);
     virtual ~Link();
 
     /** these return the *configured* transport/host/port, which does not change over the

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp?rev=1336246&r1=1336245&r2=1336246&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp Wed May  9 15:38:32 2012
@@ -101,7 +101,8 @@ pair<Link::shared_ptr, bool> LinkRegistr
                                                    bool     durable,
                                                    const string&  authMechanism,
                                                    const string&  username,
-                                                   const string&  password)
+                                                   const string&  password,
+                                                   bool failover)
 
 {
     Mutex::ScopedLock   locker(lock);
@@ -111,10 +112,11 @@ pair<Link::shared_ptr, bool> LinkRegistr
     {
         Link::shared_ptr link;
 
-        link = Link::shared_ptr (new Link (name, this, host, port, transport,
-                                           boost::bind(&LinkRegistry::linkDestroyed, this, _1),
-                                           durable, authMechanism, username, password, broker,
-                                           parent));
+        link = Link::shared_ptr (
+            new Link (name, this, host, port, transport,
+                      boost::bind(&LinkRegistry::linkDestroyed, this, _1),
+                      durable, authMechanism, username, password, broker,
+                      parent, failover));
         if (durable && store) store->create(*link);
         links[name] = link;
         QPID_LOG(debug, "Creating new link; name=" << name );

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h?rev=1336246&r1=1336245&r2=1336246&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h Wed May  9 15:38:32 2012
@@ -82,7 +82,9 @@ namespace broker {
                 bool         durable,
                 const std::string& authMechanism,
                 const std::string& username,
-                const std::string& password);
+                const std::string& password,
+                bool failover=true);
+
         /** determine if Link exists */
         QPID_BROKER_EXTERN boost::shared_ptr<Link>
           getLink(const std::string& name);

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/Backup.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/Backup.cpp?rev=1336246&r1=1336245&r2=1336246&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/Backup.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/Backup.cpp Wed May  9 15:38:32 2012
@@ -62,8 +62,9 @@ void Backup::initialize(const Url& url) 
     std::pair<Link::shared_ptr, bool> result = broker.getLinks().declare(
         broker::QPID_NAME_PREFIX + string("ha.link.") + uuid.str(),
         url[0].host, url[0].port, protocol,
-        false,              // durable
-        settings.mechanism, settings.username, settings.password);
+        false,                  // durable
+        settings.mechanism, settings.username, settings.password,
+        false);                 // amq.failover
     link = result.first;
     link->setUrl(url);
     replicator.reset(new BrokerReplicator(haBroker, link));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org