Author: gsim
Date: Fri Oct 10 12:04:08 2008
New Revision: 703558

URL: http://svn.apache.org/viewvc?rev=703558&view=rev
Log:
Identify transports by name


Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=703558&r1=703557&r2=703558&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Fri Oct 10 
12:04:08 2008
@@ -370,34 +370,35 @@
     return status;
 }
 
-boost::shared_ptr<ProtocolFactory> Broker::getProtocolFactory() const {
-    assert(protocolFactories.size() > 0);
-    return protocolFactories[0];
+boost::shared_ptr<ProtocolFactory> Broker::getProtocolFactory(const 
std::string& name) const {
+    ProtocolFactoryMap::const_iterator i = protocolFactories.find(name);
+    if (i == protocolFactories.end()) return 
boost::shared_ptr<ProtocolFactory>();
+    else return i->second;
 }
 
-void Broker::registerProtocolFactory(ProtocolFactory::shared_ptr 
protocolFactory) {
-    protocolFactories.push_back(protocolFactory);
-}
-
-// TODO: This can only work if there is only one protocolFactory
+//TODO: should this allow choosing the port by transport name?
 uint16_t Broker::getPort() const  {
     return getProtocolFactory()->getPort();
 }
 
-// TODO: This should iterate over all protocolFactories
-void Broker::accept() {
-    for (unsigned int i = 0; i < protocolFactories.size(); ++i)
-        protocolFactories[i]->accept(poller, factory.get());
+void Broker::registerProtocolFactory(const std::string& name, 
ProtocolFactory::shared_ptr protocolFactory) {
+    protocolFactories[name] = protocolFactory;
 }
 
+void Broker::accept() {
+    for (ProtocolFactoryMap::const_iterator i = protocolFactories.begin(); i 
!= protocolFactories.end(); i++) {
+        i->second->accept(poller, factory.get());
+    }
+}
 
-// TODO: How to chose the protocolFactory to use for the connection
 void Broker::connect(
-    const std::string& host, uint16_t port, bool /*useSsl*/,
+    const std::string& host, uint16_t port, const std::string& transport,
     boost::function2<void, int, std::string> failed,
     sys::ConnectionCodec::Factory* f)
 {
-    getProtocolFactory()->connect(poller, host, port, f ? f : factory.get(), 
failed);
+    boost::shared_ptr<ProtocolFactory> pf = getProtocolFactory(transport);
+    if (pf) pf->connect(poller, host, port, f ? f : factory.get(), failed);
+    else throw Exception(QPID_MSG("Unsupported transport type: " << 
transport));
 }
 
 void Broker::connect(
@@ -407,7 +408,7 @@
 {
     url.throwIfEmpty();
     TcpAddress addr=boost::get<TcpAddress>(url[0]);
-    connect(addr.host, addr.port, false, failed, f);
+    connect(addr.host, addr.port, TCP_TRANSPORT, failed, f);
 }
 
 uint32_t Broker::queueMoveMessages( 
@@ -436,7 +437,7 @@
   return knownBrokers;
 }
 
-
+const std::string Broker::TCP_TRANSPORT("tcp");
 
 }} // namespace qpid::broker
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?rev=703558&r1=703557&r2=703558&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Fri Oct 10 12:04:08 
2008
@@ -93,10 +93,12 @@
     };
  
   private:
+    typedef std::map<std::string, boost::shared_ptr<sys::ProtocolFactory> > 
ProtocolFactoryMap;
+
     boost::shared_ptr<sys::Poller> poller;
     Options config;
     management::ManagementAgent::Singleton managementAgentSingleton;
-    std::vector< boost::shared_ptr<sys::ProtocolFactory> > protocolFactories;
+    ProtocolFactoryMap protocolFactories;
     MessageStore* store;
     AclModule* acl;
     DataDir dataDir;
@@ -166,13 +168,14 @@
                                                         std::string& text);
     
     /** Add to the broker's protocolFactorys */
-    void registerProtocolFactory(boost::shared_ptr<sys::ProtocolFactory>);
+    void registerProtocolFactory(const std::string& name, 
boost::shared_ptr<sys::ProtocolFactory>);
 
     /** Accept connections */
     void accept();
 
     /** Create a connection to another broker. */
-    void connect(const std::string& host, uint16_t port, bool useSsl,
+    void connect(const std::string& host, uint16_t port, 
+                 const std::string& transport,
                  boost::function2<void, int, std::string> failed,
                  sys::ConnectionCodec::Factory* =0);
     /** Create a connection to another broker. */
@@ -189,7 +192,7 @@
 
     // TODO: There isn't a single ProtocolFactory so the use of the following 
needs to be fixed
     // For the present just return the first ProtocolFactory registered.
-    boost::shared_ptr<sys::ProtocolFactory> getProtocolFactory() const;
+    boost::shared_ptr<sys::ProtocolFactory> getProtocolFactory(const 
std::string& name = TCP_TRANSPORT) const;
 
     /** Expose poller so plugins can register their descriptors. */
     boost::shared_ptr<sys::Poller> getPoller();
@@ -200,7 +203,8 @@
     Timer& getTimer() { return timer; }
 
     boost::function<std::vector<Url> ()> getKnownBrokers;
-    
+
+    static const std::string TCP_TRANSPORT;
 };
 
 }}

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp?rev=703558&r1=703557&r2=703558&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp Fri Oct 10 12:04:08 
2008
@@ -107,7 +107,7 @@
         // Set the state before calling connect.  It is possible that connect
         // will fail synchronously and call Link::closed before returning.
         setStateLH(STATE_CONNECTING);
-        broker->connect (host, port, useSsl,
+        broker->connect (host, port, useSsl ? "ssl" : Broker::TCP_TRANSPORT,
                          boost::bind (&Link::closed, this, _1, _2));
     } catch(std::exception& e) {
         setStateLH(STATE_WAITING);

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp?rev=703558&r1=703557&r2=703558&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp Fri Oct 10 
12:04:08 2008
@@ -217,7 +217,7 @@
             const broker::Broker::Options& opts = broker->getOptions();
             ProtocolFactory::shared_ptr protocol(new 
RdmaIOProtocolFactory(opts.port, opts.connectionBacklog));
             QPID_LOG(info, "Listening on RDMA port " << protocol->getPort());
-            broker->registerProtocolFactory(protocol);
+            broker->registerProtocolFactory("rdma", protocol);
         }
     }
 } rdmaPlugin;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=703558&r1=703557&r2=703558&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp Fri Oct 10 
12:04:08 2008
@@ -67,7 +67,7 @@
             const broker::Broker::Options& opts = broker->getOptions();
             ProtocolFactory::shared_ptr protocol(new 
AsynchIOProtocolFactory(opts.port, opts.connectionBacklog, opts.tcpNoDelay));
             QPID_LOG(info, "Listening on TCP port " << protocol->getPort());
-            broker->registerProtocolFactory(protocol);
+            broker->registerProtocolFactory("tcp", protocol);
         }
     }
 } tcpPlugin;


Reply via email to