[asterisk-scf-commits] asterisk-scf/release/ice-util-cpp.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Sep 26 16:30:48 CDT 2011


branch "master" has been updated
       via  efa46708b13689012282a678cb3501c4a7f6037d (commit)
      from  d8d94a2704d08f1a2d8be9237be3ad64cb16e1c6 (commit)

Summary of changes:
 src/Component/Component.cpp |   70 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 57 insertions(+), 13 deletions(-)


- Log -----------------------------------------------------------------
commit efa46708b13689012282a678cb3501c4a7f6037d
Author: Benjamin Oldenburg <benjamin.oldenburg at bericom.eu>
Date:   Mon Sep 26 23:16:29 2011 +0200

    ASTSCF-289: Enhance Component base class to cope with non-available Service Locator

diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index f654031..50b18ee 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -17,6 +17,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <Ice/Ice.h>
+#include <IceUtil/Thread.h>
 #include <IceBox/IceBox.h>
 
 #include <AsteriskSCF/Helpers/PropertyHelper.h>
@@ -41,7 +42,7 @@ namespace Component
 {
 static const string ServiceLocatorManagementPropertyName("LocatorServiceManagement.Proxy");
 static const string ServiceLocatorPropertyName("LocatorService.Proxy");
-
+	
 static const string ComponentServiceProxyId("ComponentService");
 static const string ReplicaProxyId("Replica");
 
@@ -748,25 +749,68 @@ void Component::createBackplaneServices()
  */
 void Component::initServiceLocatorProxies()
 {
+    int timeout = 0, retryDelay = 0;
+
     try
     {
-        // Get a proxy to the management interface for the Service Locator manager.
-        mServiceLocatorManagement = 
-            ServiceLocatorManagementPrx::checkedCast(mCommunicator->stringToProxy(
-                 mCommunicator->getProperties()->getPropertyWithDefault(
-                  ServiceLocatorManagementPropertyName, "LocatorServiceManagement:tcp -p 4412")));
-
-        // Get a proxy to the interface for the Service Locator.
-        mServiceLocator = 
-            ServiceLocatorPrx::checkedCast(mCommunicator->stringToProxy(
-                 mCommunicator->getProperties()->getPropertyWithDefault(
-                  ServiceLocatorPropertyName, "LocatorService:default -p 4411")));
+        timeout = mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + ".InitServiceLocatorTimeout", 30);
+        retryDelay = mCommunicator->getProperties()->getPropertyAsIntWithDefault(mName + ".InitServiceLocatorRetryDelay", 2);
     }
     catch(const Ice::Exception& e)
     {
-        mLogger(Error) << BOOST_CURRENT_FUNCTION << "Unable to obtain proxies to ServiceLocator. Check configuration. " << e.what();
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << "Failure to get property." << e.what();
+        throw;
+    }
+
+    if(timeout < 1)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << "The value (=" << timeout << ") of the property '"
+            << mName + ".InitServiceLocatorTimeout"
+            << "' cannot be less than 1.";
         throw;
     }
+
+    if(retryDelay < 1)
+    {
+        mLogger(Error) << BOOST_CURRENT_FUNCTION << "The value (=" << retryDelay << ") of the property '"
+            << mName + ".InitServiceLocatorRetryDelay"
+            << "' cannot be less than 1.";
+        throw;
+    }
+
+    IceUtil::Time tTimeout = IceUtil::Time::now() + IceUtil::Time::seconds(timeout);
+
+    while( IceUtil::Time::now() < tTimeout)
+    {
+        try
+        {
+            // Get a proxy to the management interface for the Service Locator manager.
+            mServiceLocatorManagement = 
+                ServiceLocatorManagementPrx::checkedCast(mCommunicator->stringToProxy(
+                    mCommunicator->getProperties()->getPropertyWithDefault(
+                        ServiceLocatorManagementPropertyName, "LocatorServiceManagement:tcp -p 4412")));
+
+            // Get a proxy to the interface for the Service Locator.
+            mServiceLocator = 
+                ServiceLocatorPrx::checkedCast(mCommunicator->stringToProxy(
+                     mCommunicator->getProperties()->getPropertyWithDefault(
+                      ServiceLocatorPropertyName, "LocatorService:default -p 4411")));
+
+            // If we made it to this point, everything's good.
+            return;
+        }
+        catch(const Ice::Exception& e)
+        {
+            mLogger(Notice) << " Unable to obtain proxies to ServiceLocator. Retry in " << retryDelay << " seconds.";
+        }
+
+        // Wait a little before retrying.
+        IceUtil::ThreadControl::sleep (IceUtil::Time::seconds(retryDelay));
+    }
+
+    // Timeout
+    mLogger(Error) << BOOST_CURRENT_FUNCTION << " Unable to obtain proxies to ServiceLocator for " << timeout << " seconds. Timeout!.";
+    throw; 
 }
 
 void Component::verifyProperties()

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


-- 
asterisk-scf/release/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list