[asterisk-scf-commits] asterisk-scf/integration/mediaformatgeneric.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Apr 6 10:15:57 CDT 2012


branch "retry_deux" has been updated
       via  128fc01443e97b6f5a0da1887b3d9cf584a7ddd8 (commit)
      from  dc5a3443a6af095d8fccaf4165e390e1adbad33f (commit)

Summary of changes:
 src/Configuration.cpp |  162 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 113 insertions(+), 49 deletions(-)


- Log -----------------------------------------------------------------
commit 128fc01443e97b6f5a0da1887b3d9cf584a7ddd8
Author: David M. Lee <dlee at digium.com>
Date:   Fri Apr 6 10:15:27 2012 -0500

    Added retry logic

diff --git a/src/Configuration.cpp b/src/Configuration.cpp
index ab6aac0..9ec5020 100644
--- a/src/Configuration.cpp
+++ b/src/Configuration.cpp
@@ -1,7 +1,7 @@
 /*
  * Asterisk SCF -- An open-source communications framework.
  *
- * Copyright (C) 2011, Digium, Inc.
+ * Copyright (C) 2011-2012, Digium, Inc.
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk SCF project. Please do not directly contact
@@ -18,9 +18,9 @@
 
 #include <boost/thread.hpp>
 #include <boost/shared_ptr.hpp>
-#include <boost/thread/shared_mutex.hpp>
 
 #include <AsteriskSCF/System/Component/ConfigurationIf.h>
+#include <AsterisksCF/Operations/OperationMonitor.h>
 
 #include "MediaFormatGenericConfigurationIf.h"
 #include "Configuration.h"
@@ -28,14 +28,18 @@
 
 using namespace AsteriskSCF::System::Configuration::V1;
 using namespace AsteriskSCF::Configuration::FormatGeneric::V1;
+using namespace AsteriskSCF::Operations;
 
 class ConfigurationServiceImplPriv
 {
 public:
     ConfigurationServiceImplPriv(const SDPDescriptorServiceImplPtr& descriptorService,
                                  const SDPDescriptorCompareServiceImplPtr& comparatorService) :
+        mOperationContextCache(OperationContextCache::create(DEFAULT_TTL_SECONDS)),
         mDescriptorService(descriptorService), mComparatorService(comparatorService) { };
 
+    OperationContextCachePtr mOperationContextCache;
+
     /**
      * Formats configuration group
      */
@@ -111,15 +115,15 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskS
         boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
         ConfigurationGroupSeq& mGroups;
     };
-    
+
     ConfigurationGroupSeq newGroups;
     FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
-    
+
     for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
     {
         (*group)->visit(v);
     }
-    
+
     return newGroups;
 }
 
@@ -130,7 +134,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const Asteri
     public:
         GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv, ConfigurationGroupSeq& visitorGroups) :
             mImplPriv(implPriv), mGroups(visitorGroups) { };
- 
+
     private:
         void visitFormatsGroup(const FormatsGroupPtr&)
         {
@@ -138,50 +142,50 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const Asteri
             {
                 return;
             }
-     
+
             mGroups.push_back(mImplPriv->mFormatsGroup);
         };
-        
+
         boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
         ConfigurationGroupSeq& mGroups;
     };
-    
+
     ConfigurationGroupSeq newGroups;
     FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
 
     boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
-    
+
     for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
     {
         (*group)->visit(v);
     }
-    
+
     return newGroups;
 }
 
 ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationGroups(const Ice::Current&)
 {
     ConfigurationGroupSeq groups;
- 
+
     boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
-   
+
     if (mImplPriv->mFormatsGroup)
     {
         FormatsGroupPtr general = new FormatsGroup();
         groups.push_back(general);
     }
-    
+
     return groups;
 }
 
-void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::V1::OperationContextPtr&,
+void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::V1::OperationContextPtr& context,
     const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
 {
     class GroupVisitor : public FormatsConfigurationGroupVisitor
     {
     public:
         GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
- 
+
     private:
         /**
          * Helper function which performs serial number checking of items
@@ -198,22 +202,22 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::V1::O
                 {
                     continue;
                 }
-  
+
                 ConfigurationItemDict::const_iterator localItem = localItems.find(item->first);
-  
+
                 if (localItem == localItems.end())
                 {
                     // This is a new item so serial checking does not apply
                     continue;
                 }
-  
+
                 if (item->second->serialNumber < localItem->second->serialNumber)
                 {
                     throw SerialConflict(group, item->second);
                 }
             }
         }
- 
+
         void visitFormatsGroup(const FormatsGroupPtr& group)
         {
             if (!mImplPriv->mFormatsGroup)
@@ -224,7 +228,7 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::V1::O
             {
                 performSerialCheck(group->configurationItems, mImplPriv->mFormatsGroup->configurationItems, group);
             }
-     
+
             for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
                  item != group->configurationItems.end();
                  ++item)
@@ -241,29 +245,49 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::V1::O
                 mImplPriv->mFormatsGroup->configurationItems.insert((*item));
             }
         }
- 
+
         boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
     };
-    
-    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
 
-    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
-    
-    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    ContextDataPtr data = checkAndThrow(mImplPriv->mOperationContextCache, context);
+
+    if (!data)
     {
-        (*group)->visit(v);
+        // retry detected
+        return;
+    }
+
+    try
+    {
+        FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+        boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+        for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+        {
+            (*group)->visit(v);
+        }
+        data->setCompleted();
+    }
+    catch (const std::exception& e)
+    {
+        data->setException(e);
+    }
+    catch (...)
+    {
+        data->setException();
     }
 }
 
 void ConfigurationServiceImpl::removeConfigurationItems(
-    const AsteriskSCF::System::V1::OperationContextPtr&,
+    const AsteriskSCF::System::V1::OperationContextPtr& context,
     const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
 {
     class GroupVisitor : public FormatsConfigurationGroupVisitor
     {
     public:
         GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
-        
+
         void removeItems(FormatsConfigurationItemVisitor* visitor, ConfigurationItemDict& itemsToRemove,
                          ConfigurationItemDict& localItems)
         {
@@ -292,40 +316,60 @@ void ConfigurationServiceImpl::removeConfigurationItems(
                 localItems.erase(localItem);
             }
         }
- 
+
         void visitFormatsGroup(const FormatsGroupPtr& group)
         {
             if (!mImplPriv->mFormatsGroup)
             {
                 return;
             }
-            
+
             removeItems(0, group->configurationItems, mImplPriv->mFormatsGroup->configurationItems);
         };
- 
+
     private:
         boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
     };
-    
-    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
 
-    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
-    
-    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    ContextDataPtr data = checkAndThrow(mImplPriv->mOperationContextCache, context);
+
+    if (!data)
     {
-        (*group)->visit(v);
+        // retry detected
+        return;
+    }
+
+    try
+    {
+        FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+        boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+        for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+        {
+            (*group)->visit(v);
+        }
+        data->setCompleted();
+    }
+    catch (const std::exception& e)
+    {
+        data->setException(e);
+    }
+    catch (...)
+    {
+        data->setException();
     }
 }
 
 void ConfigurationServiceImpl::removeConfigurationGroups(
-    const AsteriskSCF::System::V1::OperationContextPtr&,
+    const AsteriskSCF::System::V1::OperationContextPtr& context,
     const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
 {
     class GroupVisitor : public FormatsConfigurationGroupVisitor
     {
     public:
         GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
- 
+
     private:
         void visitFormatsGroup(const FormatsGroupPtr&)
         {
@@ -336,19 +380,39 @@ void ConfigurationServiceImpl::removeConfigurationGroups(
 
             mImplPriv->mDescriptorService->removeAllFormats();
             mImplPriv->mComparatorService->removeAllFormats();
-            
+
             mImplPriv->mFormatsGroup = 0;
         };
-        
+
         boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
     };
-    
-    FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
 
-    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
-    
-    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    ContextDataPtr data = checkAndThrow(mImplPriv->mOperationContextCache, context);
+
+    if (!data)
     {
-        (*group)->visit(v);
+        // retry detected
+        return;
+    }
+
+    try
+    {
+        FormatsConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+        boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+        for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+        {
+            (*group)->visit(v);
+        }
+        data->setCompleted();
+    }
+    catch (const std::exception& e)
+    {
+        data->setException(e);
+    }
+    catch (...)
+    {
+        data->setException();
     }
 }

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


-- 
asterisk-scf/integration/mediaformatgeneric.git



More information about the asterisk-scf-commits mailing list