[asterisk-scf-commits] team/dlee/servicediscovery.git branch "ami" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Nov 19 10:35:59 CST 2010


branch "ami" has been updated
       via  dd4d3d7d801b7babf5cf24b66c88cb14869a1fae (commit)
       via  169e47bf4b05b6a721b6473905bc5d76e0411b09 (commit)
      from  f0ff0f1b9a5de9eb233d8e70ac68c39184b88eac (commit)

Summary of changes:
 src/ServiceLocator.cpp |  103 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 85 insertions(+), 18 deletions(-)


- Log -----------------------------------------------------------------
commit dd4d3d7d801b7babf5cf24b66c88cb14869a1fae
Author: David M. Lee <dlee at digium.com>
Date:   Fri Nov 19 10:33:56 2010 -0600

    Fixed unit test, but not in an optimal way.
    
    ServiceLocator's AMD operations spawn off new threads to allow
    concurrent discovery.  Ideally, we want to avoid new threads and
    simply use AMI to contact comparators.  But it's a step in the right
    direction.

diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index d3d5d77..e16dc03 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -14,6 +14,8 @@
  * at the top of the source tree.
  */
 
+#include <boost/thread.hpp>
+
 #include <Ice/Ice.h>
 #include <IceStorm/IceStorm.h>
 #include <IceBox/IceBox.h>
@@ -75,20 +77,92 @@ private:
     ServiceLocatorManagementImpl* mLocatorServiceManagement;
 };
 
+class LocateThread
+{
+public:
+    LocateThread(const AMD_ServiceLocator_locatePtr& cb,
+        const ServiceLocatorParamsPtr& params,
+        ServiceLocatorManagementImpl* locatorServiceManagement) :
+        mCallback(cb),
+        mParams(params),
+        mLocatorServiceManagement(locatorServiceManagement)
+    {
+    }
+
+    void operator()()
+    {
+        try
+        {
+            lg(Info) << "locate(" << mParams->category << ")\n";
+            mCallback->ice_response(mLocatorServiceManagement->locate(mParams));
+            lg(Info) << "locate(" << mParams->category << "): complete\n";
+        }
+        catch(std::exception const &e)
+        {
+            lg(Info) << "locate(" << mParams->category << "): std::exception(" << e.what() << ")\n";
+            mCallback->ice_exception(e);
+        }
+        catch(...)
+        {
+            lg(Info) << "locate(" << mParams->category << "): bad::exception\n";
+            mCallback->ice_exception();
+        }
+    }
+private:
+    AMD_ServiceLocator_locatePtr mCallback;
+    ServiceLocatorParamsPtr mParams;
+    ServiceLocatorManagementImpl* mLocatorServiceManagement;
+};
+
+class LocateAllThread
+{
+public:
+    LocateAllThread(const AMD_ServiceLocator_locateAllPtr& cb,
+        const ServiceLocatorParamsPtr& params,
+        ServiceLocatorManagementImpl* locatorServiceManagement) :
+        mCallback(cb),
+        mParams(params),
+        mLocatorServiceManagement(locatorServiceManagement)
+    {
+    }
+
+    void operator()()
+    {
+        try
+        {
+            mCallback->ice_response(mLocatorServiceManagement->locateAll(mParams));
+        }
+catch(std::exception const &e)
+        {
+            lg(Info) << "locate(" << mParams->category << "): std::exception(" << e.what() << ")\n";
+            mCallback->ice_exception(e);
+        }
+        catch(...)
+        {
+            lg(Info) << "locate(" << mParams->category << "): bad::exception\n";
+            mCallback->ice_exception();
+        }
+    }
+private:
+    AMD_ServiceLocator_locateAllPtr mCallback;
+    ServiceLocatorParamsPtr mParams;
+    ServiceLocatorManagementImpl* mLocatorServiceManagement;
+};
+
 }
 
 void ServiceLocatorImpl::locate_async(const AMD_ServiceLocator_locatePtr& cb,
     const ServiceLocatorParamsPtr& params,
     const ::Ice::Current&)
 {
-    cb->ice_response(mLocatorServiceManagement->locate(params));
+    boost::thread(LocateThread(cb, params, mLocatorServiceManagement));
 }
 
 void ServiceLocatorImpl::locateAll_async(const AMD_ServiceLocator_locateAllPtr& cb,
     const ServiceLocatorParamsPtr& params,
     const ::Ice::Current&)
 {
-    cb->ice_response(mLocatorServiceManagement->locateAll(params));
+    boost::thread(LocateAllThread(cb, params, mLocatorServiceManagement));
 }
 
 void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& communicator,

commit 169e47bf4b05b6a721b6473905bc5d76e0411b09
Author: David M. Lee <dlee at digium.com>
Date:   Fri Nov 19 09:40:36 2010 -0600

    ServiceLocator now uses AMD to dispatch operations.
    
    This is the first step toward getting ServiceLocator to be resilient
    to non-responsive comparators.

diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index b76772c..d3d5d77 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -63,8 +63,9 @@ class ServiceLocatorImpl : public ServiceLocator
 public:
     ServiceLocatorImpl(ServiceLocatorManagementImpl* LocatorServiceManagement) :
         mLocatorServiceManagement(LocatorServiceManagement) { };
-    Ice::ObjectPrx locate(const ServiceLocatorParamsPtr&, const Ice::Current&);
-    Ice::ObjectProxySeq locateAll(const ServiceLocatorParamsPtr&, const Ice::Current&);
+
+    void locate_async(const ::AsteriskSCF::Core::Discovery::V1::AMD_ServiceLocator_locatePtr&, const ::AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const ::Ice::Current&);
+    void locateAll_async(const ::AsteriskSCF::Core::Discovery::V1::AMD_ServiceLocator_locateAllPtr&, const ::AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const ::Ice::Current&);
 private:
     /**
      * A pointer to the ServiceManagement implementation as that is where everything is
@@ -76,26 +77,18 @@ private:
 
 }
 
-/**
- * Implementation of the locate method as defined in service_locator.ice
- */
-Ice::ObjectPrx ServiceLocatorImpl::locate(const ServiceLocatorParamsPtr& params,
-    const Ice::Current&)
+void ServiceLocatorImpl::locate_async(const AMD_ServiceLocator_locatePtr& cb,
+    const ServiceLocatorParamsPtr& params,
+    const ::Ice::Current&)
 {
-    /* This API call forwards into the management implementation, it is separated to
-     * provide a level of security. */
-    return mLocatorServiceManagement->locate(params);
+    cb->ice_response(mLocatorServiceManagement->locate(params));
 }
 
-/**
- * Implementation of the locateAll method as defined in service_locator.ice
- */
-Ice::ObjectProxySeq ServiceLocatorImpl::locateAll(const ServiceLocatorParamsPtr& params,
-    const Ice::Current&)
+void ServiceLocatorImpl::locateAll_async(const AMD_ServiceLocator_locateAllPtr& cb,
+    const ServiceLocatorParamsPtr& params,
+    const ::Ice::Current&)
 {
-    /* This API call forwards into the management implementation, it is separated to
-     * provide a level of security. */
-    return mLocatorServiceManagement->locateAll(params);
+    cb->ice_response(mLocatorServiceManagement->locateAll(params));
 }
 
 void ServiceLocatorApp::start(const string& name, const Ice::CommunicatorPtr& communicator,

-----------------------------------------------------------------------


-- 
team/dlee/servicediscovery.git



More information about the asterisk-scf-commits mailing list