[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
Thu Feb 23 16:52:34 CST 2012


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

Summary of changes:
 .../AsteriskSCF/Operations/OperationContextCache.h |   39 ++++++++++-
 src/Operations/OperationContextCache.cpp           |   73 +++++++++++++++++++-
 2 files changed, 107 insertions(+), 5 deletions(-)


- Log -----------------------------------------------------------------
commit 22fa0af4711d80cd08fb5d172bc3fc3badef2a3d
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Feb 23 16:50:40 2012 -0600

    Added support for cookies on cache entries to support return values.
    Also added a remove operation.

diff --git a/include/AsteriskSCF/Operations/OperationContextCache.h b/include/AsteriskSCF/Operations/OperationContextCache.h
index 69eec86..77d7433 100644
--- a/include/AsteriskSCF/Operations/OperationContextCache.h
+++ b/include/AsteriskSCF/Operations/OperationContextCache.h
@@ -33,6 +33,12 @@ typedef ASTSCF_DLL_EXPORT boost::shared_ptr<OperationContextCachEntry> Operation
 class OperationContextPruner;
 typedef IceUtil::Handle<OperationContextPruner> OperationContextPrunerPtr;
 
+class ASTSCF_DLL_EXPORT OperationContextCookie
+{
+};
+
+typedef ASTSCF_DLL_EXPORT boost::shared_ptr<OperationContextCookie> OperationContextCookiePtr;
+
 /**
  * Utiltity class that provides a queryable cache of OperationContext objects.
  */
@@ -63,21 +69,49 @@ public:
 
     /**
      * Caches the specified context if it isnt' already in the cache. 
+     *
+     * @param operationContext The context to add to the cache. 
      * @return true The context was added, which means it wasn't already in the cache.
+     *
      * @note Make sure you don't confuse the return value of this operation with the return
      * value of the 'contains' operation. 
      */
     bool addOperationContext(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
 
     /**
+     * Caches the specified context if it isnt' already in the cache, and associate a cookie with it. 
+     *
+     * @param operationContext The context to add to the cache. 
+     * @param inCookie A cookie object to associate with this entry in the cache. 
+     * @param existingCookie This value will be set by this method to the cookie of an existing
+     * operationContext if there was already an entry in the cache with the same identity. 
+     * @return true The context was added, which means it wasn't already in the cache.
+     *
+     * @note Make sure you don't confuse the return value of this operation with the return
+     * value of the 'contains' operation. 
+     */
+    bool addOperationContext(
+        const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+        const OperationContextCookiePtr& inCookie, 
+        OperationContextCookiePtr& existingCookie);
+
+    /**
      * Tests if the specified context is in the cache. 
      */
     bool contains(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
 
     /**
+     * This will remove an OperationContext from the cache, if one exists with the given id. 
+     * Removal is typically done automatically within the cache based on an internal timer. 
+     * This operation exists to support clients that wish to force an immediate removal of a 
+     * context themselves. 
+     */
+    void removeOperationContext(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
+
+    /**
      * Drop entries that are older than the TTL. 
      * @note This method is called by an internal timer task, so clients
-     * of this class don't need to call it unless they just want to. 
+     * of this class don't need to call it. (There's no harm if a client does call it.)  
      */
     void prune(); 
 
@@ -87,7 +121,8 @@ public:
     std::size_t size();
 
 private:
-    bool containsImpl(const AsteriskSCF::System::V1::OperationContextPtr& operationContext);
+    bool containsImpl(const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+        OperationContextCachEntryPtr& cacheEntry);
     void logStaleList(std::vector<std::string>& staleList);
 
     AsteriskSCF::System::Logging::Logger mLogger;
diff --git a/src/Operations/OperationContextCache.cpp b/src/Operations/OperationContextCache.cpp
index e5bd901..c1eac70 100644
--- a/src/Operations/OperationContextCache.cpp
+++ b/src/Operations/OperationContextCache.cpp
@@ -48,11 +48,24 @@ public:
     {
     }
 
+    OperationContextCachEntry(const OperationContextPtr& context, const OperationContextCookiePtr& cookie, const IceUtil::Time& ttl) :
+      mContext(context),
+      mCookie(cookie),
+      mTimestamp(IceUtil::Time::now()),
+      mTTL(ttl)
+    {
+    }
+
     OperationContextPtr getContext()
     {
         return mContext;
     }
 
+    OperationContextCookiePtr getCookie()
+    {
+        return mCookie;
+    }
+
     /** 
      * Compares this entries timestamp to the passed in time. 
      * Return true if the difference is greater than the TTL. 
@@ -68,6 +81,7 @@ public:
 
 private:
     OperationContextPtr mContext;
+    OperationContextCookiePtr mCookie;
     IceUtil::Time mTimestamp;
     IceUtil::Time mTTL;
 };
@@ -154,19 +168,26 @@ OperationContextCache::~OperationContextCache()
 /**
  * Non-locking contains() operation for code sharing. 
  */
-bool OperationContextCache::containsImpl(const OperationContextPtr& operationContext)
+bool OperationContextCache::containsImpl(
+    const OperationContextPtr& operationContext,
+    OperationContextCachEntryPtr& cacheEntry)
 {
     std::map<std::string, OperationContextCachEntryPtr>::iterator entry = mCache.find(operationContext->id);
     if (entry == mCache.end())
     {
         return false;
     }
+
+    cacheEntry = entry->second;
     return true;
 }
 
 /**
  * Caches the specified context if it isnt' already in the cache. 
+ *
+ * @param operationContext The context to add to the cache. 
  * @return true The context was added, which means it wasn't already in the cache.
+ *
  * @note Make sure you don't confuse the return value of this operation with the return
  * value of the 'contains' operation. 
  */
@@ -174,7 +195,8 @@ bool OperationContextCache::addOperationContext(const OperationContextPtr& opera
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
 
-    if (containsImpl(operationContext))
+    OperationContextCachEntryPtr existingEntry;
+    if (containsImpl(operationContext, existingEntry))
     {
         return false;
     }
@@ -186,6 +208,50 @@ bool OperationContextCache::addOperationContext(const OperationContextPtr& opera
 }
 
 /**
+ * Caches the specified context if it isnt' already in the cache, and associate a cookie with it. 
+ *
+ * @param operationContext The context to add to the cache. 
+ * @param inCookie A cookie object to associate with this entry in the cache. 
+ * @param existingCookie This value will be set by this method to the cookie of an existing
+ * operationContext, if there was already one in the cache with this id. 
+ * @return true The context was added, which means it wasn't already in the cache.
+ *
+ * @note Make sure you don't confuse the return value of this operation with the return
+ * value of the 'contains' operation. 
+ */
+bool OperationContextCache::addOperationContext(
+    const AsteriskSCF::System::V1::OperationContextPtr& operationContext,
+    const OperationContextCookiePtr& inCookie, 
+    OperationContextCookiePtr& existingCookie)
+{
+    boost::shared_lock<boost::shared_mutex> lock(mLock);
+
+    OperationContextCachEntryPtr existingEntry;
+    if (containsImpl(operationContext, existingEntry))
+    {
+        existingCookie = existingEntry->getCookie();
+        return false;
+    }
+
+    OperationContextCachEntryPtr entry(new OperationContextCachEntry(operationContext, inCookie, mTTL));
+    mCache[operationContext->id] = entry;
+
+    return true;
+}
+
+void OperationContextCache::removeOperationContext(const OperationContextPtr& operationContext)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mLock);
+
+    std::map<std::string, OperationContextCachEntryPtr>::iterator entryIter = mCache.find(operationContext->id);
+    if (entryIter == mCache.end())
+    {
+        return;
+    }
+    mCache.erase(entryIter);
+}
+
+/**
  * Tests if the specified context is in the cache. 
  * @param operationContext 
  */
@@ -193,7 +259,8 @@ bool OperationContextCache::contains(const OperationContextPtr& operationContext
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
 
-    return containsImpl(operationContext);
+    OperationContextCachEntryPtr entry;
+    return containsImpl(operationContext, entry);
 }
 
 void OperationContextCache::logStaleList(std::vector<std::string>& staleList)

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


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



More information about the asterisk-scf-commits mailing list