[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Feb 14 18:46:12 CST 2012


branch "retry_deux" has been updated
       via  8f40afd174d340cec6eef706e6a20ceaa7eb5deb (commit)
      from  6fc167a116b660eb2cd6cc798976030874fcc29e (commit)

Summary of changes:
 .../Discovery/LocatorRegistrationWrapper.h         |  152 ++++++++++----------
 include/AsteriskSCF/Helpers/OperationContext.h     |    4 +-
 include/AsteriskSCF/Replication/StateReplicator.h  |   51 +++++--
 3 files changed, 116 insertions(+), 91 deletions(-)


- Log -----------------------------------------------------------------
commit 8f40afd174d340cec6eef706e6a20ceaa7eb5deb
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Feb 14 18:45:29 2012 -0600

    Applying operation context.

diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index 752325b..48c5fbe 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -61,82 +61,6 @@ public:
     {
     }
 
-    void addLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
-        const std::string& comparatorGUID)
-    {
-        mServiceManagement->addLocatorParams(mAddServiceOpContext, params, comparatorGUID);
-    }
-
-    /**
-     * Retries adding the locator params for the service. 
-     * @return true Successful
-     */
-    bool retryAddLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
-        const std::string& comparatorGUID)
-    {
-        AsteriskSCF::RetryPolicy retryPolicy(5,500);
-
-        while(retryPolicy.canRetry())
-        {
-            try
-            {
-                addLocatorParams(params, comparatorGUID);
-                return true;
-            }
-            catch(const Ice::ConnectionLostException&)
-            {
-                // For this exception, we'll just loop and rety as long as policy allows. 
-            }
-            catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
-            {
-                if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
-                {
-                    return true;
-                }
-                return false;
-            }
-        }
-        return false;
-    }
-
-    void addService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
-    {
-        mServiceManagement = 
-            AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(
-                management->addService(mService, mName));
-    }
-
-    /**
-     * Retries adding the service to the ServiceLocator. 
-     * @return true Successful
-     */
-    bool retryAddService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
-    {
-        AsteriskSCF::RetryPolicy retryPolicy(5,500);
-
-        while(retryPolicy.canRetry())
-        {
-            try
-            {
-                addService(management);
-                return true;
-            }
-            catch(const Ice::ConnectionLostException&)
-            {
-                // For this exception, we'll just loop and rety as long as policy allows. 
-            }
-            catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
-            {
-                if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
-                {
-                    return true;
-                }
-                return false;
-            }
-        }
-        return false;
-    }
-
     /**
      * The main registration function. The only exceptions handled are those related
      * to retries (for failover scenarios) so the caller must be prepared
@@ -231,6 +155,82 @@ public:
 
 private:
 
+    void addLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
+        const std::string& comparatorGUID)
+    {
+        mServiceManagement->addLocatorParams(mAddServiceOpContext, params, comparatorGUID);
+    }
+
+    /**
+     * Retries adding the locator params for the service. 
+     * @return true Successful
+     */
+    bool retryAddLocatorParams(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
+        const std::string& comparatorGUID)
+    {
+        AsteriskSCF::RetryPolicy retryPolicy(5,500);
+
+        while(retryPolicy.canRetry())
+        {
+            try
+            {
+                addLocatorParams(params, comparatorGUID);
+                return true;
+            }
+            catch(const Ice::ConnectionLostException&)
+            {
+                // For this exception, we'll just loop and rety as long as policy allows. 
+            }
+            catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
+            {
+                if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
+                {
+                    return true;
+                }
+                return false;
+            }
+        }
+        return false;
+    }
+
+    void addService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
+    {
+        mServiceManagement = 
+            AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx::uncheckedCast(
+                management->addService(mService, mName));
+    }
+
+    /**
+     * Retries adding the service to the ServiceLocator. 
+     * @return true Successful
+     */
+    bool retryAddService(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& management)
+    {
+        AsteriskSCF::RetryPolicy retryPolicy(5,500);
+
+        while(retryPolicy.canRetry())
+        {
+            try
+            {
+                addService(management);
+                return true;
+            }
+            catch(const Ice::ConnectionLostException&)
+            {
+                // For this exception, we'll just loop and rety as long as policy allows. 
+            }
+            catch(AsteriskSCF::System::V1::OperationCallCancelledException& cancelled)
+            {
+                if (cancelled.reason == AsteriskSCF::System::V1::Duplicate)
+                {
+                    return true;
+                }
+                return false;
+            }
+        }
+        return false;
+    }
+
     //
     // This template doesn't use boost locking simply because it already has a physical dependency
     // to Ice runtime, so avoiding adding a second seemed reasonable.
diff --git a/include/AsteriskSCF/Helpers/OperationContext.h b/include/AsteriskSCF/Helpers/OperationContext.h
index 1f4b0ca..6758d9a 100644
--- a/include/AsteriskSCF/Helpers/OperationContext.h
+++ b/include/AsteriskSCF/Helpers/OperationContext.h
@@ -16,7 +16,7 @@
 #pragma once
 
 #include <IceUtil/UUID.h>
-#include <AsteriskSCF/System/OperationContextIf.h>
+#include <AsteriskSCF/System/OperationsIf.h>
 
 namespace AsteriskSCF
 {
@@ -24,7 +24,7 @@ namespace AsteriskSCF
 /**
  * createContext simply creates a new OperationContext instance with the ID set to a UUID.
  */
-AsteriskSCF::System::V1::OperationContextPtr createContext()
+inline AsteriskSCF::System::V1::OperationContextPtr createContext()
 {
     AsteriskSCF::System::V1::OperationContextPtr newContext(new AsteriskSCF::System::V1::OperationContext);
     newContext->id = IceUtil::generateUUID();
diff --git a/include/AsteriskSCF/Replication/StateReplicator.h b/include/AsteriskSCF/Replication/StateReplicator.h
index e75e4ea..eb57812 100644
--- a/include/AsteriskSCF/Replication/StateReplicator.h
+++ b/include/AsteriskSCF/Replication/StateReplicator.h
@@ -19,6 +19,7 @@
 #include <Ice/Current.h>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/shared_mutex.hpp>
+#include <AsteriskSCF/System/OperationsIf.h>
 
 namespace AsteriskSCF
 {
@@ -68,13 +69,20 @@ public:
     {
         // Types: T - Listener type, U - State Item seq.
     public:
-        SetStateNotice(const U& stateSeq) : mStateSeq(stateSeq) {}
+        SetStateNotice(
+            const AsteriskSCF::System::V1::OperationContextPtr& operationContext, 
+            const U& stateSeq) 
+            : mOperationContext(operationContext),
+              mStateSeq(stateSeq) 
+        {
+        }
+
         ~SetStateNotice() {}
         void operator() (const T& x)
         {
             try
             {
-                x->stateSet(mStateSeq);
+                x->stateSet(mOperationContext, mStateSeq);
             }
             catch(...)
             {
@@ -84,6 +92,7 @@ public:
                 // should at the very least log these exceptions.
             }
         }
+        AsteriskSCF::System::V1::OperationContextPtr mOperationContext;
         U mStateSeq;
     };
 
@@ -94,13 +103,20 @@ public:
     {
         // Types: T - Listener type, V - Key Item seq.
     public:
-        RemoveStateByKeyNotice(const V& keys) : mKeys(keys) {}
+        RemoveStateByKeyNotice(
+            const AsteriskSCF::System::V1::OperationContextPtr& operationContext, 
+            const V& keys) 
+            : mOperationContext(operationContext),
+              mKeys(keys) 
+        {
+        }
+
         ~RemoveStateByKeyNotice() {}
         void operator() (const T& x)
         {
             try
             {
-                x->stateRemoved(mKeys);
+                x->stateRemoved(mOperationContext, mKeys);
             }
             catch(...)
             {
@@ -110,6 +126,7 @@ public:
                 // should at the very least log these exceptions.
             }
         }
+        AsteriskSCF::System::V1::OperationContextPtr mOperationContext;
         V mKeys;
     };
 
@@ -120,13 +137,20 @@ public:
     {
         // Types: T - Listener type, U - State Item seq.
     public:
-        RemoveStateNotice(const U& stateSeq) : mStateSeq(stateSeq) {}
+        RemoveStateNotice(
+            const AsteriskSCF::System::V1::OperationContextPtr& operationContext, 
+            const U& stateSeq) 
+            : mOperationContext(operationContext),
+              mStateSeq(stateSeq) 
+        {
+        }
+
         ~RemoveStateNotice() {}
         void operator() (T x)
         {
             try
             {
-                x->stateRemovedForItems(mStateSeq);
+                x->stateRemovedForItems(mOperationContext, mStateSeq);
             }
             catch(...)
             {
@@ -136,6 +160,7 @@ public:
                 // should at the very least log these exceptions.
             }
         }
+        AsteriskSCF::System::V1::OperationContextPtr mOperationContext;
         U mStateSeq;
     };
 
@@ -177,7 +202,7 @@ public:
 
         // Give this new listener the current state.
         boost::shared_lock<boost::shared_mutex> lock(mStateLock);
-        listener->stateSet(mStateItems);
+        listener->stateSet(new AsteriskSCF::System::V1::OperationContext(IceUtil::generateUUID()), mStateItems);
     }
 
     /**
@@ -225,7 +250,7 @@ public:
      * Add or update the specified state variables, and notify listeners.
      * @Override
      */
-    void setState(const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
+    void setState(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
     {
         {    // critical scope
             boost::unique_lock<boost::shared_mutex> lock(mStateLock);
@@ -247,14 +272,14 @@ public:
         }
 
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
-        for_each( mListeners.begin(), mListeners.end(), SetStateNotice<L,std::vector<S> >(items) );
+        for_each( mListeners.begin(), mListeners.end(), SetStateNotice<L,std::vector<S> >(operationContext, items) );
     }
 
     /**
      * Remove specified state variables identified by the specified keys, and notify listeners.
      * @Override
      */
-    void removeState(const std::vector<K>& ids, const Ice::Current& = ::Ice::Current())
+    void removeState(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const std::vector<K>& ids, const Ice::Current& = ::Ice::Current())
     {
         {   // critical scope
             boost::unique_lock<boost::shared_mutex> lock(mStateLock);
@@ -271,7 +296,7 @@ public:
         }
 
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
-        for_each(mListeners.begin(), mListeners.end(), RemoveStateByKeyNotice<L,std::vector<K> >(ids));
+        for_each(mListeners.begin(), mListeners.end(), RemoveStateByKeyNotice<L,std::vector<K> >(operationContext, ids));
     }
 
     /**
@@ -279,7 +304,7 @@ public:
      * The item's key is used to identify the item to remove. Any other field is ignored. 
      * @Override
      */
-    void removeStateForItems(const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
+    void removeStateForItems(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
     {
         {   // critical scope
             boost::unique_lock<boost::shared_mutex> lock(mStateLock);
@@ -296,7 +321,7 @@ public:
         }
 
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
-        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<S> >(items));
+        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<S> >(operationContext, items));
     }
 
     /**

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


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



More information about the asterisk-scf-commits mailing list