[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
Wed Feb 22 12:11:57 CST 2012


branch "retry_deux" has been updated
       via  3b06f219461933ef87dc6b02d781eb283d2f6217 (commit)
      from  d5eeba382f5c92e84e36bba38878224644aea2a1 (commit)

Summary of changes:
 .../AsteriskSCF/Operations/OperationContextCache.h |    6 ++-
 src/Operations/OperationContextCache.cpp           |   38 ++++++++++++------
 .../LocatorRegistrationTest.cpp                    |   41 ++++++++++++--------
 .../OperationContextCacheTest.cpp                  |    8 ++--
 4 files changed, 58 insertions(+), 35 deletions(-)


- Log -----------------------------------------------------------------
commit 3b06f219461933ef87dc6b02d781eb283d2f6217
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Feb 22 12:12:01 2012 -0600

    - Updated OperationContextCache to avoid circular references with Timer.
    - Updated unit tests for OperationContext.

diff --git a/include/AsteriskSCF/Operations/OperationContextCache.h b/include/AsteriskSCF/Operations/OperationContextCache.h
index 54a2f89..69eec86 100644
--- a/include/AsteriskSCF/Operations/OperationContextCache.h
+++ b/include/AsteriskSCF/Operations/OperationContextCache.h
@@ -30,6 +30,9 @@ namespace Operations
 class OperationContextCachEntry;
 typedef ASTSCF_DLL_EXPORT boost::shared_ptr<OperationContextCachEntry> OperationContextCachEntryPtr;
 
+class OperationContextPruner;
+typedef IceUtil::Handle<OperationContextPruner> OperationContextPrunerPtr;
+
 /**
  * Utiltity class that provides a queryable cache of OperationContext objects.
  */
@@ -91,8 +94,7 @@ private:
     bool mLoggingEnabled;
     std::string mLoggingLabel;
     boost::shared_mutex mLock;
-    IceUtil::TimerTaskPtr mTimerTask;
-    IceUtil::TimerPtr mTimer;
+    OperationContextPrunerPtr mPruner;
     IceUtil::Time mTTL;
     std::map<std::string, OperationContextCachEntryPtr> mCache;
 };
diff --git a/src/Operations/OperationContextCache.cpp b/src/Operations/OperationContextCache.cpp
index 09a8f7c..e5bd901 100644
--- a/src/Operations/OperationContextCache.cpp
+++ b/src/Operations/OperationContextCache.cpp
@@ -74,13 +74,17 @@ private:
 
 /** 
  * A TimerTask to instigate the pruning of the cache. 
+ * The OperationContextCache manages the life of this task and its
+ * internal timer. 
  */
 class OperationContextPruner : public IceUtil::TimerTask
 {
 public:
-    OperationContextPruner(const OperationContextCachePtr& cache)
-        : mCache(cache)
+    OperationContextPruner(OperationContextCache* cache, int ttlSeconds) :
+        mCache(cache),
+        mTimer(new IceUtil::Timer)
     {
+         mTimer->scheduleRepeated(this, IceUtil::Time::seconds(ttlSeconds));
     }
 
     /**
@@ -88,13 +92,25 @@ public:
      */
     void runTimerTask()
     {
+        if (mCache == 0)
+        {
+            return;
+        }
+
         mCache->prune();
     }
 
+    void cancel()
+    {
+        mTimer->destroy();
+        mTimer = 0;
+        mCache = 0;
+    }
+
 private:
-    OperationContextCachePtr mCache;
+    OperationContextCache* mCache; // Raw pointer to avoid circular refs
+    IceUtil::TimerPtr mTimer;
 };
-typedef IceUtil::Handle<OperationContextPruner> OperationContextPrunerPtr;
 
 /**
  * Constructor.
@@ -106,11 +122,9 @@ OperationContextCache::OperationContextCache(int ttlSeconds)
     : mLogger(lg),
       mLoggingEnabled(false),
       mLoggingLabel(""),
-      mTTL(IceUtil::Time::seconds(ttlSeconds)),
-      mTimer(new IceUtil::Timer),
-      mTimerTask(new OperationContextPruner(this))
+      mPruner(new OperationContextPruner(this, ttlSeconds)),
+      mTTL(IceUtil::Time::seconds(ttlSeconds))
 {
-    mTimer->scheduleRepeated(mTimerTask, mTTL);
 }
 
 /**
@@ -127,16 +141,14 @@ OperationContextCache::OperationContextCache(int ttlSeconds,
     : mLogger(logger),
       mLoggingEnabled(true),
       mLoggingLabel(label),
-      mTTL(IceUtil::Time::seconds(ttlSeconds)),
-      mTimer(new IceUtil::Timer),
-      mTimerTask(new OperationContextPruner(this))
+      mPruner(new OperationContextPruner(this, ttlSeconds)),
+      mTTL(IceUtil::Time::seconds(ttlSeconds))
 {
-    mTimer->scheduleRepeated(mTimerTask, mTTL);
 }
 
 OperationContextCache::~OperationContextCache()
 {
-    mTimer->cancel(mTimerTask);
+    mPruner->cancel();
 }
 
 /**
diff --git a/test/LocatorRegistration/LocatorRegistrationTest.cpp b/test/LocatorRegistration/LocatorRegistrationTest.cpp
index d100fab..5442c26 100644
--- a/test/LocatorRegistration/LocatorRegistrationTest.cpp
+++ b/test/LocatorRegistration/LocatorRegistrationTest.cpp
@@ -40,6 +40,7 @@ using namespace std;
 using namespace boost::unit_test;
 using namespace AsteriskSCF::Discovery;
 using namespace AsteriskSCF::System::V1;
+using namespace AsteriskSCF::Operations;
 
 namespace AsteriskSCF
 {
@@ -155,19 +156,19 @@ public:
         return mData->state();
     }
 
-    void suspend(const Ice::Current&)
+    void suspend(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const Ice::Current&)
     {
         statePreCheck();
         mData->suspend();
     }
 
-    void unsuspend(const Ice::Current&)
+    void unsuspend(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const Ice::Current&)
     {
         statePreCheck();
         mData->unsuspend();
     }
     
-    void unregister(const Ice::Current&)
+    void unregister(const AsteriskSCF::System::V1::OperationContextPtr& operationContext, const Ice::Current&)
     {
         if (!mData->destroy())
         {
@@ -343,8 +344,11 @@ public:
     {
     }
     
-    AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx addService(const Ice::ObjectPrx& service,
-            const std::string& guid, const Ice::Current&)
+    AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx addService(
+        const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+        const Ice::ObjectPrx& service,
+        const std::string& guid, 
+        const Ice::Current&)
     {
         return mDB->add(guid, service)->tokenProxy();
     }
@@ -370,13 +374,18 @@ public:
         return AsteriskSCF::Core::Discovery::V1::ServiceInfo();
     }
     
-    void addCompare(const std::string&, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsComparePrx&, 
+    void addCompare(
+        const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+        const std::string&, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsComparePrx&, 
         const Ice::Current&)
     {
         // NO-OP
     }
 
-    void removeCompare(const std::string&, const Ice::Current&)
+    void removeCompare(
+        const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+        const std::string&, 
+        const Ice::Current&)
     {
         //NO-OP
     }
@@ -472,10 +481,10 @@ public:
             // Looks a little weird maybe, but WHY can't the manager be added to the locator. It makes a whole whackload of sense really.
             //
             mMgrTokenUUID = IceUtil::generateUUID();
-            mMgrToken = mManager->addService(mManager, mMgrTokenUUID);
+            mMgrToken = mManager->addService(createContext(), mManager, mMgrTokenUUID);
             AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params(new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams);
             params->category = "AsteriskSCF.LocatorManager";
-            mMgrToken->addLocatorParams(new OperationContext(IceUtil::generateUUID()), params, "");
+            mMgrToken->addLocatorParams(createContext(), params, "");
         }
     }
 
@@ -498,7 +507,7 @@ public:
         }
         if (token)
         {
-            token->unregister();
+            token->unregister(createContext());
         }
         if (adapter)
         {
@@ -564,27 +573,27 @@ private:
 class TestListener : public AsteriskSCF::System::Discovery::Events
 {
 public:
-    void comparisonRegistered(const std::string&, const Ice::Current&)
+    void comparisonRegistered(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 
-    void comparisonUnregistered(const std::string&, const Ice::Current&)
+    void comparisonUnregistered(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 
-    void serviceRegistered(const std::string&, const Ice::Current&)
+    void serviceRegistered(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 
-    void serviceUnregistered(const std::string&, const Ice::Current&)
+    void serviceUnregistered(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 
-    void serviceSuspended(const std::string&, const Ice::Current&)
+    void serviceSuspended(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 
-    void serviceUnsuspended(const std::string&, const Ice::Current&)
+    void serviceUnsuspended(const AsteriskSCF::System::V1::OperationContextPtr& context, const std::string&, const Ice::Current&)
     {
     }
 };
diff --git a/test/OperationContextCache/OperationContextCacheTest.cpp b/test/OperationContextCache/OperationContextCacheTest.cpp
index ac9aa45..1973c89 100644
--- a/test/OperationContextCache/OperationContextCacheTest.cpp
+++ b/test/OperationContextCache/OperationContextCacheTest.cpp
@@ -29,7 +29,7 @@
 
 using namespace AsteriskSCF;
 using namespace AsteriskSCF::System::V1;
-using namespace AsteriskSCF::Helpers;
+using namespace AsteriskSCF::Operations;
 using namespace AsteriskSCF::System::Logging;
 
 namespace
@@ -59,9 +59,9 @@ static void runOperationContextCacheTest()
     // Verify empty
     testCache(cache, testOperations);
 
-    testOperations.push_back(new OperationContext("ID1"));
-    testOperations.push_back(new OperationContext("ID2"));
-    testOperations.push_back(new OperationContext("ID3"));
+    testOperations.push_back(new OperationContext("ID1", "Transact1"));
+    testOperations.push_back(new OperationContext("ID2", "Transact1"));
+    testOperations.push_back(new OperationContext("ID3", "Transact1"));
 
     BOOST_CHECK(cache->addOperationContext(testOperations[0]) == true);
     BOOST_CHECK(cache->addOperationContext(testOperations[1]) == true);

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


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



More information about the asterisk-scf-commits mailing list